Worked Solutions to Exercises 7.2#
Solution to Exercise 7.2.1#
See: Exercise 7.2.1
We first write down the difference equations by tracing through the signals in the block diagram of Fig. 14.
We take Z-transforms of equations (67) and (68):
Gather terms in (69) and (70):
From (72) we obtain
We then use (73) to eliminate \(W(z)\) from (71), giving
and the transfer function follows:
Solution to Exercise 7.2.2#
See: u72:ex:2
The same procedure used for Solution to Exercise 7.2.1 is used.
Solution to Exercise 7.2.3#
Design a 2nd-order Butterworth filter with \(\omega_c = 20\) kHz. Use the Bilinear transformation to convert the analogue filter to a digital filter with sampling frequency of 44.1 kHz. Use pre-warping to ensure that the cutoff frequency is correct at the equivalent digital frequency.
See: Exercise 7.2.3
The magnitude squared function of a \(k\)-th order Butterworth low-pass filter is
We need to design a filter that has \(k=2\) and \(\omega_c = 2\times\pi\times 20\times 10^3 = 125,66371\times 10^3\) rad/s. It will be easier to design the filter for \(\omega_c = 1\) then complete the design by subsitution of the actual cut-off frequency afterwards.
We follow the procedure outlined in the notes (see Butterworth Analogue Low-Pass Filter Design).
which on subsitution of \(\omega^2 = -s^2\) gives
The poles of this equation are given by \(s = \sqrt[4]{-1}\), that is \(s = \sqrt[4]{1\angle 180^\circ}\) which, by De Moivre’s theorem, with \(n = 4\),
Thus $\( \begin{array}{ll} s_1 = e^{j 3\pi/4} = -\frac{1}{\sqrt{2}} + j\frac{1}{\sqrt{2}} & s_2 = e^{j5\pi/4} = -\frac{1}{\sqrt{2}} - j\frac{1}{\sqrt{2}}\\ s_3 = e^{j 7\pi/4} = +\frac{1}{\sqrt{2}} - j\frac{1}{\sqrt{2}} & s_4 = e^{j9\pi/4} = +\frac{1}{\sqrt{2}} + j\frac{1}{\sqrt{2}} \end{array} \)$
We take the left-half plane poles \(s_1\) and \(s_2\) and
The gain \(K\) is found from \(A^2(0) = 1\), and \(H(0) = 1\), so \(K=1\) and the prototype Butterworth low-pass filter is
We now convert this to the filter we need by substitution \(s = s/\omega_c\)
from which
and
We will complete the problem by switching to MATLAB. We first need to determine the pre-warping correction
fs = 44.1e2; % sampling frequency
Ts = 1/fs;
wc = 2*pi*20e3
wa = (2/Ts)*tan(wc*Ts/2)
Re calculate Butterworth filter with pre-warped frequency
Hs = tf(wa^2,[1 sqrt(2)*wa wa^2])
Now find \(H(z)\) using the bilinear transformation by substituting
You should try this algebraicly, but we will cheat
Hz = c2d(Hs,Ts,'tustin')
From which
To implement this, we simply convert to negative powers of \(z\)
Solution to Exercise 7.2.4#
A digital filter with cutoff frequency of 100 Hz for a signal sampled at 1 kHz has transfer function
\[H(z) = \frac{0.6401 -1.1518z^{-1} + 0.6401z^{-2}}{1 -1.0130 z^{-1} + 0.4190z^{-2}} \]The frequency response for this filter (plotted against \(f/(f_s/2)\)) is shown in Fig. 25.
a) What type of filter is this?
b) Estimate the band-pass ripple, and stop-band ripple of the filter.
c) Implement the filter as Direct Form Type II digital filter and sketch its block diagram.
d) Use the example of Convert to code to give a code implementation of the filter.
e) If the input to this filter is a step function \(x[n] = \left\{1,1,1,1,\ldots\right\}\), calculate the first 5 outputs \(y[n]\) of the filter.
See: Exercise 7.2.4
This is a 2nd-order filter designed to have a cut-off frequency of \(100\) Hz. Beacuse it is low-order, the ripple is rather non-typical!
a) The gain at high frequency is 0 dB so the filter is high-pass. There is ripple in the stop-band so it is Chebyshev Type II.
b) The stop-band ripple is 10 dB, there is no ripple in the pass-band. Note that it is not clear that the cut-off frequency is 100 Hz! Any value near the -3dB cut-off frequency will be taken as correct.
c) For the sketch, refer to Fig. 17 and note that the coefficients will be: \(b_0 = 0.6401\), \(b_1 = -1.1518\), \(b_3 = 0.6401\), \(a_1 = 1.0130\), \(a_2 = 0.4190\). Note in particular the signs of the \(a\) coefficients. They are negative in the block diagram but positive in the transfer function.
d) To write the code, we need to express the transfer function as a difference equation.
So
Taking inverse Z-transform:
Using the example in Convert to code with \(T_s = 1/1000 = 0.001\)
/* Initialize */
Ts = 0.001; /* more probably some fraction of clock speed */
ynm1 = 0; ynm2 = 0; unm1 = 0; unm2 = 0;
while (true) {
un = read_adc();
yn = 0.6401*un + −1.1518*unm1 + 0.6401*unm2 + 1.0130*ynm1 - 0.4190*ynm2;
write_dac(yn);
/* store past values */
ynm2 = ynm1; ynm1 = yn;
unm2 = unm1; unm1 = un;
wait(Ts);
}
e) The easiest way to complete the problem is to tabulate the data
\(n\) |
\(x[n]\) |
\(0.6401 x[n]\) |
\(-1.1518 x[n-1]\) |
\(0.6401 x[n-2]\) |
\(1.0130 y[n-1] \) |
\(- 0.4190 y[n-2]\) |
\(y[n]\) |
---|---|---|---|---|---|---|---|
\(0\) |
\(1\) |
\(0.6401\) |
\(0\) |
\(0\) |
\(0\) |
\(0\) |
\(0.6401\) |
\(1\) |
\(1\) |
\(0.6401\) |
\(-1.1518\) |
\(0\) |
\(0.6486\) |
\(0\) |
\(0.1369\) |
\(2\) |
\(1\) |
\(0.6401\) |
\(-1.1518\) |
\(0.6401\) |
\(0.1387\) |
\(-0.2682\) |
\(-0.011\) |
\(3\) |
\(1\) |
\(0.6401\) |
\(-1.1518\) |
\(0.6401\) |
\(-0.0011\) |
\(-0.0574\) |
\(0.0700\) |
\(4\) |
\(1\) |
\(0.6401\) |
\(-1.1518\) |
\(0.6401\) |
\(0.0709\) |
\(0.0004\) |
\(0.1997\) |
from which \(y[n] = \left\{0.6401,0.1369,-0.011,0.0700,0.1997,\dots\right\}\)
I find the use of Excel to be a useful tool for confirming such results and the sheet for this one can be downloaded sol_ex_7_2_3.xlsx.
You can also use MATLAB of course. Here we set up the transfer function:
fs = 1000;
Ts = 1/fs
Hz = tf([0.6401,-1.1518,0.6401],[1,-1.0130,0.4190],Ts)
Then compute the step response
[yn,nTs] = step(Hz);
stem(nTs*1000,yn),grid,title('Step response of filter in Exercise 7.2.3'),xlabel('Time [ms]')
ylabel('y[n]')
Confirm the tabulated results
yn(1:5)