542 Practical MATLAB® Applications for Engineers
g. Estimate and plot (Figure 5.59) the magnitude and phase errors of the two methods
in the frequency domain defi ned by the following relations:
mag_error = abs{fft[gf (n)]} − abs{fft[gc(n)]}
phase_error = angle{fft[gf (n)]} − angle{fft[gc(n)]}
over the range 1 ≤ k ≤ 50.
The MATLAB solution for Example 5.13 is given by the script fi le discrete_syst as
follows:
ANALYTICAL Solution
Part a
g(n) = 0.7g(n − 1) − 0.3g(n − 2) + f(n) + 0.9f(n − 1)
g(n) − 0.7g(n − 1) + 0.3g(n − 2) = f(n) + 0.9f(n − 1)
Taking the ZT yields
G(z) − 0.7z−^1 G(z) + 0.3z−^2 G(z) = F(z) + 0.9z−^1 F(z)
G(z)[1 − 0.7z−^1 + 0.3z−^2 ] = F(z)[1 + 0.9z−^1 ]
Hz
z
zz
()
109
107 03
1
12
.
..
Part b
Replacing z = ejW
He
Ge
Fe
e
ee
jW jW
jW
jW
() jW j W
()
()
.
..
109
107 032
MATLAB Solution
% Script file: discrete _ syst
num = [1 0.9];
den = [1 -0.7 0.3];
n = 1:1:50;
fn = 0.9.^n.*sin(0.033*pi.*n);
gnf = filter(num,den,fn);
figure(1) % input and output plots
subplot(2,1,1)
plot(n,fn,’o’,n,fn);
title(‘[System input sequence f(n)] vs n’)
xlabel(‘time index n’);ylabel(‘Magnitude’)
subplot(2,1,2)
plot(n,gnf,’s’,n,gnf);