Laplace Transform Example #2

MATLAB Code


%         ***** MATLAB Code Starts Here
%

%LAPLACE_02_MAT

%

% Example of using the "residue" function to compute the inverse

% Laplace Transform through Partial Fraction Expansion.

%

fig_size = [232 84 774 624];

w0 = sin(pi/3); % Frequency of oscillation

% for complex poles

%

olp = [-1;-1;-0.5+j*w0;-0.5-j*w0;-0.75]; % Poles of transfer function

den = real(poly(olp)); % Transfer function denominator

%

olz = [-0.1;-0.3;-2]; % Zeros of transfer function

num = 100*real(poly(olz)); % Transfer function numerator

%

t = [0:0.05:20]; % Time vector

%

yi = impulse(num,den,t); % Impulse Response

%

ys = step(num,den,t); % Step Response

%

[resi,poli,fdth] = residue(num,den); % Partial Fraction Expansion

% for impulse response

%

[ress,pols,fdth] = residue(num,[den 0]); % Partial Fraction Expansion

% for step response

%

% Components of Impulse Response

%

yi1 = real(resi(1) * exp(poli(1)*t));

yi2 = real(resi(2) * t .* exp(poli(2)*t));

yi34 = real(resi(3) * exp(poli(3)*t) + resi(4) * exp(poli(4)*t));

yi5 = real(resi(5) * exp(poli(5)*t));

%

%

% Components of Step Response

%

ys1 = real(ress(1) * exp(pols(1)*t));

ys2 = real(ress(2) * t .* exp(pols(2)*t));

ys34 = real(ress(3) * exp(pols(3)*t) + ress(4) * exp(pols(4)*t));

ys5 = real(ress(5) * exp(pols(5)*t));

ys6 = real(ress(6) * ones(1,length(t)));

%

% Plots of Impulse Response

%

figure(1),clf,plot(t,yi1,t,yi2,t,yi34,t,yi5),grid,xlabel('Time (s)'),...

ylabel('Amplitude'),title('Components of Impulse Response'),set(gcf,'Position',fig_size),...

text(0.75,-550,'1'),text(0.75,-125,'2'),text(1,140,'3'),text(0.75,500,'4'),text(7,-300,'1 = exp(-t) term'),...

text(7,-500,'2 = t*exp(-t) term'),text(7,-700,'3 = sum of 2 complex terms'),...

text(7,-900,'4 = exp(-0.75*t) term')

%

figure(2),clf,plot(t,yi,'b',t,yi1+yi2+yi34+yi5,'r:'),grid,xlabel('Time (s)'),...

ylabel('Amplitude'),title('System Impulse Response'),set(gcf,'Position',fig_size),...

text(4,25,'Solid Blue = Computed by "Impulse" function'),...

text(4,15,'Dashed Red = Sum of Individual Components')

%

% Plots of Step Response

%

figure(3),clf,plot(t,ys1,t,ys2,t,ys34,t,ys5,t,ys6),grid,...

xlabel('Time (s)'),ylabel('Amplitude'),...

title('Components of Step Response'),set(gcf,'Position',fig_size),...

text(0.75,575,'1'),text(0.75,125,'2'),text(0.75,-125,'3'),text(0.75,-600,'4'),text(7.5,50,'5'),...

text(7,1350,'1 = exp(-t) term'),text(7,1150,'2 = t*exp(-t) term'),...

text(7,950,'3 = sum of 2 complex terms'),text(7,750,'4 = exp(-0.75*t) term'),...

text(7,550,'5 = constant term')

%

figure(4),clf,plot(t,ys,'b',t,ys1+ys2+ys34+ys5+ys6,'r:'),grid,...

xlabel('Time (s)'),ylabel('Amplitude'),title('System Step Response'),set(gcf,'Position',fig_size),...

text(7,45,'Solid Blue = Computed by "Step" function'),...

text(7,35,'Dashed Red = Sum of Individual Components')

%

w = logspace(-3,2,501); % Frequency vector

%

% Frequency response of the transfer function equals the frequency

% content of the system output when the system input is the unit

% impulse function.

%

[magi,phi] = bode(num,den,w);

%

% Frequency response of the transfer function multiplied by 1/s equals

% the frequency content of the system output when the system input is the

% unit step function.

%

[mags,phs] = bode(num,[den 0],w);

%

figure(5),clf,semilogx(w,20*log10(magi),w,phi),grid,...

xlabel('Frequency (r/s)'),ylabel('Magnitude (db) & Phase (deg)'),set(gcf,'Position',fig_size),...

title('Magnitude and Phase of Impulse Response'),...

text(1.3,40,'Magnitude'),text(1.3,-70,'Phase')

%

figure(6),clf,semilogx(w,20*log10(mags),w,phs),grid,...

xlabel('Frequency (r/s)'),ylabel('Magnitude (db) & Phase (deg)'),set(gcf,'Position',fig_size),...

title('Magnitude and Phase of Step Response'),...

text(1.3,40,'Magnitude'),text(1.3,-160,'Phase')

%

%
%         ***** MATLAB Code Stops Here

Click the icon to return to the Dr. Beale's home page

Lastest revision on Thursday, May 18, 2006 11:08 PM