Modeling and Simulation
Modeling and Simulation
Simulation
Prof Sam’s Portion
Mohamed Isa Bin Mohamed Nasser
U076183A
1
1 Introduction
This experiment will cover the whole process of control system design and simulation. This
whole process is described in the flow chart below. In beginning stages, we are familiarized
with Labview in order to do extract data in a meaningful manner from the system.
This data is then treated to remove noise. With the collected data, non-parametric as well as
parametric methods are used to identify the system which is used in the many methods to
control the system.
2 The DC Motor
The DC motor is equipped with two sensors, a potentiometer to measure the angular position and a
tachogenerator to measure the angular velocity. The sensors are shown in Figure 1.
2
4 Data Acquisition and Conditioning
In this section, the developments of the required Labview program to acquire data as well as
methods to condition them are explored.
The data that has been acquired looks like the following:
3
20
Velocity 0.2Hz 3V Square Wave
15 input
10
-5
-10
-15
-20
0 1 2 3 4 5 6 7 8 9 10
The data is actually very clean with little noise. Most of the noise is high frequency and at the
peaks. Firstly the butterworth filtered is used to attenuate the high frequencies. The
parameters used for the function is shown in the MATLAB code.
4
original
15 filtered
10
-5
-10
-15
100 200 300 400 500 600 700 800 900 1000
When the high frequencies are filtered away, many of the harmonic components to maintain
the shape of the square wave is removed. This causes it to slant. A frequency domain filter is
therefore not ideal for removing this noise. The next step is to try down-sampling the signal to
reduce the effect of the high frequency noise.
5
20
4X resampled output Signal
15 Input Signal
10
-5
-10
-15
-20
0 1 2 3 4 5 6 7 8 9 10
time(s)
The high frequency noise has now been visually reduced. In order to smoothen it further a
spline smooth has been used. The details of this method are covered in the next section. The
result is shown.
6
20
Spline Smoothed output Signal
15 Input Signal
10
-5
-10
-15
-20
0 1 2 3 4 5 6 7 8 9 10
time(s)
Although the noise is reduced further, it introduces notch on the transitions at the edges. This is
not a desirable property since these notches do not appear in the actual system. Although the
spline smoothing works well in smoother waveforms, it is not good for signals with large drops
and very sharp edges such as the square wave. We therefore will use the previous conditioning
result for modeling.
In this exercise, a set of noisy input-output data has to be conditioned. The data contains time,
input and output information. The unfiltered data looks like the following:
7
1.4
Originial Noisy Signal
1.2 Input Signal
0.8
0.6
0.4
0.2
-0.2
-0.4
0 5 10 15 20 25 30 35 40
time(s)
It is stated that the output has been contaminated with high frequency noise with zero mean.
After much experimentation with the processes to clean the signal, a very effective method has
been realized.
The signal is first downsampled in order to reduce the number of points. This will reduce the
resolution and the high frequency components will be reduced significantly. The output of this
part is shown in the following figure.
8
1.4
40X resampled output Signal
1.2 Input Signal
0.8
0.6
0.4
0.2
-0.2
-0.4
0 5 10 15 20 25 30 35 40
time(s)
For this particular signal, it has been downsampled by 40 times. However it is found to be only
effective for the current problem. A more general downsampling amount is 10 times. As
observed in the above figure, the high frequency oscillations have been removed. This is a good
improvement. The next step required should be to smooth out the jagged points which are a
result of sampling sharp oscillations.
In order to this, a spline smoothing technique written by Damien Garcia is used. Splines are
multiple segments of piecewise curve fits, often by a polynomial regression, that is used to fit
data that are otherwise difficult to fit and often non-linear. It can be used to smooth signals by
fitting a series of smooth curves to the signal.
Knots are the points between two piecewise curves. The choice of knots as well as the order of
polynomial regression can therefore be used to smooth the curve. This type of smoothing is
ideal for of data since it has zero mean and the center of the amplitude of the sharp oscillations
9
is the desired signal. A least square curve fit will achieve this. The result of the spline smoothing
is shown in the following figure.
1.4
Spline Smoothed output Signal
1.2 Input Signal
0.8
0.6
0.4
0.2
-0.2
0 5 10 15 20 25 30 35 40
time(s)
The result is very good. By visual inspection with the noisy signal, we can see that this signal is
almost identical with the original clean signal.
The MATLAB code to achieve the above smoothing has been created into a function for easy
use in later exercises.
10
hold on;
plot(X(:,1),X(:,3));
hold off;
legend('Originial Noisy Signal', 'Input Signal');
Xlabel('time(s)');
end
%==========================
% DC offset
%==========================
startidx = 1;
endidx = length(X(:,1));
X_DC = X;
for i = 1:endidx
X_DC(i - startidx + 1,3)=X(i,3) - DCoff;
end
%==========================
% Resample
%==========================
j = 1;
m=10;
for i = startidx:endidx
if(rem(i,m) == 0)
X_filtered(j,1) = X_DC(i,1);
X_filtered(j,2) = X_DC(i,2);
X_filtered(j,3) = X_DC(i,3);
j = j+1;
end
end
if(showplot == 1)
figure(2);
plot(X_filtered(:,1),X_filtered(:,3));
hold on
plot(X(:,1),X(:,2),'-r');
hold off
legend('10X resampled output Signal', 'Input Signal');
11
Xlabel('time(s)');
end
%==========================
% Spline smooth
%==========================
% the
Z = SMOOTHN(X_filtered(:,3),smoothness);
if(showplot == 1)
figure(3);
plot(X_filtered(:,1),Z);
hold on
plot(X(:,1),X(:,2),'-r');
hold off
legend('Spline Smoothed output Signal', 'Input Signal');
Xlabel('time(s)');
end
[X_filtered(:,1);X_filtered(:,2);Z]
out = [X_filtered(:,1)';X_filtered(:,2)';Z'];
In this section, a Labview program has to be made to perform step response as well as impulse
response analysis. The format of the data must be in the following form:
A square wave generator has been used to produce the impulse as well as the step response. Of
course an ideal impulse is not realizable since it has a peak at infinity. A simulation of this can
be achieved by the signal:
12
This guarantees that the area of the impulse response still has an area of 1 that is,
Therefore a sharp square wave will be used as an approximation for the impulse response for
small pulse widths. These calculations are made at this portion of the block diagram.
13
The full block diagram is shown below.
A convenient switch is used to switch between a step responses to an impulse response. When
a user stops the program, the plots will be saved into text files.
The user can set the sampling rate, magnitude and pulse width for the step response. Except
for the pulse width, every other parameter can be directly set to the square-wave box. The only
way to set the pulse width is by adjusting the duty cycle of the square wave. Therefore the
pulse width is set using,
Constants
Frequency = 0.2 Hz
14
Period = 10s
Input
Duty cycle = X / 10
For the impulse response, the user can only set sampling rate and magnitude in order to satisfy
the requirements. The relation used again to set the pulse width from the magnitude is,
The following figure shows the front panel in impulse response operation. The amplitude
chosen is 5. This will mean the pulse width is 0.2 seconds. This generates a thin pulse. This is the
best pulse attainable by the system with the available headroom.
15
The next figure shows the impulse response but this time with amplitude of 1. The pulse width
is therefore 1 second. This is significantly thicker than the wave form above.
The step response is simply a square wave with a big enough period for the whole step
response to occur; the pulse width must be set bigger than the settling time. The snapshot of
the schematic used to achieve the requirement is shown below. The pulse width and amplitude
is adjustable.
16
5 Non-Parametric Approach for system Identification
This section covers impulse response and step response method of non-parametric approach
for system identification in MATLAB .
The code used to obtain the impulse response has been obtained by the using the code below.
MATLAB Code
17
disp(' Impulse Response Coefficients:')
X = impulse(G1, [0:1:15])
figure(1);
impulse(G1, [0:1:15])
1.0000
-0.5000
0.2500
-0.1250
0.0625
-0.0313
0.0156
-0.0078
0.0039
-0.0020
0.0010
-0.0005
0.0002
-0.0001
0.0001
-0.0000
18
Impulse Response
1
0.5
Amplitude
System: G1
Time (sec): 10
Amplitude: 0.000977
0
-0.5
0 5 10 15
Time (sec)
From the above plot, we can see that it is oscillating and settles at t = 10 seconds.
In order to find the step response, the method step() is invoked. The command stepinfo() can
be used to find the step response characteristics. This method is then compared against using
numerical methods of obtaining the settling time as well as verifying it on the plot.
19
MATLAB Code
%================================
% Get Step response and Plot
%================================
disp('Step Response Analysis:')
G = tf([1],[1 1 2],'inputdelay', 0.3);
[Y T] = step(G,0:0.001:50);
step(G);
%==============================
% Find All 2nd Order Param
%==============================
S = stepinfo(G,'RiseTimeLimits',[0.05,0.95])
%====================================
% Verify by checking Settling time
%====================================
settling_percent = 0.02; % Find the time when all values of response
% are within 2% of final output
The console output shows all the characteristics of the response. These quantities need to be
subtracted by the delay time of 0.3 in order to be used to model the system using the 2nd order
system estimation for rise time and overshoot.
Console Output
20
S=
RiseTime: 1.1778
SettlingTime: 8.0411
SettlingMin: 0.4535
SettlingMax: 0.6515
Overshoot: 30.3097
Undershoot: 0
Peak: 0.6515
PeakTime: 2.7551
Settling_time_check =
8.0430
This is the step response with the overshoot and 90% and 10% magnitude points marked.
21
Step Response
X: 2.755
0.7
Y: 0.6446
0.6
System: G
Time (sec): 1.63
0.5
Amplitude: 0.45
0.4
Amplitude
0.3
0.2
0.1
System: G
0
0 Time (sec):
2 0.637 4 6 8 10 12
Amplitude: 0.0502
Time (sec)
To illustrate the previous point about having to subtract the delay time from the rise time, two
plots are made. The first one without subtraction and the next, with subtraction.
22
Step Response
0.7
original
estimate
0.6
0.5
0.4
Amplitude
0.3
0.2
0.1
0
0 2 4 6 8 10 12 14 16
Time (sec)
The estimate above fit is bad since the delay is not taken into consideration.
23
Step Response
0.7
original
estimate
0.6
0.5
0.4
Amplitude
0.3
0.2
0.1
0
0 2 4 6 8 10 12
Time (sec)
In contrast the above estimate is very good. The formulas used for the estimates of the
damping ratio and natural frequency will be covered in the following section.
There are two sets of data provided which comes from the same signal. The data is in the usual
form of:
The data in set1 contains the step response of the system. However, the data is noisy and the
step response does not occur neatly at t = 0. The first task is to use the function
24
conditionplot(<data>,<show plot>,<offset>,<smoothness>) created in the preceding part to
smooth the signal. The results are as follows.
1.4
Originial Noisy Signal
1.2 Input Signal
0.8
0.6
0.4
0.2
-0.2
-0.4
0 5 10 15 20 25 30 35 40 45 50
time(s)
This is the original signal. Notice it has high frequency noise. The shape of the signal can be seen
visually.
25
1.4
10X resampled output Signal
1.2 Input Signal
0.8
0.6
0.4
0.2
-0.2
-0.4
0 5 10 15 20 25 30 35 40 45 50
time(s)
It is the downsampled by 10 times and a smoother plot is observed. The high frequency
oscillations are no longer present.
26
1.4
Spline Smoothed output Signal
1.2 Input Signal
0.8
0.6
0.4
0.2
-0.2
-0.4
0 5 10 15 20 25 30 35 40 45 50
time(s)
The final filtered signal is shown. Notice that the signal has an initial condition. This is not a
delay because it starts at a negative value on the positive edge. To find the overshoot, rise time
and other parameters from the discrete data, a simple program can be made that finds
magnitude of individual samples and compare it with the DC gain. The sample corresponding to
the 10% and 90% point can be deduced from this code snippet.
MATLAB code
27
end
The overshoot can be found by sample with the maximum magnitude. This is then divided by
the static gain and multiplied by 100% to get the percentage. This is done in the following code
snippet.
MATLAB code
% calculate OS and tp
[Ypeak,Ipeak] = max(abs(Y)); % find max response value and index
tp = T(Ipeak); % tp is time at max response
index(4) = Ipeak; % tp index
if (Ypeak >= StepSize), % if max response is greater than StepSize then
calculate OS
OS = 100*(Ypeak/StepSize)-100;
else % if max response is less than StepSize then OS = 0%
OS = 0;
End
The above code is written by Clinthon Cathey in the form of a function StepResponse(). Using
this function, the following values are obtained.
Mp: 16.1595%
From these values, a second order model of the system can be constructed using the following
estimations given in Benjamin C. Kuo, Automatic Control Systems, 7th ed., Prentice Hall, 1995.
Mp = exp(-pi*zeta/sqrt(1-zeta^2))
tr = (1-0.4167*zeta+2.917*zeta^2)/wn for zeta<1
ts = 3.2/(zeta*wn) for zeta<0.69; and t_s = 4.5*zeta/wn for zeta>0.69
28
This can then be rearranged to give:
Using the values obtained for Wn and ζ, we can now find the transfer function.
MATLAB Code
Cdata1=conditionplot(data1,0,0,1);
Cdata2=conditionplot(data2,0,0,1);
%================================
% Find Set 1 Step Response
%================================
[OS,ts,tr,tp,T,U,Y,index] =
StepResponse(Cdata1(1,:),Cdata1(2,:),Cdata1(3,:),10^-1);
% display results
index(1) = [];
29
disp(strcat('Mp :',num2str(OS)))
disp(strcat('Tr :',num2str(tr)))
disp(strcat('Tp :',num2str(tp)))
%================================
% Create 2nd Order TF Model
%================================
%================================
% Plot and Compare
%================================
figure(1);
plot(T,U,'color','red');
hold on;
plot(T,Y,'color','blue');
grid
xlabel('Truncated Time')
ylabel('Truncated Command and Response')
[resp T] = step(sys,0:0.01:max(T));
plot(T+.55,resp,'-r','color','green');
hold off;
%====================================
% Print out Transfer Function
%====================================
disp('S-Domain Transfer Function')
sys
disp('Z-Domain Transfer Function at Sampleing Frequency of 1 Hz')
[num den] = tfdata(sys)
bilinear(num,den,1)
30
Console Output:
Transfer function:
1.034
---------------------
Transfer function:
------------------------------
Sampling time: 1
The code also plots the corresponding respond of the original step response to the estimated
step response. The results are good.
31
1.2
0.8
Truncated Command and Response
0.6
0.4
0.2
0
X: 0.55
Y: 0
-0.2
0 5 10 15 20 25 30 35
Truncated Time
1.2
Originial Noisy Signal
1 Input Signal
0.8
0.6
0.4
0.2
-0.2
-0.4
0 5 10 15 20 25 30 35 40 45 50
time(s)
32
1.2
10X resampled output Signal
Input Signal
1
0.8
0.6
0.4
0.2
-0.2
0 5 10 15 20 25 30 35 40 45 50
time(s)
1.2
Spline Smoothed output Signal
Input Signal
1
0.8
0.6
0.4
0.2
-0.2
0 5 10 15 20 25 30 35 40 45 50
time(s)
33
Since the impulse response is already given, the important step here is to extract the right
portion out. This can be done by using the binary type signal that is the output and checking
when it is one and when it is zero.
%================================
% Find Set 2 Impulse Response
%================================
%=========================================
% Select the Impulse Response Portion
%=========================================
detectlow = 0;
detecthighstart = 0;
detecthighend = 0;
Cdata2 = Cdata2';
for i = 1: length(Cdata2(:,2))
if(Cdata2(i,2)<0.5)
detectlow=1;
end
if(Cdata2(i,2)>0.5 && detectlow==1 && detecthighstart==0)
detecthighstart = i;
break;
end
%{
if(set2(i,2)<0.5 && detecthighstart>0)
detecthighstart = i;
break;
end
%}
end
%=================================================
% Select the convert from Z-domain to S-domain
%=================================================
set2impulse = Cdata2(detecthighstart:detecthighstart+30,:);
figure(2);
plot(set2impulse(:,1),set2impulse(:,2), set2impulse(:,1),set2impulse(:,3));
fs = 1/(set2impulse(5,1)-set2impulse(4,1));
[num den] = ibilinear(set2impulse(:,2)',set2impulse(:,3)',fs);
figure(3);
impulse(tf(num,den));
The extracted plot is show.
34
1.2
0.8
0.6
0.4
0.2
-0.2
10 15 20 25 30 35 40 45 50
This is now coefficients for the impulse response in the time-domain. In order to obtain s-
domain value, an inverse form for the bilinear algorithm can be used.
%================================
% Find Set 2 Impulse Response
%================================
%=================================================
% Convert from Z-domain to S-domain
%=================================================
set2impulse = Cdata2(detecthighstart:detecthighstart+30,:);
figure(2);
plot(set2impulse(:,1),set2impulse(:,2), set2impulse(:,1),set2impulse(:,3));
fs = 1/(set2impulse(5,1)-set2impulse(4,1));
[num den] = ibilinear(set2impulse(:,2)',set2impulse(:,3)',fs);
figure(3);
impulse(tf(num,den));
35
Console Output
Transfer function:
-8.527e-014 s^30 + 632 s^29 + 5.814e004 s^28 + 2.629e006 s^27 + 7.814e007 s^26
+ 1.047e021 s + 1.822e020
---------------------------------------------------------------------------------
s^30 + 124.1 s^29 + 7581 s^28 + 2.941e005 s^27 + 8.405e006 s^26 + 1.824e008 s^25
+ 1.936e020
The dominant poles can be extracted to reduce the order of the transfer function.
Extracting the transfer function from the impulse response in the time domain is harder than
achieving the same from the step response. This is firstly due to the fact that impulse is not
perfect while the step response is made very much near perfect. The amplitude of the pulse for
the impulse is 1V which is rather low for an approximation of the ideal impulse.
36
Also, the impulse response errors are directly translated on the poles and zeros of the transfer
function. Conditioning and smoothening is therefore crucial. However without knowing the
exact interference and noise, there is ambiguity if the conditioning method maintains the
fidelity of the signal and hence the accuracy of the transfer function.
It is important to say that the impulse response method is able to extract a system with higher
order than this particular method of step response analysis since the fitting for step response
uses a second order transfer function model.
5.3
In this part,
The given set points are set into the following block diagram.
The outputs are recorded accordingly. The second block diagram is used with the step is set to
start at 50 seconds. The corresponding step response is saved in MATLAB’s workspace for more
accurate reading and the transfer function deduced.
u0 = 3, y0 = 0.684
37
Time constant = τ = 50.03 – 49.34 = 0.68 seconds
0.653
1 + 0.68s
u0 = 18, y0 = 6
38
output
12.25 input
X: 52.4
Y: 12.2
12.2
12.15
12.1 X: 50.11
Y: 12.07
12.05
X: 50
Y: 12
12
11.95
11.9
11.85
50 50.5 51 51.5 52 52.5
39
0.2
1 + 0.11s
From this, we can see that every operating point on a non-linear system can be approximated as a linear
system for a neighbourhood of points around a fixed point of operation. This is stated by the Hartman-
Grobman theorem.
5.4
14
12
10
0
0 20 40 60 80 100 120 140 160 180 200
40
X: 0.99
Y: 11.8
12
10
Truncated Command and Response
6
X: 0.1128
Y: 4.423
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Truncated Time
This is a first order transfer function with gain of 11.8 and the time constant is 4.423 seconds.
The latency is negligible and cannot be detected from this graph.
11.8
1 + 4.43s
The impulse response will not be used due to the difficulty in obtaining a realistic impulse
response as seen from the previous example on non-parametric identification.
The set point is 2V so that the neighbourhood of points around it is applicable for the model.
This region, we anticipate, will be the range where the motor will operate in.
The sampling period is set to 0.02. This is for the integrator to have more samples per second
resulting in a better PID control output. Also, from the previous models used, the smoothing
41
method has removed half of the samples in down sampling which reduces the sample by half.
This is of course relevant mostly in the parametric methods for model fitting.
50
input
40 output
30
20
10
-10
-20
-30
-40
-50
0 2 4 6 8 10 12 14 16 18 20
time(s)
The data is contaminated with high frequency noise. The conditionplot() method created will be
used. The resulting signal is shown.
42
50
Spline Smoothed output Signal
40 Input Signal
30
20
10
-10
-20
-30
-40
-50
0 2 4 6 8 10 12 14 16 18 20
time(s)
Since only one frequency wave is used as input, we a can extract the system’s phase at the
frequency as well as the gain at the frequency.
43
10
X: 8.35
5 Y: 3.509
0
X: 7.46 X: 9.61
Y: 0.0079 Y: 0.0591
-5
Spline Smoothed output Signal
Input Signal
-10
10
X: 9.32
Y: 5.23
X: 8.36
5 Y: 3.5
X: 8
Y: 1
-5
Spline Smoothed output Signal
Input Signal
-10
44
Gain = (5.23-3.5)/ 1 = 1.73
18
output
16 input
X: 8.7
Y: 16.12
14
12
10
6
X: 8.5
4 Y: 2.998
2 X: 5.7
Y: 0.514
0
0 5 10 15 20 25
f = 0.1 Hz
45
14
X: 10.38 output
Y: 13.75 input
12
10
X: 9.9
4 Y: 3.035
2
X: 9.74
Y: 0.002
0
0 5 10 15 20 25
f = 0.2 Hz
46
14 X: 6.28
Y: 12.43 output
input
12
10
6 X: 5.94
Y: 4.513
2
X: 5.82
Y: 0.001
0
0 2 4 6 8 10 12 14
f = 0.3 Hz
47
12
output
X: 8.22
Y: 11.5
input
10
X: 7.98
6 Y: 5.396
2
X: 7.86
Y: 0.001
0
0 2 4 6 8 10 12 14 16 18 20
f = 0.4 Hz
48
15
output
input
X: 4.16
Y: 10.97
10
X: 4.38
Y: 5.926
X: 4.28
Y: 0.001
0
0 1 2 3 4 5 6 7 8 9
f = 0.5 Hz
49
14
output
input
12
X: 2.82
Y: 10.39
10
X: 2.74
4
Y: 2.983
0
0 5 10 15 20 25
f = 0.6 Hz
50
12
X: 3.84 output
Y: 10.34
input
10
4 X: 3.76
Y: 2.978
0
0 5 10 15 20 25
f = 0.7 Hz
51
12
output
input
10
X: 3.86
Y: 10.09
4 X: 3.8
Y: 2.986
0
0 2 4 6 8 10 12
f = 0.8 Hz
52
X: 1.44
Y: 9.892
10 output
X: 6.76
Y: 10.01
input
9
4 X: 1.14 X: 6.7
Y: 2.955 Y: 2.989
3
0 2 4 6 8 10 12 14 16 18
f = 0.9 Hz
53
Magnitude plot of System
16
15
14
13
12
Gain
11
10
7
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
freq (Hz)
54
-0.05
-0.1
-0.15
phase (rad)
-0.2
-0.25
-0.3
-0.35
-0.4
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
freq (Hz)
This method is very slow even if the comparing of the sampled sine waves are automated.
Placing the poles at s=5, s=5, s=10, the following gains has been calculated from the C.E.
Kd = 13 , Kp = 74 ,Ki = 125
55
The resulting step response is as follows:
56
The static state gain is 0dB and the over shoot is 14.9%. The system is stable and underdamped.
8.1.2 Using Particle Swarm optimization to obtain Optimal Location using PID block
57
While the previous method of controlling the motor using certain fixed dominant pole position
is successful, it is not optimal. In order to find optimal control gains, the output wave can be
subtracted from the input. This will give a good indicator of how well the controller gains
perform. This cost function is then minimized by setting different vales of controller gains. Since
the function is non-linear, the optimization algorithm chosen is a heuristic method for multi
objective optimization
The Particle Swarm Optimization (PSO) toolbox is used to find the global minima for the
controller parameters. The output and input are not calculated in MATLAB but in Simulink itself.
Code has been written in MATLAB to send and receive data to and from Simulink.
This is slightly different than the previous example in terms of the block diagram since it now
uses a simulation of a real PID controller in simulink.
The resulting best controller gains are KI = 10.1418 , KP =23.6699 , KD =5.1514 and its plot is
shown.
1.4
Ki = 10.1418Kp = 23.6699Kd = 5.1514
input Signal
1.2
0.8
0.6
0.4
0.2
0
0 5 10 15 20 25 30
58
8.2 Control Design and simulation
Kd = 13 , Kp = 74 ,Ki = 125
Next the same gains are used on a digital plant. The block diagram used in Simulink is shown
below.
The resulting plot is very near the one in continuous plant. The output is shown below.
This method of design has worked at least in the case of the simulation.
59
Another method to design D(z) is to convert a continuous time plant G(s) into discrete time.
Given that
z
G( z) = 2
z − 16 z + 0.64
z z −1
D( z ) = k p + k D ( ) + kI
z −1 z
G ( z ) D( z )
H ( z) =
1 + G ( z ) D( z )
1 + G( z) D( z) = 0
z 2 + (k p + k I + k D − 2.6) z 2 + (2.24 − k P − k D ) z + (k D − 0.64) = 0
( z + 0.2) 2 ( z + 1) = 0
z 2 + 1.4 z 2 + 0.44 z + 0.04 = 0
k p + k I + k D − 2.6 = 1.4
2.24 − k p − 2k D = 0.44
k D − 0.64 = 0.04
k D = 0.68
With T = 1, using the same model as 8.1 the following diagram shows a block in Simulink.
60
The system is stable but with large overshoot. Also the steady state gain is 0.5.
Just as the previous example of using the PSO example, this diagram is also optimized. And
similarly it uses the discrete PID controller instead of a transfer function. Therefore the
dynamics is different.
61
1.4
Ki = 0.78973 Kp = 1.0503 Kd = 0.67555
Input signal
1.2
0.8
0.6
0.4
0.2
0
0 5 10 15 20 25 30
The following screenshot shows the PSO toolbox searching for the global minima.
62
The next two screen shot shows the output signal followed by the input signal from the scope
in Labview.
63
Using model obtained from the step response, we PSO to optimize the controller gains. The
following set of gains are obtained.
64
1.4
Ki = 2.715Kp = 29.9812Kd = 8.6986e-006
input Signal
1.2
0.8
0.6
0.4
0.2
0
0 5 10 15 20 25 30
However using these controller gains for the system, specifically the Ki value does not work well.
The tuning for Ki has to be reduced in order to obtain the following response.
65
This is much faster than the open loop response.
Just as the way the PSO algorithm was used to find a global minima in question 8.3.2 we
wanted to implement such an algorithm but instead of computing offline, we wanted to
implement it online.
The problem that is encountered, however, is that Labview is not able to support MATLAB
codes fully. The Mathscript block is able to run MATLAB scripts however the variables are
unable to retain information and also external functions cannot be called. The Labview version
in the lab does not have any support for any language that has any degree of object orientated
support.
All heuristic optimization algorithms that we are aware of require support for external function
calling and of course retaining of variable. The retaining of variable can be solved by shift
registers but the function calling problem is not solvable. We are left with a large compromise
of using random walk to find not the optimal, but the best possible within the search iteration.
66
The block diagram used for this section is shown in the next page. Many shift registers are used
to retain certain variables and arrays between loops.
Position and velocity control are controlled separately using single feedback. Therefore the
block diagram has to be rewired for the feedback between the two control schemes.
67
68
The best result of that the control system is able to find for position control is for Kp=2.02347 KI
= 0.00400 and KD = 0.00017.
It has to be said that although this process can find the global minima in many iterations, the
results here are obtained through guided finding of the range for the random numbers. The
random walk search is just a mediocre way to obtain a global maxima. The result is not very bad
with some overshoot. This will be improved in the next scheme using state-feedback control.
69
The solution found for velocity control however is very good. The wave form is much faster
than the open loop performance shown in the step response of the system. The next section
will improve position control of the system. This time non-parametric parameters obtained for
the motor has been used and converted in to state-space equations.
While the last example did not use the model made for the system this next method does.
Another method to control the motor is by using the state space description of the system and
implementing a state feedback. We have modeled the motor as a first order transfer function
using step analysis earlier. State space description of the system can be constructed as such:
The Ackermann formula can be used to set poles for the system if both state-feedback is
available which is the case. This formula is supported by MATLAB as acker(A,B,Pole).
70
The poles used are obtained using the Bessel prototype table. The system is a third order
system with the integral action. Therefore the corresponding pole from the prototype table is
at
The remaining parameter to optimize is Wn. This is done automatically using an adaptive
control that exhaustively searches for the best response.
The cost function to define this best response is the input signal itself. The output signal is
accumulated and within intervals subtracted from the accumulated input signal. The value of
Wn is then changed and this process is repeated. The minimum Wn will be selected after a
certain number of searches. This control scheme can be illustrated by the following block
diagram.
The controller block for our scheme uses the Bessel prototype poles to place the poles at certain
prototype positions.
The Labview block diagram used to achieve this control is shown and has been created by us.
Again many shift registers are used to pass variable between loops.
71
72
The results of the controller for controlling the motor with 1V square waves are shown below.
The motor is controlling position.
Here a bad parameter is used during the exhaustive search. It consequently has a high cost
function value.
73
At the end of the search, the best match is selected. The results are very good, the control does
not have any overshoot is relatively fast.
We have now been able to control both the velocity and the position of the motor with good
performance.
Conclusion
This part of the experiment explores data conditioning method, data acquisition using Labview
and different non-parametric models of the system. It also emphasizes the importance of the
linearization theorem in designing a control scheme.
At the end of the exercise, a practical implementation of all that has been learnt is done. We
have introduced many less conventional methods such as spline fitting for conditioning, PSO
algorithm for optimization of control paramters, online searching for optimal parameters as
well as state feedback control that achieved very good results.
74