PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

546 Practical MATLAB® Applications for Engineers


Example 5.14

Let the impulse response of an LTI system be given by hn n
n

().


05
0

15
∑ and the system
input sequence be fn n
n

() cos( /)


15 5 3
0

15
∑ 
.
Create the script fi le syst_anal that returns the following plots:

a. f(n) versus n and h(n) versus n, using the stem command (Figure 5.60)
b. g(n) = {IDFT of the products of DFT [f(n)] times DFT [h(n)]} versus n (Figure 5.61)
c. gnn(n) = convolution of h(n) with g(n) versus n (Figure 5.61)
d. Estimate the error plot (in the time domain) of the two approaches (parts b
and c), given by (Figure 5.62)

error(n) = [g(n) − gnn(n)] versus n

MATLAB Solution
% Script file: syst _ anal
n = 0:15;
fn = cos(5*pi*n/3);
hn = 0.5.^n; % the length of convolution is 16*2-1
DFT _ F = fft(fn,31);
DFT _ H = fft(hn,31);
gn = ifft(DFT _ F.*DFT _ H);
figure(1)
subplot(2,1,1)
stem(n,fn)
ylabel(‘Amplitude’);axis([0 15 -1.2 1.2]);
title(‘ [Input sequence f(n)] vs n ‘)
subplot(2,1,2)
stem(n,hn)
ylabel(‘Amplitude ‘);axis([0 15 -0.5 1.2]);
xlabel(‘time index n’); title(‘[Impulse response h(n)] vs n’)
figure(2) % output plots
subplot(2,1,1)
nn=0:1:30;
plot(nn,gn);title(‘[IDFT of the products of the DFTs ] vs n’);
xlabel(‘time index n ’); ylabel(‘Amplitude’);axis([0 25 -1.5 2]);
subplot(2,1,2)
gnn=conv(fn,hn);
plot(nn,gnn);axis([0 25 -1.5 2]);
xlabel(‘time index n’), ylabel(‘Amplitude’)
title(‘[Direct convolution in the time domain] vs. n’);
figure(3)
error = gn-gnn;
bar(nn,error);title(‘ Error =[part(b)-part(c)] vs. n’ );
xlabel(‘time index n’), ylabel(‘Magnitude’);

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

>> syst _ anal
Free download pdf