Filtering Convolution (Circular)
Filtering Convolution (Circular)
Abstract
Class notes on filtering, convolutions, eigenvalue/eigenvector, diagonalization, and
z-transform.
Filtering
Filtering refers to linear transforms that change the frequency contents of signals. Depending on whether high (low) frequencies are attenuated, filtering process is called low (high)
pass.
1.1
Example: two point moving average, recall the linear time invariant system:
y(n) = [s(n) + s(n 1)]/2,
(1.1)
where s(n) is a periodic signal, s(1) = s(N ), N 2. The output y is a smoother signal
with higher frequency component damped and low frequency component maintained. To
see this, let s(n) = sin(2 f n/N ), then:
1
1
s(n) + s(n 1)
2
2
1
1
=
sin(2 f n/N ) + sin(2 f (n 1)/N )
2
2
1
1
=
(1 + cos(2 f /N )) sin(2 f n/N ) sin(2 f /N ) cos(2 f n/N ),
2
2
= A1 sin(2f n/N ) A2 cos(2 f n/N ),
y(n) =
where:
1
1
A1 = (1 + cos(2 f /N )), A2 = sin(2 f /N ).
2
2
(1.2)
At low frequency, f 0, A1 1, A2 0, so
y(n) sin(2 f n/N ) = s(n).
Low frequency input is almost preserved.
At high frequency, f N/2 (near Nyquist frequency), A1 0, A2 0, so y(n) 0. High
frequency input is almost zeroed out.
fft
magnitute
of
h=[1/2,1/2,zeros(1,126)]
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
20
40
60
80
100
120
140
1.2
Convolution
A useful way to view filtering is by convolution. The first type of convolution is:
Definition 1.1 (Circular Convolution). Let x and y C N . Circular convolution vector
w = (w1 , w2 , , wN 1 ) C N is:
wm =
N
1
X
xk y(mk) mod N ,
(1.3)
k=0
fft
magnitute
of
h=[1/2,1/2,zeros(1,126)]
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
20
40
60
80
100
120
140
My =
y0
y1
y2
yN 1
yN 1 yN 2
y0
yN 1
y1
y0
yN 2 yN 3
y1
y2
y3
y0
The matrix My is called circulant matrix, notice that its row entries rotate around. Alternatively, each diagonal is a vector with identitical entries.
In Matlab, the command
diag(y0 ones(N, 1), 0),
produces the N N diagonal matrix with y0 on the diagonal. The command
diag(y1 ones(N 1, 1), 1),
gives the N N matrix with y1 on the first subdiagonal. Similarly,
diag(yN 1 ones(N 1, 1), 1),
gives the N N matrix with yN 1 on the first super-diagonal. Next do
diag(y2 ones(N 2, 1), 2) + diag(yN 2 ones(N 2, 1), 2),
to fill in the next sub(super)-diagonals, and so on. Adding these matrices up generates My .
The two point moving average filter can be written (strictly speaking approximated) as
circular convolution w = x h, h0 = 1/2, h1 = 1/2, hk = 0, k = 2 : N 1. In Matlab, do:
N = 8;
Mh = diag(1/2 ones(N, 1), 0) + diag(1/2 ones(N 1, 1), 1);
Mh (1, N ) = 1/2,
display shows that Mh has 1/2 on the main diagonal, first subdiagonal, and upper right
corner. Now enter:
x = [1, 1, 1, 1, 1, 1, 1, 1]0 ; w = Mh x,
4
1.3
Example: two point difference, consider the linear time invariant system:
y(n) = [s(n) s(n 1)]/2,
(1.4)
where s(n) is a periodic signal, s(1) = s(N ), N 2. The output y is a less smooth signal
with low frequency component damped and frequency component maintained.
In Matlab, define h = [1/2, 1/2, zeros(1, 6)], x = [1, 1, 1, 1, 1, 1, 1, 1]; then:
w = real(if f t((f f t(x). f f t(h)))) = [1, 0, 0, 0, 1, 0, 0, 0],
5
notice that two point differencing zeros out identical entries, and maintains entries with
sign change. The first 1 is due to the last -1 in x, the middle -1 stays because the entry in
front of it equals 1.
To visualize the filtering effect in Fourier domain, define h = [1/2, 1/2, zeros(1, 126)],
plot(abs(fft(h))),
we get Figure 2 which shows a high pass filter.
1.4
Eigenvector v 6= 0 is a special vector of a square matrix A such that A v lies in the same
direction of v:
A v = v, v 6= 0,
(1.5)
(1.6)
shows that A I is degenerate (or its rows are not linearly independent), hence:
determinant|A I| = 0.
(1.7)
1 2
1 0
= 2 2 = 0.
shows that:
D=
V =
2 0
0 1
0.8944 0.7071
0.4472 0.7071
1 1
1 0
3 i)/2,
1.5
If eigenvalues are distinct, the corresponding eigenvectors are linearly independent. Consider 1 6= 2 , suppose there are two constants c1 and c2 such that:
c1 V1 + c2 V2 = 0,
(1.8)
where V1 and V2 are corresponding eigenvectors. Then multiplying A on both sides of (1.8)
gives:
c1 1 V1 + c2 2 V2 = 0.
(1.9)
7
(1.10)
(1.11)
1.6
(1.12)
the complex conjugate of the m-th row vector of DFT matrix, m = 0, 1, , N 1. Then
DFT(EN,m ) = N (k m). Let w = h EN,m , then
W = DF T (w) = DF T (h)(k). N (k m) = N DF T (h)(m) (k m),
ifft back to get:
w = h EN,m = Mh EN,m = DF T (h)(m) EN,m .
(1.13)
m2
X
(2.1)
m=m1
n
X
xa (m) ya (n m), 0 n N 1.
(2.2)
m=0
N
1
X
m=0
n
X
xa (m) ya (n m modN )
N
1
X
xa (m) ya (n m) +
m=0
xa (m) ya (n m + N ).
(2.3)
m=n+1
For the product term in the second sum to be nonzero, the lengths N1 and N2 of x and y
satisfy the constraints:
n + 1 m N1 1,
0 n m + N,
n m N1 .
(2.4)
(2.5)
(2.6)
The last inequality (2.6) can be seen as follows. If n m > N1 , then n m + N >
N N1 = N2 1, so ya (n m + N ) = 0. The two inequalities (2.5)-(2.6) combine into:
N1 + n m N + n,
(2.7)
(2.8)
Y (z) =
N
1 1
X
n=0
N
2 1
X
xn z n ,
(2.9)
yn z n ,
(2.10)
n=0
they are called z-transforms of x and y respectively. The z-transform of linear convolution
w equals X(z)Y (z) which has N1 + N2 1 coefficients.
In Matlab, w = conv(x, y).
Example: compute w = x y, x = [2, 3], y = [1, 4, 5],
w = conv(x, y) = [2, 5, 2, 15].
(2.11)
2.1
(2.12)
Here mod z N means that z n and z nN are regarded as the same, for any integer n.
10
Example: x = [1, 1, 1], y = [1/2, 1/2, 0], x y = [0, 1, 0] (check it in Matlab). On the
other hand, X(z) = 1 + z 1 z 2 , Y (z) = 1/2 + 1/2z 1 , direct multiplication shows:
X(z)Y (z) = 1/2 + z 1 1/2z 3 = z 1 mod z 3 ,
also producing vector [0, 1, 0].
A simple way to see (2.12) other than direct verification by multiplication is as follows.
Let k = e2ik/N , the k-th root of unity. Then by definition of DFT, W (k ) is DFT(w),
similarly for x and y, so:
W (k ) = X(k )Y (k ),
0 k N 1. Define:
P (z) = X(z)Y (z) mod z N .
Because km = kn if m = n mod N ,
P (k ) = X(k )Y (k ),
so P (k ) = W (k ). It follows that the degree N 1 polynomial z N 1 (W (z) P (z))
vanishes at k , k = 0, 1, , N 1, or has N distinct roots, so it must be identically zero,
or W (z) P (z).
Formula (2.12) yields an algorithm for computing circular convolution by linear convolution. The linear convolution u = x y corresponds to coefficients in X(z)Y (z), which
contains powers z 0 , z 1 , , z 2(N 1) . To get circular convolution, we add the coefficients
of z n and z nN , for n = 0, 1, , N 2,
w(n) = u(n) + u(n + N ),
while w(N 1) = u(N 1).
2.2
+
X
n=
x(n) z n ,
(2.13)
+
X
a z
n=0
+
X
(az 1 )n =
n=0
1
,
1 a z 1
x(n m) z n =
So z 1 means delay by 1.
Time reversal: w(n) = x(n) = W (z) = X(z 1 ).
Multiplication: w(n) = an x(n) = W (z) = X(z/a), if a 6= 0.
Differentiation: w(n) = nx(n) = W (z) = z dX(z)/dz.
Linear convolution: w(n) = (x y)(n) = W (z) = X(z) Y (z).
Example 3: The moving average linear system:
y(k) = (x(k) + x(k 1))/2,
is z-transformed into:
Y (z) = (1/2 + 1/2 z 1 ) X(z).
The function (1/2 + 1/2 z 1 ) is called transfer function, denoted by H(z).
A more general linear shift invariance filtering system is of the form:
y(k) + a2 y(k 1) + + am+1 y(k m) = b1 x(k) + b2 x(k 1) + + bn+1 x(k n), (2.14)
assuming zero initial condition (causality). So in time:
y(1) = b1 x(1),
12
b1 + b2 z 1 + + bn+1 z n
.
1 + a2 z 1 + + am+1 z m
Matlab Projects
References
[1] S. A. Broughton and K. Bryan, Discrete Fourier Analysis and Wavelets, Wiley, 2009.
[2] R. C. Gonzalez and R. E. Woods, Digital Image Processing, Third Edition, Pearson
Prentice Hall, 2008.
[3] W. Hartmann, Signals, Sound, and Sensation, Springer, AIP Series in Modern Acoustics and Signal Processing, 4th edition, 2000.
[4] B. Porat, A course on digital signal processing, John Wiley and Sons, 1997.
14