Control system - second order - understand it within the use of matlab

by 19:21 0 comments
Second Order System

3027390131_9785761bce_z.jpg

Introduction

Second order equations has the formula g(s)=wn2s(s+2wn), where wn and ζare the parameters of the system.
There is also two other important parameters that we have to consider, the good news they are functions of the above two parameters.
wd = wn1-2, =wn
In this report we will discuss the effect of changing these parameters on step response of the system, Bode diagram and margin of the system.

Changing

In order to study the effect of changing sigma we will use matlab script to do all the mathematical work.
When using wd=1and =0.5, 1, 5.
The graph for step response is following
Also the bode diagram is as following

And the margins ….
And of-course the code written to obtain these rsults …..
% Get the start and end time from the user and the number of points in time
tg = input('Enter the initial and final times(eg. [1 10]):_');
nt = input('Enter the number of time points nt(eg. 100):_');

% Making time vector
tt = linspace(tg(1), tg(2), nt);

% Repeat above for frequency(w)
wg = input('Enter the frequency range(eg. [0.01 100]):_');
nw = input('Enter the number of frequency points nt(eg. 100):_');
w = logspace(log10(wg(1)), log10(wg(2)), nw); % w vector

%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
%                                                                         %
%      Step Response and bode diagrame for fixed wd and variable sigma    %
%                                                                         %
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%

% Read the wd and number of segments
wd = input('Enter the fixed value of wd rad/sec (eg. 1):_');
nseg = input('Enter the number of segments (eg. 3):_');

% Open and clear (if opened) 3 figure windows
figure(1); clf reset; figure(2); clf reset; figure(3); clf reset;

% Loop number of segments
for jnseg=1:nseg
  % Get segma from the user
  str = sprintf('Please Enter the Value number %g of segma(eg. 0.5, 1, 5):_', jnseg);
  seg = input(str);
  
  % Calculate wn and theta
  wn = sqrt(seg^2 + wd^2);
  theta = seg/wn;
  
  % Store values in vectors
  wns(jnseg)=wn; wds(jnseg)=wd; thetas(jnseg)=theta; segs(jnseg)=seg;
  
  % Create the system open and closed loop
  numinator = wn^2; dominator = [1 2*seg 0];
  olSys = tf(numinator, dominator);
  clSys = minreal(olSys/(1+olSys));
  
  % Relative stability (gain margin, phase margin, gain crossover, phase crossover)
  [gm, pm, wgc, wpc] = margin(olSys);
  pc = rlocus(olSys);
  
  
  % Step response and Bode
  yt = step(clSys, tt);
  [mag, phase] = bode(clSys, w);
  
  % Extract needed part of mag and phase
  for jj=1:nw
     m(jj) = mag(:,:,jj);
     p(jj) = phase(:,:,jj);
  end
  mag = m'; phase = p';
  
  % Draw the step response
  figure(1);
  plot(tt, yt);
  hold on;
  title(sprintf('Step response for closed loop system with fixed wd=%g', wd));
  xlabel('time(sec)'); ylabel('amplitude'); shg; % Pring graph on the top of the screen
  gtext(sprintf('-->segma=%g', seg));
  
  
  % Draw bode diagram
  figure(2); subplot(211); semilogx(w, 20*log10(mag)); hold on;
  title(sprintf('the magnitude for C.L. analog system with fixed wd=%g', wd));
  xlabel('log w'); ylabel('Magnitude db'); shg;
  gtext(sprintf('-->segma=%g', seg));
  
  figure(2); subplot(212); semilogx(w, phase); hold on;
  title(sprintf('the phase for C.L. analog system with fixed wd=%g', wd));
  xlabel('log w'); ylabel('phase deg'); shg;
  gtext(sprintf('-->segma=%g', seg));
  
  % Draw the margins
  figure(3); margin(olSys); hold on;
end

Changing wd

After editing the code so that =1, and wd= 0.5, 1, 1.5we now have the following results.

Effect on step response …
Bode diagram …
And margins ….
Capture.PNG
Finally … the code we were using (it not that big different code).
% Get the start and end time from the user and the number of points in time
tg = input('Enter the initial and final times(eg. [1 10]):_');
nt = input('Enter the number of time points nt(eg. 100):_');

% Making time vector
tt = linspace(tg(1), tg(2), nt);

% Repeat above for frequency(w)
wg = input('Enter the frequency range(eg. [0.01 100]):_');
nw = input('Enter the number of frequency points nt(eg. 100):_');
w = logspace(log10(wg(1)), log10(wg(2)), nw); % w vector

%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
%                                                                         %
%      Step Response and bode diagrame for fixed sigma and variable wd    %
%                                                                         %
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%

% Read the segma and number of wds
seg = input('Enter the fixed value of sigma  (eg. 1):_');
nwd = input('Enter the number of wds (eg. 3):_');

% Open and clear (if opened) 3 figure windows
figure(1); clf reset; figure(2); clf reset; figure(3); clf reset;

% Loop number of wds
for jnwd=1:nwd
  % Get wd from the user
  str = sprintf('Please Enter the Value number %g of wd rad/sec(eg. 0.5, 1, 5):_', jnwd);
  wd = input(str);
  
  % Calculate wn and theta
  wn = sqrt(seg^2 + wd^2);
  theta = seg/wn;
  
  % Store values in vectors
  wns(jnwd)=wn; wds(jnwd)=wd; thetas(jnwd)=theta; segs(jnwd)=seg;
  
  % Create the system open and closed loop
  numinator = wn^2; dominator = [1 2*seg 0];
  olSys = tf(numinator, dominator);
  clSys = minreal(olSys/(1+olSys));
  
  % Relative stability (gain margin, phase margin, gain crossover, phase crossover)
  [gm, pm, wgc, wpc] = margin(olSys);
  pc = rlocus(olSys);
  
  
  % Step response and Bode
  yt = step(clSys, tt);
  [mag, phase] = bode(clSys, w);
  
  % Extract needed part of mag and phase
  for jj=1:nw
     m(jj) = mag(:,:,jj);
     p(jj) = phase(:,:,jj);
  end
  mag = m'; phase = p';
  
  % Draw the step response
  figure(1);
  plot(tt, yt);
  hold on;
  title(sprintf('Step response for closed loop system with fixed segma=%g', seg));
  xlabel('time(sec)'); ylabel('amplitude'); shg; % Pring graph on the top of the screen
  gtext(sprintf('-->wd=%g', wd));
  
  
  % Draw bode diagram
  figure(2); subplot(211); semilogx(w, 20*log10(mag)); hold on;
  title(sprintf('the magnitude for C.L. analog system with fixed segma=%g', seg));
  xlabel('log w'); ylabel('Magnitude db'); shg;
  gtext(sprintf('-->wd=%g', wd));
  
  figure(2); subplot(212); semilogx(w, phase); hold on;
  title(sprintf('the phase for C.L. analog system with fixed segma=%g', seg));
  xlabel('log w'); ylabel('phase deg'); shg;
  gtext(sprintf('-->wd=%g', wd));
  
  % Draw the margins
  figure(3); margin(olSys); hold on;
end

Changing wn

Now we will see what changing wncauses, we consider =0.707 and wn=0.707, 1.4, 7.07.

The step response is ….
Capture.PNG
The Bode plot is ….
Capture.PNG
And the margins are …
Capture.PNG
And our pretty code …
% Get the start and end time from the user and the number of points in time
tg = input('Enter the initial and final times(eg. [1 10]):_');
nt = input('Enter the number of time points nt(eg. 100):_');

% Making time vector
tt = linspace(tg(1), tg(2), nt);

% Repeat above for frequency(w)
wg = input('Enter the frequency range(eg. [0.01 100]):_');
nw = input('Enter the number of frequency points nt(eg. 100):_');
w = logspace(log10(wg(1)), log10(wg(2)), nw); % w vector

%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
%                                                                         %
%      Step Response and bode diagrame for fixed theta and variable wn    %
%                                                                         %
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%

theta = input('Enter the value of theta (eg. 0.707):_');
nwn = input('Enter the number of wns (eg. 3):_');

% Open and clear (if opened) 3 figure windows
figure(1); clf reset; figure(2); clf reset; figure(3); clf reset;

% Loop number of wns
for jnwn=1:nwn
  % Get wn from the user
  str = sprintf('Please Enter the Value number %g of wn rad/sec(eg. 0.707, 1.4, 7.07):_', jnwn);
  wn = input(str);
  
  % Store values in vectors
  wns(jnwn)=wn; thetas(jnwn)=theta;
  
  % Create the system open and closed loop
  numinator = wn^2; dominator = [1 2*theta*wn 0];
  olSys = tf(numinator, dominator);
  clSys = minreal(olSys/(1+olSys));
  
  % Relative stability (gain margin, phase margin, gain crossover, phase crossover)
  [gm, pm, wgc, wpc] = margin(olSys);
  pc = rlocus(olSys);
  
  
  % Step response and Bode
  yt = step(clSys, tt);
  [mag, phase] = bode(clSys, w);
  
  % Extract needed part of mag and phase
  for jj=1:nw
     m(jj) = mag(:,:,jj);
     p(jj) = phase(:,:,jj);
  end
  mag = m'; phase = p';
  
  % Draw the step response
  figure(1);
  plot(tt, yt);
  hold on;
  title(sprintf('Step response for closed loop system with fixed theta=%g', theta));
  xlabel('time(sec)'); ylabel('amplitude'); shg; % Pring graph on the top of the screen
  gtext(sprintf('-->wn=%g', wn));
  
  
  % Draw bode diagram
  figure(2); subplot(211); semilogx(w, 20*log10(mag)); hold on;
  title(sprintf('the magnitude for C.L. analog system with fixed theta=%g', theta));
  xlabel('log w'); ylabel('Magnitude db'); shg;
  gtext(sprintf('-->wn=%g', wn));
  
  figure(2); subplot(212); semilogx(w, phase); hold on;
  title(sprintf('the phase for C.L. analog system with fixed theta=%g', theta));
  xlabel('log w'); ylabel('phase deg'); shg;
  gtext(sprintf('-->wn=%g', wn));
  
  % Draw the margins
  figure(3); margin(olSys); hold on;
end

Changing

Finally we will see the effect of changing , considering wn=1.414 and =0.866, 0.707, 0.5.
The step response is like following ….
Capture.PNG
The Bode plot ….
Capture.PNG
And the margins for sure ….
Capture.PNG
Finally the code used to obtain results (pattern must be very clear now)...
% Get the start and end time from the user and the number of points in time
tg = input('Enter the initial and final times(eg. [1 10]):_');
nt = input('Enter the number of time points nt(eg. 100):_');

% Making time vector
tt = linspace(tg(1), tg(2), nt);

% Repeat above for frequency(w)
wg = input('Enter the frequency range(eg. [0.01 100]):_');
nw = input('Enter the number of frequency points nt(eg. 100):_');
w = logspace(log10(wg(1)), log10(wg(2)), nw); % w vector

%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
%                                                                         %
%      Step Response and bode diagrame for fixed wn and variable theta    %
%                                                                         %
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%

wn = input('Enter the value of wn (eg. 1.414):_');
ntheta = input('Enter the number of thetas (eg. 3):_');

% Open and clear (if opened) 3 figure windows
figure(1); clf reset; figure(2); clf reset; figure(3); clf reset;

% Loop number of thetas
for jntheta=1:ntheta
  % Get theta from the user
  str = sprintf('Please Enter the Value number %g of theta (eg. 0.866, 0.707, 0.5):_', jntheta);
  theta = input(str);
  
  % Store values in vectors
  wns(jntheta)=wn; thetas(jntheta)=theta;
  
  % Create the system open and closed loop
  numinator = wn^2; dominator = [1 2*theta*wn 0];
  olSys = tf(numinator, dominator);
  clSys = minreal(olSys/(1+olSys));
  
  % Relative stability (gain margin, phase margin, gain crossover, phase crossover)
  [gm, pm, wgc, wpc] = margin(olSys);
  pc = rlocus(olSys);
  
  
  % Step response and Bode
  yt = step(clSys, tt);
  [mag, phase] = bode(clSys, w);
  
  % Extract needed part of mag and phase
  for jj=1:nw
     m(jj) = mag(:,:,jj);
     p(jj) = phase(:,:,jj);
  end
  mag = m'; phase = p';
  
  % Draw the step response
  figure(1);
  plot(tt, yt);
  hold on;
  title(sprintf('Step response for closed loop system with fixed wn=%g', wn));
  xlabel('time(sec)'); ylabel('amplitude'); shg; % Pring graph on the top of the screen
  gtext(sprintf('-->theta=%g', theta));
  
  
  % Draw bode diagram
  figure(2); subplot(211); semilogx(w, 20*log10(mag)); hold on;
  title(sprintf('the magnitude for C.L. analog system with fixed wn=%g', wn));
  xlabel('log w'); ylabel('Magnitude db'); shg;
  gtext(sprintf('-->theta=%g', theta));
  
  figure(2); subplot(212); semilogx(w, phase); hold on;
  title(sprintf('the phase for C.L. analog system with fixed wn=%g', wn));
  xlabel('log w'); ylabel('phase deg'); shg;
  gtext(sprintf('-->theta=%g', theta));
  
  % Draw the margins
  figure(3); margin(olSys); hold on;
end

Conclusion

It looks like resonance peak is inverse proportional to , as well as POS, so Mr POS.
It also looks like BW 1Tr, Actually  BW = 0.35 / Tr

Where wnis inverse proportional to rise time so, wnTr.

Ammar Atef

Blog Creator

Always work and you will be happy, Writing code, designing system and learning some thing new, I call that real life, No matter what is the problem, humanity can solve it any way, Creative one who believes he is creative, Who really watch, think, try and success, World is watching us because we are engineers.

0 comments:

Post a Comment