Академический Документы
Профессиональный Документы
Культура Документы
Abstract
Class notes on filtering, convolutions, eigenvalue/eigenvector, diagonalization, and
z-transform.
1 Filtering
Filtering refers to linear transforms that change the frequency contents of signals. Depend-
ing on whether high (low) frequencies are attenuated, filtering process is called low (high)
pass.
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
y(n) = 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 ), (1.2)
where:
1 1
A1 = (1 + cos(2 f /N )), A2 = sin(2 f /N ).
2 2
Department of Mathematics, UCI, Irvine, CA 92617.
1
At low frequency, f 0, A1 1, A2 0, so
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
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:
2
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
0 20 40 60 80 100 120 140
w0 = [x0 x1 x2 xN 1 ] [y0 yN 1 yN 2 y1 ],
similarly
w1 = [x0 x1 x2 xN 1 ] [y1 y0 yN 1 y2 ],
and
w2 = [x0 x1 x2 xN 1 ] [y2 y1 y0 y3 ],
wN 1 = [x0 x1 x2 xN 1 ] [yN 1 yN 2 yN 3 y0 ].
3
where x = [x0 x1 x2 xN 1 ], and
y0 yN 1 yN 2 y1
y1 y0 yN 1 y2
y2 y1 y0 y3
My =
yN 1 yN 2 yN 3 y0
The matrix My is called circulant matrix, notice that its row entries rotate around. Alter-
natively, each diagonal is a vector with identitical entries.
In Matlab, the command
diag(y0 ones(N, 1), 0),
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 (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
we see w = zeros(8, 1). Oscillation in x is averaged out to zero.
Now re-define x and calculate w:
x = [1, 1, 1, 1, 1, 1, 1, 1]0 ; w = Mh x
gives:
w = [0, 1, 0, 0, 1, 0, 0, 0],
So we take fft to do regular multiplication in Fourier domain, then ifft back to recover w.
For the above example, enter one line in Matlab:
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:
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.
(A I)v = 0, (1.6)
shows that A I is degenerate (or its rows are not linearly independent), hence:
determinant|A I| = 0. (1.7)
[V, D] = eig(A)
6
shows that:
2 0
D=
0 1
0.8944 0.7071
V =
0.4472 0.7071
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
Equations (1.8)-(1.9) can be combined into:
1 1 c1 V 1
= 0,
1 2 c2 V 2
where V1 and V2 are row vectors. Because 1 6= 2 , the left square matrix in invertible
(or has nonzero determinant), hence c1 V1 = 0, c2 V2 = 0, implying that c1 = c2 = 0 since
V1 6= 0 and V2 6= 0. The general case follows in similar manner.
If matrix A is order N N with N distinct eigenvalues, then putting the eigenvectors
together form an invertible matrix V = [V1 V2 VN ], here Vj0 are column vectors. It
follows that
A V = V D, (1.10)
where D is a diagonal matrix with 1 , , N on its diagonal. Taking inverse of V gives:
V 1 A V = D, (1.11)
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
8
2 Linear Convolution and z-Transform
Given x = x(n), n = 0, , N1 1; y = (y(n)), n = 0, , N2 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, (2.4)
0 n m + N, (2.5)
n m N1 . (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)
9
which allows one to use fft to calculate linear convolution.
The linear convolution can be computed by multiplying two polynomials with coeffi-
cients from x(n) and y(n). Define the z-polynomials:
N
X1 1
X(z) = xn z n , (2.9)
n=0
N
X2 1
Y (z) = 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],
Finally:
X(z) = 2 + 3z 1 ,
Y (z) = 1 4z 1 + 5z 2 ,
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:
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 ),
11
Example 2: Let a be a complex number, x(n) = an if n 0, x(n) = 0 if n < 0. Then:
+ +
X
n
X 1
X(z) = n
a z = (az 1 )n = ,
n=0 n=0
1 a z 1
Linearity: w(n) = a x(n) + b y(n) = W (z) = a X(z) + b Y (z), for any two complex
numbers a and b.
X X
x(n m) z n = x(n) z (n+m) = z m X(z).
n n
So z 1 means delay by 1.
is z-transformed into:
Y (z) = (1/2 + 1/2 z 1 ) X(z).
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)
y(1) = b1 x(1),
12
y(2) = b1 x(2) + b2 x(1) a2 y(1)
y = filter(b, a, x).
3 Matlab Projects
1. Write a Matlab function expressing circular convolution by linear convolution command
conv.
function z=cconv(x,y);
% input vectors x, y are two vectors to be convolved
% output vector z: result of circular convolution
N=length(x);
if (length(y) = N);
error(vectors of unequal lengths); end
z=conv(reshape(x,1,N),reshape(y,1,N));
z=z(1:N)+[z(N+1:2*N-1),0];
Test on some vectors x and y, and compare with real(ifft((fft(x).*fft(y)))).
2. Let x be the step function defined as x = zeros(1, 128), x(64 : 128) = 1. Filter it 20
times by the moving average filter as follows:
13
a = 1; b = [1/21/2]; plot(x), hold on;
for i=1:20, y=filter(b,a,x); x=y; end;
plot(y,r).
3. Define one second duration signal with two tones at (3, 40) Hz sampled at 100 Hz:
fs=100;
t=0:1/fs:1;
x=sin(2*pi*t*3) + 0.25*sin(2*pi*t*40);
Next define 10-point moving average filter:
b=ones(1,10)/10;
y=filter(b,1,x);
plot(t,x,t,y,r).
Comparing output y with input x, we notice that 40 Hz tone is removed, however there
is a delay in y (phase distortion). Matlab double filter function filtfilt corrects the phase
distortion, which in the z-domain proceeds as follows:
b. Compare plots of sn and sq and their sounds. Also compare the magnitude of their
discrete Fourier transforms. How does their frequency content differ? Which signal has
more energy?
c. Define an ideal low pass filter that keeps only the frequencies smaller than 1000 in
magnitude. Often it is easier to proceed as if the frequency domain is centered around 0
14
and then correct this with ifftshift, a circular shift that undoes the effect of fftshift.
This can be done by defining z = -3999:4000; LP = ifftshift(abs(z)<=1000);
d. Plot LP and also plot its inverse Fourier transform, given by real(ifft(LP)). This
function should be familiar. What is it? What would be the result of applying this low
pass filter to an impulse function?
e. Apply the low pass filter LP to the square wave sq by computing LPsq = real(ifft(LP.*fft(sq)));.
How does LPsq compare to sq and sn in both the spatial and frequency domains? Also
compare the sound.
f. Repeat the above steps with a Gaussian low pass filter defined in the frequency domain
by G = ifftshift(exp(-(z.^2)/(2*sigma^2)));. Note that g = real(ifft(G)) is
also Gaussian-shaped. Try different values of and compare how this affects the width
of g and G.
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 Acous-
tics and Signal Processing, 4th edition, 2000.
[4] B. Porat, A course on digital signal processing, John Wiley and Sons, 1997.
15