# Digital Signal Processing II

Homework 4 Solutions
Due Tuesday 4 February 2014

1. A lattice structure can be used for filter implementation.
a.) In Figure(a) below, write the difference equation for y[n] for input x[n]. Find the values for the
multiplier coefficients for:
i. A filter with a zero at z = -1 and a pole at z = 0.5
ii. An allpass filter with a pole at z = -0.5 and a zero at z = -2
b.) In Figure(b) below, write the z-transform for the output of each adder. Write the difference
equation for y[n] for input x[n].

(a)

(b)

(a) (b)
[] [] [ ]
[] [] [ ]
[] ([] [ ]) [ ] [ ]
[] [] [ ] [ ] [ ]
[] [] [ ] [ ]

This system has a zero at and a pole at
.

For a zero at z = -1 and a pole at z = 0.5, and
.

For a zero at z = -2 and a pole at z = -0.5, .
Inner structure

()

()

()
()

()

()
Outer structure

() ()

()
()

()

()

()(

)

()
() (

)

()
(

)

()

() ()

(

)

()
()
( ( )

)

()

()

()

(

)

()
()
( ( )

)

()

()
( ( )

)
( ( )

)
()

(1)
(2)

(3)
(4)

(1a)
(2a)

(3a)

(4a)

2. Use the algebraic stability test to determine if systems with the following denominator polynomials are
a.) ()

b.) ()

c.) ()

d.) ()

e.) ()

d1 d2 |d2| < 1? 1+d2 |d1| < 1+d2?
a.) -0.5 +0.75 Yes 1.75 Yes Stable
b.) -0.5 -0.75 Yes 0.25 No Unstable
c.) +0.5 +0.75 Yes 1.75 Yes Stable
d.) -1.5 +0.9 Yes 1.9 Yes Stable
e.) -1.5 +1.2 No Unstable

3. Let G(z) be the plant model for a system with input X(z) and output Y(z). A feedback controller C(z) is
designed for the system as shown below.

a.) Write the general expression for the transfer function of the system
b.) For ()

and C(z) = K, find the range of values
of K for which the controlled system is stable.
c.) Repeat (b) for ()

a.)
() () ()()
() ()() ()(() ()())
()
()
()

()
()()

()
()

b.)
()

()

()

( )

Using the algebraic stability test, this is table if

⇒ and
|

|

⇒ . The system is
stable if both conditions are met, so 0 < K < 0.5.
c.)
()

()

() ( )

Using the algebraic stability test, this is table if

and
|

| | |

⇒ .
The system is stable if both conditions are met, so
-3.0 < K < 0.

4. An "ideal" low pass filter can be approximated by computing the IDTFT of the ideal frequency response,
| |
( )
n
n
n h
c
t
e sin
= , then windowing it with a rectangular widow of length N=2M+1 centered at n=0, and
then shifting it by M samples to make it causal.

a.) Using this method, compute the impulse response and frequency response for a low pass filter with
e
c
=0.2t and length N = 15 (M=7).
- Plot the impulse response using stem.
- Plot the magnitude of the frequency response using freqz with 256 points.
- Plot the log magnitude frequency response.(You may want to protect against the problem of
taking the log of 0 by making sure the minimum magnitude can not be lower than a very small
value.)
- If the pass-band is defined by having a magnitude greater than 0.95 and the stop-band by having
a magnitude less than 0.15, find the frequencies for the pass-band edge and stop-band edge. How
wide is the transition band?
- If the sampling frequency is 8000Hz, find the pass-band and stop-band frequencies of this filter.
b.) Repeat (a) for a length of 75 (M=37). Define the stop-band by a maximum value of 0.1 instead of 0.15.

e
c
f
c
= 0.2t( 8000 Hz/2t) Hz
= 800 Hz
Pass band edge Stopband edge Transition band width
M=7, length = 15 500.000 Hz 1015.600 Hz 515.6 Hz
M=37, length = 75 734.375 Hz 859.375 Hz 125.0 Hz
In both cases the edge frequencies and the limits are shown in green for the passband and red for the stopband.
(Plotting the passband edge and stop band edge was not requested in the problem statement.) Note that for both
filters the maximum height of the impulse response at the center is ec/t = 0.2t /t = 0.2.

%
nfilter=[15,75];
minpass=[0.95, 0.95];
minstop=[0.15, 0.10];
%
Fs=8000;
Fs2=0.5*8000;
maxdb=5.0;
mindb=-60;
for k=1:2
n = nfilter(k);
n2=(n-1)/2; % n is odd number
nv=-n2:n2;
wc=0.2;
h=sin(wc*pi*nv)./(pi*nv);
h(nv==0)= wc;
%
subplot(2,3,3*k-2)
stem(h)
hmx=max(abs(h));
axis([ 0 (n+1) (-0.1*hmx + min(0,min(h)))
(0.1*hmx + max(h)) ])
if( k== 1)
title(' Impulse response')
end
%get freq response
[H,w] = freqz(h,1,256);
Hdb = 20*log10(abs(H));
magH = abs(H);
subplot(2,3,3*k-1)
plot((Fs2/pi)*w, magH)
axis([0, Fs2, -0.1, 1.1*max(magH) ])
if( k== 1)
title('Frequency response')
end

subplot(2,3,3*k)
plot((Fs2/pi)*w, Hdb)
axis([ 0 Fs2 mindb maxdb])
if( k== 1)
title('Frequency response in dB')
end
% Note: passband and stopband limits
selected so
% that FIR response is monotonic at those
levels.
% For arbitraty levels, more complex
processing
% than shown is needed to find the band
edges

hold on
passH=find(magH >minpass(k));
w1=max(passH);
wpassedge=w(w1)*Fs2/pi
hpassedge=Hdb(w1);
hplim = 20*log10(minpass(k));
%
plot([0 Fs2],[hplim hplim],'g')
plot([wpassedge wpassedge],[mindb
maxdb],'g')
%
stopH = find(magH <minstop(k));
w2=min(stopH);
wstopedge=w(w2)*Fs2/pi
hstopedge=Hdb(w2);
hslim = 20*log10(minstop(k));
%
plot([0 Fs2],[hslim hslim],'r')
plot([wstopedge wstopedge],[mindb
maxdb],'r')
%
hold off
end

5. Specify the cutoff frequencies of low pass filters needed to create the following desired filters by adding
and subtracting multiple low pass filters. Using MATLAB, find the coefficients for the desired filter and
plot both the magnitude and the log magnitude as in the previous problem. Use M = 15 (length = 31).
a.) A high pass filter which passes frequencies above .
b.) A band pass filter which passes frequencies between and .
c.) A band pass filter which passes frequencies between and .
d.) A filter which has a gain of 2 for frequencies between and , a gain of 1 for frequencies
between and , and a gain of 3 for frequencies between and .

a.) First figure below. Top row:

[] is a low pass filter with

. Second row:

[] is a “low pass”
filter with

. This is an all pass filter with a single 1 at the center of the filter to implement a bulk
delay of half the filter length. Bottom row: The desired filter is

[]

[]. This is a high pass filter.
b.) Second figure below. Top row:

[] is a low pass filter with

. Second row:

[] is a low
pass filter with

. Bottom row: The desired filter is

[]

[]. This is a band pass filter.
c.) Third figure below. Top row:

[] is a low pass filter with

. Second row:

[] is a low pass
filter with

. Bottom row: The desired filter is

[]

[]. This is a band pass filter. It is not
a very good one because the transition width for this length filter is about the same width as the desired
pass band and the transition is not sharp enough to form the desired narrow pass band. A longer filter
length is needed to make a better filter.
d.) Fourth figure below. Top row:

[] is a low pass filter with

. Second row:

[] is a low pass
filter with

. Third row:

[] is a “low pass” filter with

. Bottom row: The desired filter
is

[]

[]

[] .

a.)

b.)

c.)

d.)

L = 31;
for k = 1:4
if(k == 1)
wc = pi*[0.8, 1.0];
ac = [-1, 1];
elseif(k == 2)
wc = pi*[0.25, 0.75];
ac = [-1, 1];
elseif(k == 3)
wc = pi*[0.5, 0.55];
ac = [-1. 1];
else
wc = pi*[0.4, 0.7, 1.0];
ac = [1, -2, 3];
end
figure(k)
ha = zeros(1,L);
%
for m = 1:length(wc)
wco = wc(m);
LC = (L-1)/2;
nv = -LC:LC;
h = sin(wco*nv)./(pi*nv);
h(LC+1) = wco/pi;
ha = ha + ac(m)*h;
subplot(4,3,3*m -2)
stem([0:L-1], h)
subplot(4,3,3*m-1)
[H W] = freqz(h, 1, 512);
plot(W,abs(H))
axis([ -0.1, pi+0.1, -0.1, 1.3])
hold on
plot([0, wco, wco, pi] ,[ 1, 1, 0, 0],'r:')
hold off
subplot(4,3,3*m)
plot(W,20*log10(abs(H)))
end
subplot(4,3,10)
stem([0:L-1], ha)
subplot(4,3,11)
[H W] = freqz(ha, 1, 512);
plot(W,abs(H))
axis([ -0.1,pi+0.1,-0.1,max(1.3,max(abs(H)))])
subplot(4,3,12)
plot(W,20*log10(abs(H)))
if (k == 4)
axis([ -0.1, pi+0.1, -5, 12])
else
axis([ -0.1, pi+0.1, -80, 5])
end
end

6. Four window functions often used to truncate an infinite length ideal impulse response are defined below.
In all cases the width of the window is 2M+1.

Window:
Rectangular
| | M n M n w s s ÷ =1
Hann
| | M n M
M
n
n w s s ÷
|
|
.
|

\
|
|
.
|

\
|
+ =
t
cos 1 5 . 0
Hamming
| | M n M
M
n
n w s s ÷
|
.
|

\
|
+ =
t
cos 46 . 0 54 . 0
Blackman
| | M n M
M
n
M
n
n w s s ÷
|
.
|

\
|
+
|
.
|

\
|
+ =
t t 2
cos 08 . 0 cos 50 . 0 42 . 0

a.) For 2M+1=15, create each window and plot each on the same page using stem. (Use a 4x3
subplot array.) Then use freqz with N=256 to compute the frequency response and plot the
magnitude of each on the same page using plot. Plot 20*log10 of the magnitude also. On these
plots find the width of the main lobe and the maximum gain of the side lobes.
b.) Repeat for 2M+1=31.
c.) Repeat for 2M+1=63.
a.) The four length 15 window functions are shown in the left column of the first set of plots below. The center
column shows the magnitude response over the full frequency range 0 to t. The right column shows 20log10
(amplitude relative to maximum amplitude) over the same full range of frequencies.
It is clear that the width of the main lobe of the Hann and Hamming windows is twice the width of the rectangular
widow. The width of the Blackman window is three times the width of the rectangular window. The main lobe width
will control the transition band width for a windowed ideal filter.
The magnitude of the sidelobes is highest for the rectangular window and lowest for the Blackman. The sidelobes
for the Hamming window are all about the same height while the sidelobes for the Hanning window start out higher
and continue to decrease. The sidelobe magnitude controls the ripple of a windowed ideal filter.

The second set of plots shows the same information for the length 15 windows except the frequency axis goes from
0 to 3x the mainlobe halfwidth. The green vertical lines on the log plots show the edges of the main lobe and the
horizontal red lines show the height of the first sidelobe from the table presented in class. This verifies the
correctness of the table. These plots were NOT requested in the problem statement.

b.) For the length 31 window, the width of the mainlobe is about half the width of the main lobe of the width 15
window. The magnitude of the first sidelobe does not depend on the window length.

function comparewind(N, plottype)
%
N2=(N-1)/2;
tv = [-N2:N2];
halfmainL = [2/N 4/N 4/N 6/N]*pi;
relSL = [13.3 31.5 42.7 58.1];
for k=1:4
if(k == 1)
windfun=boxcar(N);
elseif (k == 2)
windfun=hanning(N);
elseif( k == 3)
%windfun=hammimg(N);
windfun= 0.54 + 0.46*cos(2*pi*tv/N);
else
windfun=blackman(N);
end

[H,w] = freqz(windfun,1, 512);
subplot(4,3,3*k-2)
stem(tv,windfun)
axis( [-N/2 N/2 -0.1 1.1]);
subplot(4,3,3*k-1)
plot(w, abs(H))
if( plottype == 1)
axis([ 0 3*halfmainL(k) -0.001 1.1*max(abs(H))])
else
axis([ 0 pi -0.001 1.1*max(abs(H))])
end
%
subplot(4,3,3*k)
H0=20*log10(abs(H(1)));
plot(w, (20*log10(abs(H)) - H0) )
axis([0 pi -100 0])
if(plottype == 1)
hold on
axis([ 0 3*halfmainL(k) -100 0])
plot( [0 pi], [ -relSL(k) -relSL(k)], 'r');
plot( [halfmainL(k) halfmainL(k)], [-110 -10],'g');
hold off
end
end

a.) 2M+1 = 15

Frequency axis is
0 to 3x half the
main lobe width.

b.) 2M+1 = 31

Frequency axis is
0 to 3x half the
main lobe width.

c.) 2M+1= 63.

Frequency axis is
0 to 3x half the
main lobe width.

7. Discussion Problem – not to be turned in with the homework assignment