%
% Filename: example10.m
%
% Description: M-file demonstrating various matlab functions
% for system analysis. Functions use system transfer
% function H(s) as input.
%
clear; % clear matlab memory
numH = [2 5 7]; % numerator of H(s)
denH = [3 1 4 9]; % denominator of H(s)
disp(' '); disp('H(s) = '); % print H(s) to window
printsys(numH,denH,'s');
% Plot system poles and zeros
figure(1); clf; % put plots in figure 1
pzmap(numH,denH);
% Compute and Plot step/impulse responses
figure(2); clf; % put plots in figure 2
t = 0:0.01:10;
y = step(numH,denH,t); % compute & plot system step response
subplot(2,1,1);
plot(t,y);
xlabel('time ');
ylabel('y(t)');
title('System Step Response');
y = impulse(numH,denH,t); % compute & plot impulse response
subplot(2,1,2);
plot(t,y);
xlabel('time ');
ylabel('y(t)');
title('System Impulse Response');
% Compute and Plot Spectra of H(w) using freqs
figure(3); clf; % put plots in figure 3
w = -20:0.05:20;
H = freqs(numH,denH,w); % compute and plot H(w) spectra
subplot(2,2,1);
plot(w,abs(H));
xlabel('w ');
ylabel('|H(w)|');
title('Magnitude Spectrum of Impulse Response');
subplot(2,2,2);
plot(w,angle(H)*180/pi);
xlabel('w ');
ylabel('Phase(H(w)) ');
title('Phase Spectrum of Impulse Response');
% Compute and Plot Spectra of H(w) in log form using freqs
w = logspace(-1,1,100); % w has 100 values from 10^(-1) to 10^1
% with same # of points in each decade
H = freqs(numH,denH,w); % compute and plot H(w) spectra
subplot(2,2,3);
semilogx(w,20*log(abs(H)));
xlabel('w ');
ylabel('|H(w)| ');
title('Magnitude Spectrum of Impulse Response');
subplot(2,2,4);
semilogx(w,angle(H)*180/pi);
xlabel('w ');
ylabel('Phase(H(w)) ');
title('Phase Spectrum of Impulse Response');
% Compute and Plot Spectra of H(w) using bode
figure(4); clf; % put plots in figure 4
w = -20:0.01:20;
[mag,phase] = bode(numH,denH,w); % compute and plot H(w) spectra
subplot(2,2,1);
plot(w,mag);
xlabel('w ');
ylabel('|H(w)|');
title('Magnitude Spectrum of Impulse Response');
subplot(2,2,2);
plot(w,phase);
xlabel('w ');
ylabel('Phase(H(w)) ');
title('Phase Spectrum of Impulse Response');
% Compute and Plot Spectra of H(w) in log form using bode
w = logspace(-1,1,100); % w has 100 values from 10^(-1) to 10^1
% with same # of points in each decade
[magH, phaseH] = bode(numH,denH,w); % compute and plot H(w) spectra
subplot(2,2,3);
semilogx(w,20*log(magH));
xlabel('w ');
ylabel('|H(w)| ');
title('Magnitude Spectrum of Impulse Response');
subplot(2,2,4);
semilogx(w,phaseH);
xlabel('w ');
ylabel('Phase(H(w)) ');
title('Phase Spectrum of Impulse Response');
Matlab Response Generated:
H(s) =
num/den =
2 s^2 + 5 s + 7
----------------------
3 s^3 + s^2 + 4 s + 9
MATLAB Plots Generated: