Example H3.5

MATLAB code for example 3.5 from the book "Regeltechniek voor het HBO"

Determine sinusoidal response with the aid of a pz-map: a second order system

Copyright (c) 2021, Studieboeken Specialist Permission is granted to copy, modify and redistribute this file, provided that this header message is retained.
Table of Contents

Initialisation for MATLAB code

% clear all variables from Workspace and close all figures
clear variables;
close all;
% Define 's' variable
s=tf('s');
 
% Disable warnings on complex valued poles and zeros
warning off Control:ltiobject:TFComplex

Response proces to sine input:

First show results in s-domain. Calculate and show the poles of
% Define the transfer function of the system
H=(3*s)/(2*s^2+8*s+16);
X=5*(3)/(s^2+3^2);
Y=X*H;
zpk(Y)
ans = 22.5 s ------------------------ (s^2 + 4s + 8) (s^2 + 9) Continuous-time zero/pole/gain model.
figure(101);
pzmap(Y);
Define input parameters to show response to an sine input:
Tsim1=4; % Simulation time in seconds
x_omega1=3; % frequency in rad/s
x_amp1=5; % amplitude of the sine wave
 
figure(102);
t1 = 0:Tsim1/100:Tsim1;
x1 = x_amp1*sin(x_omega1*t1);
% Simulate the response of system H to the input x1
lsimplot(H,x1,t1);
grid on;
title('Response to a sine input 5*sin(3t)');

Response proces to input with high sine frequency compared to system

Define input parameters and notice that output starts a zero value and that the sine will eventually have zero as its average value. But also the amplitude has become lower.
Tsim2=0.5; % Simulation time in seconds
x_omega2=60; % frequency in rad/s
x_amp2=5; % amplitude of the sine wave
 
figure(103);
t2 = 0:Tsim2/100:Tsim2;
x2 = x_amp2*sin(x_omega2*t2);
% Simulate the response of system H to an input x2
lsimplot(H,x2,t2);
grid on;
title('Response to a sine input with high frequency');

Response proces to input with low sine frequency compared to system

Define input parameters and notice that also the amplitude has become lower.
Tsim3=100; % Simulation time in seconds
x_omega3=0.3; % frequency in rad/s
x_amp3=5; % amplitude of the sine wave
 
figure(104);
t3 = 0:Tsim3/100:Tsim3;
x3 = x_amp3*sin(x_omega3*t3);
% Simulate the response of system H to an input x3
lsimplot(H,x3,t3);
grid on;
title('Response to a sine input with low frequency');

Generate MATLAB figure(s) for usage in the book

Init create Enhanced Figures

Close all the earlier enhanced figures with a certain tag
EnhancedFig = findobj(0, 'Tag', 'EnhancedImage');
close(EnhancedFig);

Enhance the figures

figure1=figure(1001);
% Give it a tag
set(gcf, 'Tag','EnhancedImage');
% create the pzmap plot again but now with a figure handle
h=pzplot(X*H);
grid on;
% get the handle to the plot options
p=getoptions(h);
% Adjust Title
p.Title.String='PN beeld van \itY(s)';
p.XLim=[-3 1];
p.YLim=[-4 4];
% write the options to the figure
setoptions(h,p);
 
figure2=figure(1002);
% Give it a tag
set(gcf, 'Tag','EnhancedImage');
% create the timeresponse plot again but now with a figure handle
h=lsimplot(H,x1,t1);
grid on;
% get the handle to the plot options
p=getoptions(h);
% Adjust Title
p.Title.String='Sinusresponsie \ity(t)';
% Make input invisible. If this does not work
% create the figure again with this code in an m-
% script and toggle with a right mouse click in
% the figure the input signal
p.InputVisible={'off'};
p.XLim=[0 4];
p.YLim=[-3 3];
% write the options to the figure
setoptions(h,p);
 
figure3=figure(1003);
% Give it a tag
set(gcf, 'Tag','EnhancedImage');
% create the bodeplot with a figure handle
h=bodeplot(H);
grid on;
% get the handle to the plot options
p=getoptions(h);
% Adjust Title
p.Title.String='Bodediagram \itH(s)';
% write the options to the figure
setoptions(h,p);