PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

DTFT, DFT, ZT, and FFT 553


MATLAB Solution
% Script file: diff _ eq _ res
gnpast _ step =0; m=1;
for n =0:15;
gnstep(m) = 0.5*gnpast _ step+2*1;
gnpast _ step = gnstep(m);
m = m+1;
end
gnstep = [zeros(1,5) gnstep];
figure(1)
subplot(2,1,1)
mm =-5:1:15;
stem(mm,gnstep);title(‘Simulation of step response’)
xlabel(‘time index n’);ylabel(‘Amplitude’),axis([-5 10 0 4.3])
subplot(2,1,2)
dirack=1;h _ past=0;k=1;
for n =0:15;
hn(k) = 0.5*h _ past + 2*dirack;
dirack = 0;
h _ past = hn(k);
k = k+1;
end;
hn = [zeros(1,5) hn];
stem(mm,hn)
xlabel(‘time index n’);ylabel(‘Amplitude’);axis([-5 10 0 2.1])
title(‘Simulation of impulse response’)
The script fi le diff_eq_res is executed, and the simulated results are shown in Figure 5.65.
>> diff _ eq _ res

− 5 0 5 10

0

2

4

Simulation of step response

time index n

Amplitude

− 5 0 5 10

0

1

2

time index n

Amplitude

Simulation of impulse response

FIGURE 5.65
Simulation plots of system step and impulse responses of Example 5.17.
Free download pdf