PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

DTFT, DFT, ZT, and FFT 543


title(‘[System output sequence g(n)] vs n, using filter’)
xlabel(‘time index n’);ylabel(‘Magnitude’)
figure(2) % impulse analysis
hn = impz(num,den,n);
subplot (2,1,1)
stem(n,hn);
title(‘ [System impulse response h(n)] vs n, using impz’)
ylabel(‘Amplitude’); xlabel(‘time index n’)
subplot(2,1,2)
nn=0:1:50;
gnc=conv(hn,fn);
stem(nn(1:1:50),gnc(1:1:50))
title(‘ [System output g(n)] vs n, using convolution’)
ylabel(‘Amplitude’);xlabel(‘time index n’)
figure(3) % frequency analysis
DFT _ gnf = fft(gnf); abs _ DFT _ gnf = abs(DFT _ gnf);
ang _ DFT _ gnf=angle(DFT _ gnf);
DFT _ gnc = fft(gnc);abs _ DFT _ gnc=abs(DFT _ gnc);
ang _ DFT _ gnc=angle(DFT _ gnc);
subplot(2,2,1); stem(nn(1:1:50),abs _ DFT _ gnf(1:1:50));
ylabel(‘abs[fft(gf(n))]’);
title(‘abs[fft(gf(n))] vs k’)
axis([0 50 0 20]);
subplot(2,2,2)
stem(nn(1:1:50),ang _ DFT _ gnf(1:1:50));title(‘angle[fft(gf(n))] vs k’);
ylabel(‘angle[fft(gf(n))]’);
axis([0 50 -4 4]);
subplot(2,2,3);
stem(nn(1:1:50),abs _ DFT _ gnc(1:1:50));title(‘abs[fft(gc(n))] vs k’);
xlabel(‘index k’);ylabel(‘abs[fft(gc(n))]’);axis([0 50 0 20])
subplot(2,2,4)
stem(nn(1:1:50),ang _ DFT _ gnc(1:1:50));title(‘angle[fft(gc(n))] vs k’);
xlabel(‘index k’);ylabel(‘angle[fft(gc(n))]’);
axis([0 50 -4 0])
figure(4) % error analysis
subplot(3,1,1)
error _ time = gnf(1:1:50)-gnc(1:1:50);
bar(nn(1:1:50),error _ time);axis([0 50 -0.5 0.5]);
title(‘ error plots in time and frequency’)
ylabel(‘Amplitude’)
subplot(3,1,2)
mag _ error = abs _ DFT _ gnf(1:1:50)- abs _ DFT _ gnc(1:1:50);
phase _ error = ang _ DFT _ gnf(1:1:50)- ang _ DFT _ gnc(1:1:50);
bar(nn(1:1:50),mag _ error); ylabel(‘Magnitude error’)
axis([0 50 -10 10])
subplot(3,1,3)
bar(nn(1:1:50),phase _ error);ylabel(‘phase error’);
axis([0 50 -10 10]); xlabel(‘index k’);

The script fi le discrete_syst is executed, and the results are as follows:

>> discrete _ syst
Free download pdf