# Filtered-X LMS algorithm and built-in MATLAB implementation

I provide a short scheme for forward explanation:

There are two sources: noise signal source and anti-noise signal source (2). Noise signal travels through primary path $$h_{N_P}$$ to microphone (4). At the same time noise travels to adaptive filter $$h_N$$. Then anti-noise $$-y(k)$$ travels through secondary part $$h_{N_S}$$ and is summed with primary path noise $$d(k)$$. Thus we get error signal $$\alpha(k)$$

There is also an example of using FxLMS algorithm in ANC. Here is short step-by-step description of what happens in example:

1. real secondary path ($$h_{N_S}$$ on figure) is modeled
2. secondary path estimation ($$h'_{N_S}$$)is made using LMS algorithm
3. generation of primary path ($$h_{N_P}$$)
4. generation of polyharmonic noise $$x(k)$$
5. creation of dsp.FilteredXLMSFilter object with setting number of coefficients of $$h_N$$, algorithm step $$\mu$$ and secondary path estimation
noiseController = dsp.FilteredXLMSFilter('Length',L,'StepSize',muW,SecondaryPathCoefficients',SecondaryPathCoeffsEst);


1. desired signal is found as filtering $$x(k)$$ through $$h_{N_P}$$
2. noiseController object is used taking $$d(k)$$ and $$x(k)$$ and returning $$y(k)$$ and $$\alpha(k)$$

the strange thing is that in real system, to find an error signal $$\alpha(k)$$, you need a real secondary path. In model of that system, you need a model of the secondary path, but MATLAB implementation uses only estimation of SP.

Is that implementation correct after all and my explanation is wrong? Why if yes?

UPD: there is error in example, not in implementation.

• For clarity, could you edit your post to add a concrete question?
– MBaz
Nov 10, 2023 at 21:25
• sure. Thank you for that comment Nov 10, 2023 at 21:52

I think you are mixing the estimated, real and modelled responses. You can kinda safely assume that the real transfer functions $$h_{N_{p}}$$ and $$h_{N_{s}}$$ are never known. This, of course, is in the strict mathematical sense. This means that you will never be able to use those in real-life systems. Nevertheless, when you model a system you do have access to those “real” transfer functions since they are part of your model.

Using an estimate $$\hat{h}_{N_{s}}$$ of the “true” plant response $$h_{N_{s}}$$ is a way to “simulate” what you would do in a real scenario, where you do not have access to the true values. This would allow you to acquire results that are closer to an implemented system. Furthermore, you could also introduce “controlled inconsistencies” in the estimated responses to investigate the behaviour of your system.

I will try to provide some kind of generic example below. For that, I will introduce a basic formulation of the problem. Feel free to skip the formulation and go directly to section 2 and use the formulation section as a reference.

### 1. FxLMS Formulation

The primary sources generate a sound field $$\mathbf{x} = \left[ x_{1}, x_{2}, \ldots x_{N_{x}} \right]^{T}$$, where $$\left[ \, \cdot \, \right]^{T}$$ denotes transposition. This field is sensed by the monitoring/error sensors through the primary path transfer function matrix $$\mathbf{H}_{p}$$ ($$h_{N_{p}}$$ in your diagram) to generate the monitoring field due to the primary source

$$\mathbf{d} = \mathbf{H}_{p} \mathbf{x} \tag{1} \label{1}$$

The primary source is also sensed by the reference sensors whose output passes through the filter $$\mathbf{W}$$ (denoted $$h_{N}$$ in your diagram) to drive the secondary sources with signals

$$\mathbf{u} = \mathbf{W} \mathbf{b} = \mathbf{W} \mathbf{H}_{b} \mathbf{x} \tag{2} \label{2}$$

where the $$\mathbf{H}_{b}$$ is the transfer function from the primary sources to the reference microphones (not shown in your image).

The secondary signals are combined at the error sensors through the transfer function $$\mathbf{H}_{s}$$ ($$h_{N_{s}}$$ in your diagram) to give the total field at these positions

$$\mathbf{a} = \mathbf{d} + \mathbf{H}_{s} \mathbf{u} = \mathbf{H}_{p} \mathbf{x} + \mathbf{H}_{s} \mathbf{W} \mathbf{b} \tag{3} \label{3}$$

Now, the second operand of the summation on the right-hand side of equation \eqref{3} can be expressed as a linear system like

$$y = b * w * h = \left( b * h \right) * w \tag{4} \label{4}$$

Where $$\left[ \, * \, \right]$$ denotes convolutions. Since convolution is a linear operator, the order has changed in the last part of equation \eqref{4} and the signal can be represented as the convolution of the reference signal with plant response from the secondary source to the error microphone filtered by the filter $$w$$. This is the justification for “passing” the reference signal $$\mathbf{x}$$ through the plant response $$\mathbf{H}_{s}$$ before filtering with $$w$$ (or to calculate the filter $$w$$ through the FxLMS algorithm).

The driving signals $$\mathbf{u}$$ update formula in the FxLMS algorithm is

$$\mathbf{u} \left(n + 1 \right) = \mathbf{u} \left( n \right) - \mu \mathbf{H}_{s}^{H} \mathbf{a} \left( n \right) \tag{5} \label{5}$$

where $$\left[ \, \cdot \, \right]^{H}$$ denotes Hermitian transposition and $$\mu$$ is the “step” or “convergence coefficient”. Inserting the first part of equation \eqref{3}, for the error $$\mathbf{a}$$ we get

$$\mathbf{u} \left(n + 1 \right) = \mathbf{u} \left( n \right) - \mu \mathbf{H}_{s}^{H} \left[ \mathbf{d} \left( n \right) + \mathbf{H}_{s} \mathbf{u} \left( n \right) \right] = \mathbf{u} \left( n \right) - \mu \left[ \mathbf{H}_{s}^{H} \mathbf{d} \left( n \right) + \mathbf{H}_{s}^{H} \mathbf{H}_{s} \mathbf{u} \left( n \right) \right] \tag{6} \label{6}$$

After convergence, the term in the square brackets at the final part of equation \eqref{6} must equal zero, so the optimal (in the FxLMS sense) secondary signals are given by

$$\mathbf{u}_{\infty} = \left( \mathbf{H}_{s}^{H} \mathbf{H}_{s} \right)^{-1} \mathbf{H}_{s}^{H} \mathbf{d} \tag{7} \label{7}$$

### 2. Why use an estimated plant response?

If an estimate $$\hat{\mathbf{H}}_{s}$$ is used instead of the real plant transfer function, equation \eqref{7} is written as

$$\mathbf{u}_{\infty} = \left( \hat{\mathbf{H}}_{s}^{H} \mathbf{H}_{s} \right)^{-1} \hat{\mathbf{H}}_{s}^{H} \mathbf{d} \tag{8} \label{8}$$

and with equation \eqref{8} one can investigate the effect of incorrect plant response estimation on the system efficiency. Nothing holds you back from using the actual/real plant response to get “ideal” results but this does not reflect real systems. Furthermore, you could express the plant matrix as

$$\hat{\mathbf{H}}_{s} = \mathbf{H}_{s} + \Delta \mathbf{H}_{s} \tag{9} \label{10}$$

The first part of the right-hand side is the true plant response and then you can add an “uncertainty” matrix which adds errors to the estimated response. The $$\Delta \mathbf{H}_{s}$$ matrix can be tailored in any way you like. You could add errors to certain secondary source-to-error sensor paths, random errors, or both, or even remove some entries to simulate malfunctions in sources.

• sure, that is what my question about: equation (3) tells, that y is output from adaptive filter $w$ and some path response $h$. But MATLAB algorithm have no $h$ on input, so in its simulation, output difference $\alpha$ is not correct Nov 12, 2023 at 15:32
• I mean, that for simulation of a real system, you need both real and estimated responses of secondary path, which also can help to see results of correct or incorrect estimation Nov 12, 2023 at 15:34
• upd: there is error in example, not in implementation. Nov 12, 2023 at 21:24