PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

554 Practical MATLAB® Applications for Engineers


Example 5.18

Evaluate by hand the transfer function of the difference equation of Example 5.17, given
by g(n) = 0.5g(n − 1) + 2f(n), and then create the script fi le step_imp that returns the
coeffi cients of discrete-step and impulse responses using system simulates and the
MATLAB commands dstep and impz, respectively. Also verify that the solutions obtained
(Example 5.17) fully agree with the solutions obtained using the MATLAB commands
by evaluating the cumulative errors by comparing the two methods.

ANALYTICAL Solution

g(n) − 0.5g(n − 1) = 2f(n)

G(z)[1 − 0.5z−^1 ] = 2F(z)

Hz
Gz
Fz z
()
()
().

 

2
1051

MATLAB Solution
% Script file: step _ imp
num = [0 2];
den = [1 -0.5];
nn = 16;

figure(2)
subplot(2,1,1)
dstep(num,den)
subplot(2,1,2)
impz(num,den)
nnn = 0:10;
[Y,X] = dstep(num,den); [YY,XX] = impz(num,den);
a = gnstep(6:16);b =(Y(2:12))’;error _ step=a-b;
c =hn(6:16);d=(YY(2:12))’;error _ imp=c-d;
disp(‘**********************************************************’)
disp(‘*********************R E S U L T S***********************’)
disp(‘**********************************************************’)
disp(‘ The first 11 coefficients of the step response’)
disp(‘using the simulation of the difference equation are :’)
a
disp(‘using the command dstep are :’)
b
disp(‘ The first 11 coefficients of the impulse response’)
disp(‘using the simulation of the difference equation are :’)
c
disp(‘using the command impz are :’)
d
disp(‘ The cumulative step error [a-b] is :’)
sum(error _ step)
disp(‘ The cumulative impulse error [c-d] is :’)
sum(error _ imp)
disp(‘**********************************************************’)

The script fi le step_imp is executed, and the results are as follows:
Free download pdf