modeling and simulation

74
1 EE4307 Control System Design and Simulation Prof Sam’s Portion Mohamed Isa Bin Mohamed Nasser U076183A

Upload: digiblood

Post on 18-Nov-2014

877 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Modeling and Simulation

1

EE4307 Control System Design and

Simulation

Prof Sam’s Portion

Mohamed Isa Bin Mohamed Nasser

U076183A

Page 2: Modeling and Simulation

2

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.

Page 3: Modeling and Simulation

3

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.

4.2 Conditioning Data Acquired from Plant

The data that has been acquired looks like the following:

Page 4: Modeling and Simulation

4

0 1 2 3 4 5 6 7 8 9 10-20

-15

-10

-5

0

5

10

15

20

Velocity 0.2Hz 3V Square Wave

input

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.

Wn = 1.9999995; %fraction of Nyquist

W = idfilt(z(:,1), 100, Wn, 'noncausal','low');

t = 1:printsize;

plot(t,z(:,1),t,W), legend('original','filtered'), axis tight

Page 5: Modeling and Simulation

5

100 200 300 400 500 600 700 800 900 1000

-15

-10

-5

0

5

10

15

original

filtered

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.

Page 6: Modeling and Simulation

6

0 1 2 3 4 5 6 7 8 9 10-20

-15

-10

-5

0

5

10

15

20

time(s)

4X resampled output Signal

Input Signal

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.

Page 7: Modeling and Simulation

7

0 1 2 3 4 5 6 7 8 9 10-20

-15

-10

-5

0

5

10

15

20

time(s)

Spline Smoothed output Signal

Input Signal

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.

4.3 Data Conditioning

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:

Page 8: Modeling and Simulation

8

0 5 10 15 20 25 30 35 40-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

1.2

1.4

time(s)

Originial Noisy Signal

Input Signal

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.

Page 9: Modeling and Simulation

9

0 5 10 15 20 25 30 35 40-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

1.2

1.4

time(s)

40X resampled output Signal

Input Signal

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

Page 10: Modeling and Simulation

10

is the desired signal. A least square curve fit will achieve this. The result of the spline smoothing

is shown in the following figure.

0 5 10 15 20 25 30 35 40-0.2

0

0.2

0.4

0.6

0.8

1

1.2

1.4

time(s)

Spline Smoothed output Signal

Input Signal

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.

function [out] = conditionplot(data, showplot, DCoff, smoothness)

X = data;

if(showplot == 1)

figure(1);

plot(X(:,1),X(:,2),'-r');

Page 11: Modeling and Simulation

11

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');

Page 12: Modeling and Simulation

12

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'];

4.4 Design of Labview Program

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:

Time Input Output

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:

Page 13: Modeling and Simulation

13

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.

Page 14: Modeling and Simulation

14

The full block diagram is shown below.

The controls on the front panel are shown.

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

Page 15: Modeling and Simulation

15

Period = 10s

Input

Pulse Width = X seconds

Calculated and Set the Square Wave Box

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,

Pulse width = 1 / Magnitude

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.

Page 16: Modeling and Simulation

16

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.

Page 17: Modeling and Simulation

17

5 Non-Parametric Approach for system Identification

This part will explore non-parametric approach for system identification.

5.1 Time domain Method

This section covers impulse response and step response method of non-parametric approach

for system identification in MATLAB .

5.1.1 Impulse Response

The given system is,

The code used to obtain the impulse response has been obtained by the using the code below.

MATLAB Code

G1 = tf([1 0],[1 0.5], 1); % the tf

Page 18: Modeling and Simulation

18

disp(' Impulse Response Coefficients:')

X = impulse(G1, [0:1:15])

figure(1);

impulse(G1, [0:1:15])

The coefficients are shown in the console output:

Impulse Response Coefficients:

X =

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

The corresponding impulse response plot is shown below.

Page 19: Modeling and Simulation

19

0 5 10 15-0.5

0

0.5

1

System: G1

Time (sec): 10

Amplitude: 0.000977

Impulse Response

Time (sec)

Am

plit

ude

From the above plot, we can see that it is oscillating and settles at t = 10 seconds.

5.1.2 Step Response

The system is given as,

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.

Page 20: Modeling and Simulation

20

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

chan1 = Y(:,:,1); % Get channel 1 from the STEP output

maxtime = max(find(abs((chan1 - chan1(end)) / chan1(end) >

settling_percent)));

% Find the maximum time where you are MORE than 2% away from the final

% value

Settling_time_check = T(maxtime + 1)

% Settling time is then the next time step

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

Step Response Analysis:

Page 21: Modeling and Simulation

21

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.

Page 22: Modeling and Simulation

22

0 2 4 6 8 10 120

0.1

0.2

0.3

0.4

0.5

0.6

0.7X: 2.755

Y: 0.6446

System: G

Time (sec): 0.637

Amplitude: 0.0502

System: G

Time (sec): 1.63

Amplitude: 0.45

Step Response

Time (sec)

Am

plit

ude

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.

Page 23: Modeling and Simulation

23

0 2 4 6 8 10 12 14 160

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Step Response

Time (sec)

Am

plit

ude

original

estimate

The estimate above fit is bad since the delay is not taken into consideration.

Page 24: Modeling and Simulation

24

0 2 4 6 8 10 120

0.1

0.2

0.3

0.4

0.5

0.6

0.7

Step Response

Time (sec)

Am

plit

ude

original

estimate

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.

5.2 Non – Parametric Identification (Time Domain Models)

There are two sets of data provided which comes from the same signal. The data is in the usual

form of:

Time Input Output

Using Step Response

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

Page 25: Modeling and Simulation

25

conditionplot(<data>,<show plot>,<offset>,<smoothness>) created in the preceding part to

smooth the signal. The results are as follows.

0 5 10 15 20 25 30 35 40 45 50-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

1.2

1.4

time(s)

Originial Noisy Signal

Input Signal

This is the original signal. Notice it has high frequency noise. The shape of the signal can be seen

visually.

Page 26: Modeling and Simulation

26

0 5 10 15 20 25 30 35 40 45 50-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

1.2

1.4

time(s)

10X resampled output Signal

Input Signal

It is the downsampled by 10 times and a smoother plot is observed. The high frequency

oscillations are no longer present.

Page 27: Modeling and Simulation

27

0 5 10 15 20 25 30 35 40 45 50-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

1.2

1.4

time(s)

Spline Smoothed output Signal

Input Signal

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

for J = length(T):-1:1, % T is the time component of the discrete data

% search for when Y is ~90% of U. Y is the output. U is input.

if (Tr_ucount == 0) && (abs(Y(J)) <= Tr_u) && (T(J) < T(Ipeak))

Tr_ucount = J;

end

% search for when Y is ~10% of U

if (Tr_lcount == 0) && (abs(Y(J)) <= Tr_l) && (T(J) < T(Ipeak))

Tr_lcount = J;

end

Page 28: Modeling and Simulation

28

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%

Tr: 1.5 second

Tp: 4.35 second

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

Page 29: Modeling and Simulation

29

This can then be rearranged to give:

zeta = sqrt(1/ (1+ (-pi/log(OS/100))^2));

wn= (1-0.4167*zeta+2.917*zeta^2)/tr;

And the model for a second transfer function is in the form:

Using the values obtained for Wn and ζ, we can now find the transfer function.

MATLAB Code

% Qn 5.2. Non-Parametric Identification

clear all;

close all;

clc;

load set1.dat;

load set2.dat;

data1 = set1;

data2 = set2;

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) = [];

Page 30: Modeling and Simulation

30

disp(strcat('Mp :',num2str(OS)))

disp(strcat('Tr :',num2str(tr)))

disp(strcat('Tp :',num2str(tp)))

%================================

% Create 2nd Order TF Model

%================================

zeta = sqrt(1/ (1+ (-pi/log(OS/100))^2));

wn= (1-0.4167*zeta+2.917*zeta^2)/tr;

s = tf([1 0],1);

sys = wn^2/(s^2 + 2*zeta*wn*s + wn^2);

%================================

% 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)

Page 31: Modeling and Simulation

31

Console Output:

S-Domain Transfer Function

Transfer function:

1.034

---------------------

s^2 + 1.021 s + 1.034

Z-Domain Transfer Function at Sampling Frequency of 1 Hz

Transfer function:

0.1462 z^2 + 0.2923 z + 0.1462

------------------------------

z^2 - 0.8383 z + 0.423

Sampling time: 1

The code also plots the corresponding respond of the original step response to the estimated

step response. The results are good.

Page 32: Modeling and Simulation

32

0 5 10 15 20 25 30 35-0.2

0

0.2

0.4

0.6

0.8

1

1.2

Truncated Time

Tru

ncate

d C

om

mand a

nd R

esponse

X: 0.55

Y: 0

Using Impulse Response

0 5 10 15 20 25 30 35 40 45 50-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

1.2

time(s)

Originial Noisy Signal

Input Signal

Page 33: Modeling and Simulation

33

0 5 10 15 20 25 30 35 40 45 50-0.2

0

0.2

0.4

0.6

0.8

1

1.2

time(s)

10X resampled output Signal

Input Signal

0 5 10 15 20 25 30 35 40 45 50-0.2

0

0.2

0.4

0.6

0.8

1

1.2

time(s)

Spline Smoothed output Signal

Input Signal

Page 34: Modeling and Simulation

34

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.

Page 35: Modeling and Simulation

35

10 15 20 25 30 35 40 45 50-0.2

0

0.2

0.4

0.6

0.8

1

1.2

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));

The transfer function obtained is a very high order transfer function

Page 36: Modeling and Simulation

36

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.72e009 s^25 + 2.99e010 s^24 + 4.264e011 s^23 + 5.106e012 s^22

+ 5.215e013 s^21 + 4.59e014 s^20 + 3.507e015 s^19 + 2.339e016 s^18

+ 1.367e017 s^17 + 7.029e017 s^16 + 3.186e018 s^15 + 1.274e019 s^14

+ 4.499e019 s^13 + 1.4e020 s^12 + 3.831e020 s^11 + 9.193e020 s^10

+ 1.925e021 s^9 + 3.5e021 s^8 + 5.482e021 s^7 + 7.325e021 s^6

+ 8.22e021 s^5 + 7.566e021 s^4 + 5.499e021 s^3 + 2.96e021 s^2

+ 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

+ 3.233e009 s^24 + 4.648e010 s^23 + 5.718e011 s^22 + 5.897e012 s^21

+ 5.335e013 s^20 + 4.123e014 s^19 + 2.836e015 s^18 + 1.686e016 s^17

+ 8.985e016 s^16 + 4.166e017 s^15 + 1.737e018 s^14 + 6.326e018 s^13

+ 2.066e019 s^12 + 5.913e019 s^11 + 1.504e020 s^10 + 3.361e020 s^9

+ 6.559e020 s^8 + 1.129e021 s^7 + 1.643e021 s^6 + 2.121e021 s^5

+ 2.184e021 s^4 + 2.004e021 s^3 + 1.297e021 s^2 + 7.231e020 s

+ 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.

Page 37: Modeling and Simulation

37

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

Page 38: Modeling and Simulation

38

Time constant = τ = 50.03 – 49.34 = 0.68 seconds

Steady State Gain = Ks = 0.653 / 1 = 0.653

First order T.F. Step Response

s68.01

653.0

+

u0 = 18, y0 = 6

Page 39: Modeling and Simulation

39

50 50.5 51 51.5 52 52.5

11.85

11.9

11.95

12

12.05

12.1

12.15

12.2

12.25

X: 50

Y: 12

X: 50.11

Y: 12.07

X: 52.4

Y: 12.2

output

input

Time constant = τ = 50.11 - 50 = 0.11 seconds

Steady State Gain = Ks = (55.2-50) / 1 = 0.2

First order T.F. Step Response

Page 40: Modeling and Simulation

40

s11.01

2.0

+

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

The following is the plot of the step analysis of the system

0 20 40 60 80 100 120 140 160 180 2000

2

4

6

8

10

12

14

Page 41: Modeling and Simulation

41

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

2

4

6

8

10

12

X: 0.99

Y: 11.8

Truncated Time

Tru

ncate

d C

om

mand a

nd R

esponse

X: 0.1128

Y: 4.423

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.

Therefore the transfer function for the motor is

s43.41

8.11

+

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

Page 42: Modeling and Simulation

42

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.

5.5 Non-Parametric Identification (Frequency Domain Method)

0 2 4 6 8 10 12 14 16 18 20-50

-40

-30

-20

-10

0

10

20

30

40

50

time(s)

input

output

The data is contaminated with high frequency noise. The conditionplot() method created will be

used. The resulting signal is shown.

Page 43: Modeling and Simulation

43

0 2 4 6 8 10 12 14 16 18 20-50

-40

-30

-20

-10

0

10

20

30

40

50

time(s)

Spline Smoothed output Signal

Input Signal

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.

Page 44: Modeling and Simulation

44

7 7.5 8 8.5 9 9.5 10 10.5 11 11.5

-10

-5

0

5

10

X: 8.35

Y: 3.509

time(s)

X: 9.61

Y: 0.0591X: 7.46

Y: 0.0079

Spline Smoothed output Signal

Input Signal

Phase = (9.61-8.35) / (9.61-7.46) * 2π = 3.6822rads

7 7.5 8 8.5 9 9.5 10 10.5 11 11.5

-10

-5

0

5

10

X: 8.36

Y: 3.5

time(s)

X: 8

Y: 1

X: 9.32

Y: 5.23

Spline Smoothed output Signal

Input Signal

Page 45: Modeling and Simulation

45

Gain = (5.23-3.5)/ 1 = 1.73

Frequency = 1 / (9.61-7.46) = 0.4651 Hz

From this exercise, we manage

5.6 Parametric Identification Of Assigned system

The following are the sinusoid outputs from sinusoid inputs used in the frequency analysis

0 5 10 15 20 250

2

4

6

8

10

12

14

16

18

X: 8.5

Y: 2.998

X: 8.7

Y: 16.12

X: 5.7

Y: 0.514

output

input

f = 0.1 Hz

Magnitude = 16.12 – 0.514 / 2 / 1.5 = 15.9487

Phase = (8.7-8.5)/(1/0.1)*(2*pi) = 0.1257 rad

Page 46: Modeling and Simulation

46

0 5 10 15 20 250

2

4

6

8

10

12

14

X: 9.74

Y: 0.002

X: 9.9

Y: 3.035

X: 10.38

Y: 13.75

output

input

f = 0.2 Hz

Magnitude = 13.75 -3.035/2/1.5 = 12.7383

Phase = (9.9-9.74)/(1/0.2)*(2*pi) = 0.2011 rad

Page 47: Modeling and Simulation

47

0 2 4 6 8 10 12 140

2

4

6

8

10

12

14

X: 5.82

Y: 0.001

X: 6.28

Y: 12.43

X: 5.94

Y: 4.513

output

input

f = 0.3 Hz

Magnitude = 12.43 -4.513/2/1.5 = 10.9257

Phase = (5.94-5.82)/(1/0.3)*(2*pi) = 0.2262 rad

Page 48: Modeling and Simulation

48

0 2 4 6 8 10 12 14 16 18 200

2

4

6

8

10

12

X: 8.22

Y: 11.5

X: 7.98

Y: 5.396

X: 7.86

Y: 0.001

output

input

f = 0.4 Hz

Magnitude = 11.5 -5.396/2/1.5 = 9.7013

Phase = (7.98-7.86)/(1/0.4)*(2*pi) = 0.3016 rad

Page 49: Modeling and Simulation

49

0 1 2 3 4 5 6 7 8 90

5

10

15

X: 4.38

Y: 5.926

X: 4.28

Y: 0.001

X: 4.16

Y: 10.97

output

input

f = 0.5 Hz

magnitude = 10.97-5.926/2/1.5 = 8.9947

Phase = (4.38-4.28)/(1/0.5)*(2*pi) = 0.3142 rad

Page 50: Modeling and Simulation

50

0 5 10 15 20 250

2

4

6

8

10

12

14

X: 2.82

Y: 10.39

X: 2.74

Y: 2.983

output

input

f = 0.6 Hz

Magnitude = 10.71 – 6.359 /2/1.5 = 8.5903

Phase = (2.82-2.74)/(1/0.6)*(2*pi) = 0.3016 rad

Page 51: Modeling and Simulation

51

0 5 10 15 20 250

2

4

6

8

10

12

X: 3.84

Y: 10.34

X: 3.76

Y: 2.978

output

input

f = 0.7 Hz

Magnitude = 10.34 -6.6/2/1.5 = 8.1400

Phase = (3.84-3.76)/(1/0.7)*(2*pi) = 0.3519 rad

Page 52: Modeling and Simulation

52

0 2 4 6 8 10 120

2

4

6

8

10

12

X: 3.86

Y: 10.09

X: 3.8

Y: 2.986

output

input

f = 0.8 Hz

Magnitude = 10.07 -6.841/2/1.5 = 7.7897

Phase = (3.86-3.8)/(1/0.8)*(2*pi) = 0.3016 rad

Page 53: Modeling and Simulation

53

0 2 4 6 8 10 12 14 16 18

1

2

3

4

5

6

7

8

9

10

X: 1.44

Y: 9.892

X: 1.14

Y: 2.955

X: 6.7

Y: 2.989

X: 6.76

Y: 10.01

output

input

f = 0.9 Hz

Magnitude = 9.892 -7.081/2/1.5 = 7.5317

Phase = (6.76-6.7)/(1/0.9)*(2*pi) = 0.3393 rad

Page 54: Modeling and Simulation

54

Magnitude plot of System

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.97

8

9

10

11

12

13

14

15

16

freq (Hz)

Gain

Phase plot of System

Page 55: Modeling and Simulation

55

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9-0.4

-0.35

-0.3

-0.25

-0.2

-0.15

-0.1

-0.05

freq (Hz)

phase (

rad)

This method is very slow even if the comparing of the sampled sine waves are automated.

8.1 Design of continuous time control system

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

This is used in the following block diagram.

Page 56: Modeling and Simulation

56

The resulting step response is as follows:

To look at the amount of over shoot, the image is transferred to MATLAB.

Page 57: Modeling and Simulation

57

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

Page 58: Modeling and Simulation

58

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.

0 5 10 15 20 25 300

0.2

0.4

0.6

0.8

1

1.2

1.4

Ki = 10.1418Kp = 23.6699Kd = 5.1514

input Signal

Page 59: Modeling and Simulation

59

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.

8.3.1 Pole placement and results

Page 60: Modeling and Simulation

60

Another method to design D(z) is to convert a continuous time plant G(s) into discrete time.

Given that

64.016)(

2+−

=

zz

zzG

z

zk

z

zkkzD IDp

1)

1()(

−+

+=

)()(1

)()()(

zDzG

zDzGzH

+

=

The CE is what determines the poles:

0)64.0()24.2()6.2(

0)()(1

22=−+−−+−+++

=+

DDPDIp kzkkzkkkz

zDzG

Solving for all the gains:

004.044.04.1

0)1()2.0(

22

2

=+++

=++

zzz

zz

04.064.0

44.0224.2

4.16.2

=−

=−−

=−++

D

Dp

DIp

k

kk

kkk

From the above we can find the gains:

68.0=Dk

68.0

88.2

44.0

44.0)68.0(224.2

=

=

=

=−−

d

I

p

p

k

k

k

k

With T = 1, using the same model as 8.1 the following diagram shows a block in Simulink.

Page 61: Modeling and Simulation

61

The system is stable but with large overshoot. Also the steady state gain is 0.5.

8.3.2 Using Particle Swarm Optimization to find Optimal Parameters

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.

The optimum controller gain is found to be Ki=0.78973 Kp = 1.0503 and Kd = 0.67555.

Page 62: Modeling and Simulation

62

0 5 10 15 20 25 300

0.2

0.4

0.6

0.8

1

1.2

1.4

Ki = 0.78973 Kp = 1.0503 Kd = 0.67555

Input signal

The following screenshot shows the PSO toolbox searching for the global minima.

Page 63: Modeling and Simulation

63

The next two screen shot shows the output signal followed by the input signal from the scope

in Labview.

8.4 PID Control for Actual System

Off line searching Optimum Controller Gains

Page 64: Modeling and Simulation

64

Using model obtained from the step response, we PSO to optimize the controller gains. The

following set of gains are obtained.

This corresponds to the following simulated response.

Page 65: Modeling and Simulation

65

0 5 10 15 20 25 300

0.2

0.4

0.6

0.8

1

1.2

1.4

Ki = 2.715Kp = 29.9812Kd = 8.6986e-006

input Signal

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.

Page 66: Modeling and Simulation

66

This is much faster than the open loop response.

8.4 Online searching for the Optimum Controller Gains

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.

Page 67: Modeling and Simulation

67

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.

Page 68: Modeling and Simulation

68

Page 69: Modeling and Simulation

69

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.

Page 70: Modeling and Simulation

70

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.

8.5 Control using State-Feedback Adaptive Filter

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).

Page 71: Modeling and Simulation

71

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

Wn × [-0.7081; -0.5210+1.068j; -0.5210-1.068l]

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.

Page 72: Modeling and Simulation

72

Page 73: Modeling and Simulation

73

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.

Page 74: Modeling and Simulation

74

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.