Simple Least-Squares Filtering

Simple filter problem

The Filter Problem

Suppose we have input data f[t]f[t] with an impulse response function for the system given by h[t]h[t]. The length of this impulse response is mm.

Our goal is to match a desired output d[t]d[t] as closely as possible.

The convolution of the inpulse response with the input data produces an output given by:

y[t]=∑i=0m−1h[i]f[t−i]\begin{align*} y[t] &= \sum_{i=0}^{m-1} h[i]f[t-i] \end{align*}

We'd like d[t]=y[t]d[t] = y[t] but unfortunately we'll always be off by some amount given by e[t]e[t].

Therefore,

d[t]=y[t]+e[t]  ⟹  e[t]=d[t]−y[t]=d[t]−∑i=0m−1h[i]f[t−i]\begin{align*} d[t] &= y[t] + e[t] \\ \implies e[t] &= d[t] - y[t] \\ &= d[t] - \sum_{i=0}^{m-1} h[i]f[t-i] \end{align*}

Consider minimizing the error over some interval i1i_1 to i2i_2. Then we now have a system of equations.

We can construct an error vector as

e=[d[i1]−∑i=0m−1h[i]f[i1−i]d[i1+1]−∑i=0m−1h[i]f[i1+1−i]d[i1+2]−∑i=0m−1h[i]f[i1+2−i]⋮d[i2]−∑i=0m−1h[i]f[i2−i]]=[d[i1]⋮d[i2]]−[∑i=0m−1h[i]f[i1−i]⋮∑i=0m−1h[i]f[i2−i]]=d−y\begin{align*} \pmb e &= \begin{bmatrix} d[i_1] - \sum_{i=0}^{m-1} h[i] f[i_1 -i] \\ d[i_1 + 1] - \sum_{i=0}^{m-1} h[i] f[i_1 + 1 -i] \\ d[i_1 + 2] - \sum_{i=0}^{m-1} h[i] f[i_1 + 2 -i] \\ \vdots \\ d[i_2] - \sum_{i=0}^{m-1} h[i] f[i_2 -i] \\ \end{bmatrix} \\[40pt] &= \begin{bmatrix} d[i_1] \\ \vdots \\ d[i_2]\end{bmatrix} - \begin{bmatrix}\sum_{i=0}^{m-1} h[i] f[i_1 -i] \\ \vdots \\ \sum_{i=0}^{m-1} h[i] f[i_2 -i]\end{bmatrix} \\ &= \pmb d - \pmb y \end{align*}

Now, the way that formulate this problem is dependent on how we choose i1i_1 and i2i_2. We'll assume that the number of steps from i1i_1 to i2i_2 is greater than mm so that we have an over determined system.

Depending on the assumptions we're willing to make, the values of i1i_1 and i2i_2 will vary. For example, if i1<mi_1 < m then we'll index f[i1−i]f[i_1 - i] at values that don't exist. A similar situation arises from choosing i2>Ni_2 > N.

This may be a little confusing right now but the following discussion will make this clear.

Constructing AA

There are various ways we can factorize y\pmb y which is necessary to construct the least squares problem.

Once we factorize y\pmb y we'll have an equation of the form e=d−Ah\pmb e = \pmb d - A \pmb h which when minimizing the l2l_2 norm of the error is a standard least squares problem with solution h=(AHA)−1AHd\pmb h = (A^HA)^{-1}A^H \pmb d.

Finally we pick AA and we're done.

The "Covariance" Method

Let i1=mi_1 = m and let i2=Ni_2 = N, then:

A=[f[m]f[m−1]…f[1]f[m+1]f[m]…f[2]⋮⋮⋱⋮f[N]f[N−1]…f[N−m+1]]\begin{align} A = \begin{bmatrix}f[m] & f[m-1] & \dots & f[1] \\ f[m+1] & f[m] & \dots & f[2] \\ \vdots & \vdots & \ddots & \vdots \\ f[N] & f[N-1] & \dots & f[N-m+1]\end{bmatrix} \end{align}

This AA matrix has N−m+1N-m+1 rows.

Note that this matrix used all samples without any assumptions.

The "Autocorrealtion" Method

Assume that f[i]=0f[i] = 0 when i>Ni > N or i<1i < 1.

Let i1=1i_1 = 1 and let i2=N+m−1i_2 = N+m -1. Then our AA matrix becomes

A=[f[1]0…0f[2]f[1]…0⋮⋮⋱0f[m]f[m−1]…f[1]f[m+1]f[m]…f[2]⋮⋮⋱⋮f[N]f[N−1]…f[N−m+1]0f[N]…f[N−m+2⋮⋮⋱⋮0……f[N]]\begin{align*} A = \begin{bmatrix} f[1] & 0 & \dots & 0 \\ f[2] & f[1] & \dots & 0 \\ \vdots & \vdots & \ddots & 0 \\ f[m] & f[m-1] & \dots & f[1] \\ f[m+1] & f[m] & \dots & f[2] \\ \vdots & \vdots & \ddots & \vdots \\ f[N] & f[N-1] & \dots & f[N-m+1] \\ 0 & f[N] & \dots & f[N-m+2 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & \dots & \dots & f[N] \end{bmatrix} \end{align*}

This matrix has N+m−1N+m-1 rows.

The "Pre-windowing" method

Assume f[i]=0f[i] = 0 when i<1i < 1.

Let i1=1i_1 = 1 and i2=Ni_2 = N

Then AA is

A=[f[1]0…0f[2]f[1]…0⋮⋮⋱0f[m]f[m−1]…f[1]f[m+1]f[m]…f[2]⋮⋮⋱⋮f[N]f[N−1]…f[N−m+1]]\begin{align*} A = \begin{bmatrix} f[1] & 0 & \dots & 0 \\ f[2] & f[1] & \dots & 0 \\ \vdots & \vdots & \ddots & 0 \\ f[m] & f[m-1] & \dots & f[1] \\ f[m+1] & f[m] & \dots & f[2] \\ \vdots & \vdots & \ddots & \vdots \\ f[N] & f[N-1] & \dots & f[N-m+1] \end{bmatrix} \end{align*}

AA has NN rows.

The "Post-windowing" method

For this method we let f[i]=0f[i] = 0 when i>Ni> N.

Let let i1=mi_1 = m and i2=N+m−1i_2 = N+m -1

Now AA is

A=[f[m]f[m−1]…f[1]f[m+1]f[m]…f[2]⋮⋮⋱⋮f[N]f[N−1]…f[N−m+1]0f[N]…f[N−m+2⋮⋮⋱⋮0……f[N]]\begin{align*} A = \begin{bmatrix} f[m] & f[m-1] & \dots & f[1] \\ f[m+1] & f[m] & \dots & f[2] \\ \vdots & \vdots & \ddots & \vdots \\ f[N] & f[N-1] & \dots & f[N-m+1] \\ 0 & f[N] & \dots & f[N-m+2 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & \dots & \dots & f[N] \end{bmatrix} \end{align*}

AA has NN rows.