Sie sind auf Seite 1von 36

Discre'za'on

Hans-­‐Pe0er  Halvorsen,  M.Sc.  


Spesial'lfelle   Reguleringsteknikk  
Laplace   1.orden  
Tilstandsrom-­‐   Differensial Transfer-­‐
K  =  Forsterkning  
modeller   -­‐likninger   funksjoner   T=Tidskonstant  

Blokk-­‐ 1.orden  med  'dsforsinkelse  


diagrammer   Sprang-­‐
Tidsplanet   S-­‐planet   respons  
Serie,  Parallel,  Feedback  

Diskre@sering   2.orden  
Dataverktøy  
Analyse/Design  
Stabilitets-­‐
MathScript   Det  komplekse  plan  
analyse  
2.  Frekvensrespons  
LabVIEW   1.  Systemets  poler   Bodediagram  
Det  komplekse  plan  
Realisering/  
Implementering  

Diskre@sering  
Reguleringssystem  
Asympto'sk  stabilt  system  

Air  Heater   Marginalt  stabilt  system  


Tidsplanet  
Asympto'sk  stabilt  system  
Ustabilt  system   Marginalt  stabilt  system  
Ustabilt  system  
Table  of  Contents  
1.  What  is  Discrete  Signals  and  Discre'za'on?  
2.  Why  Discre'za'on?  
3.  Discre'za'on  Methods  
–  Euler,  Tus'n,  ZOH,  etc.  
4.  Discre'za'on  Examples  
–  Differen'al  Equa'ons  -­‐>  Difference  Equa'ons  
–  Con'nous  State-­‐space  models  -­‐>  Discrete  State-­‐space  models  
5.  Discre'za'on  in  MathScript  with  Examples  
6.  Discre'za'on  in  LabVIEW  with  Examples  
7.  Discrete  Lowpass  Filter  
–  Discrete  Algorithm  
–  LabVIEW  Implementa'on    (Example)    
Needed  in  
8.  Discrete  PI  Controller   the  Project  
–  Discrete  Algorithm  
–  LabVIEW  Implementa'on  (Example)  
9.  PC-­‐based  Control  System  –  LabVIEW  Example  
Digital  Signals  &  Values  
Binary  Values:  “0”  and  “1”  

E.g.  8  bit:  
00000000  -­‐>  0  
…  
…  
0   1   0   1   0   …  
8  bits  have  256  
11111111  -­‐>  255  
different  combina'ons  
Resolu@on:   or  levels  

E.g.  8  bit  resolu'on  

Resolu'on:  5V/256=0.0195V  
AD  &  DA  Converters  
Measurement  
Signal  

AD  Converter  

Control  Signal  
DA  Converter  

AD  –  Analog  to  Digital    


DA  –  Digital  to  Analog  
Con@nuous  Signal  

Discret  Signal   A  computer  can  only  deal  


with  discrete  signals  
Different  Discrete  Symbols  
and  meanings  

Previous  Value:  

Present  Value:  

Next  (Future)  Value:  

Note!  Different  Nota'on  is  used  in  different  li0erature!  


Sampling  and  Aliasing  
Original  Signal  
Aliasing  (“Nedfolding”)  -­‐>  The  Sampling  Rate  is  to  low!  

Sampling  Frequency  
Sampling  Time  
Discrete  Approxima'on  of  the  'me  deriva've  
Euler  backward  method:  

Euler  forward  method:  


Discre'za'on  Methods  
Euler  backward  method:  

More  Accurate!  

Euler  forward  method:  

Simpler  to  use!  

Other  methods  are  Zero  Order  Hold  (ZOH),  Tus'n’s  method,  etc.  
Discre'za'on  Example  
Given  the  following  con'nuous  system:  

We  will  use  the  Euler  forward  method  :  

Students:    
Pen  and  paper:  Find  the  difference  equa'on  
(discrete  differeni'al  equa'on)  for  this  
system.  
Discre'za'on  Example  -­‐  Solu'ons  
Given  the  following  con'nuous  system:  

We  will  use  the  Euler  forward  method  :  


Discre@za@on  in  MathScript  -­‐  Alt.  1  
% Simulation of discrete model
clear, clc

% Model Parameters
a = 0.25;b = 2;

% Simulation Parameters
Ts = 0.1; %s
Tstop = 20; %s
uk = 1; % Step in u
x(1) = 0; % Initial value

% Simulation
for k=1:(Tstop/Ts)
x(k+1) = (1-a*Ts).*x(k) + Ts*b*uk;
end
Students:    
% Plot the Simulation Results Implement  and  Simulate    
k=0:Ts:Tstop; this  system  in  MathScript  
plot (k, x)
grid on
Discre@za@on  in  MathScript  -­‐  Alt.  2  

% Find Discrete model


clear
clc

% Model Parameters
a = 0.25;
b = 2;
Ts = 0.1; %s

% State-space model
A = [-a];
B = [b];
We  get  the  same  answer  as  in  
C = [1];
D = [0];
previous  example!  
Students:    
model = ss(A,B,C,D) Implement  and  Simulate    
model_discrete = c2d(model, Ts, 'forward')
this  system  in  MathScript  
step(model_discrete)
Discre'za'on  in  LabVIEW  using  
the  Formula  Node  
Implemen'ng  dicrete  equa'ons  in  
LabVIEW  using  C  syntax  

Example  (bacteria  popula'on):  

SubVI  

Students:  Implement  and  Simulate  this  system  in  LabVIEW  using  a  Formula  Node  
and  a  For  Loop.  A  SubVI  could  be  used  to  implement  the  model.  
We  will  simulate  the  number  of  bacteria  in  the  jar  aqer  1  hour  (simula'on  period),  
assuming  that  ini'ally  there  are  100  bacteria  present  (x(0)).  Set  b=1,  p=0.5.  Set  Ts=0.01s.  
Discre'za'on  in  LabVIEW  using  the  Formula  Node  
-­‐  Solu'ons  

SubVI:  
Simula'on  Results:  

Note!  Right-­‐Click  and  select  Proper'es.  


Set  Mul'plier  =  0.01  (=Ts)  in  the  Scales   Note!  A  SubVI  is  
Tab.   used  to  
implement  the  
model.  
Recommended!!  
Discrete  State-­‐space  Models  

Or  using  another  nota'on:  


Discrete  State-­‐space  Models  -­‐  Example  
Given  the  following  con'nuous  system:  

We  will  use  the  Euler  forward  method  :  

Students:  Students:  Find  the  


discrete  state-­‐space  model  
(using  pen  and  paper)  
Discrete  State-­‐space  Models  -­‐  Example  
(Solu'ons)  
Given  the  following  con'nuous  system:  

We  will  use  the  Euler  forward  method  :  


Discrete  State-­‐space  Models  Example  
in  MathScript  
Given  the  following  con'nuous  system:  
Try  with  different  values  for  Ts!  
MathScript  
% Properties
Ts = 0.1;

% Continuous System:
A = [0, -Ts; 0, 0];
B = [2*Ts, 0]';
C = [1 0];
D = [0];
ssmodel = ss(A, B, C, D);
figure(1)
step(ssmodel)

% Discrete System:
ssmodel_discete = c2d(ssmodel, Ts, 'forward’)
figure(2)
step(ssmodel_discete)

Students:  Implement  the  system  above  and  find  the  step  response  using  MathScript.  
Project  
Implement  a  Control  System  for  the  Air  Heater  with  
Discrete  Lowpass  Filter  and  PI  Controller  from  Scratch  
Implemen'ng  a  Control  System  
While  the  real  process  is  con'nuous,  normally  the  Controller  and  the  Filter  is  
implemented  in  a  computer.  

Air  Heater  

We  are  going  to  find  discrete  algorithms  for  the  Lowpass  Filter  and  the  PI  Controller  
and  implement  them  in  LabVIEW  
PC-­‐based  Control  System  –  
LabVIEW  Example  (HMI/GUI)  
Tidsdiskret  (datamaskinbasert)  PID-­‐reguleringssløyfe  

ySP(tk) e(tk) u(tk) u(t) y(t)

tk=kTs tk tk t t
Ts

uman Manuell d

ySP e PID- u Pådrags-


y
omregning
DA Aktuator Prosess
regulator Auto

ymf ym
Måle- Måleverdi-
omregning
AD Sensor
filter

Målestøy
ymf(tk) Automatiseringsutstyr ym(t)
med mikroprosessor

tk t
Lowpass  Filter  
Lowpass  Filter  Transfer  func'on:  

Students:  Pen  and  Paper:  Find  the  discrete  algorithm  for  this  
filter,    which  can  be  implmented  in  a  programming  language  like  
C  or  LabVIEW  Formula  Node    

Use  the  Euler  Backward  method:  


Discrete  Lowpass  Filter  
Lowpass  Filter  Transfer  func'on:  
We  define:  

Inverse  Laplace  gives  the  differen'al  Equa'on:  

This  gives:  
We  use  the  Euler  Backward  method:  

This  gives:   Filter  output   Noisy  input  signal  

This  algorithm  can  be  easly  implemented  


in  a  Programming  language  
Discrete  Lowpass  Filter  -­‐  LabVIEW  

Example  of  
Implementa'on  

Students:  Implement  a  Discrete  


Lowpass  Filter  and  make  sure  to  test  it  
properly  
Tes'ng  the  Discrete  Lowpass  Filter  
PI  Controller  
Con'nuous  PI  Controller:  

Students:  Pen  and  Paper:  Find  the  discrete  algorithm  for  this  PI  
controller,  which  can  be  implmented  in  a  programming  language  
like  C  or  LabVIEW  Formula  Node    

Use  the  Euler  Backward  method:  


Discrete  PI  Controller  
Con'nuous  PI  Controller:   We  may  set:  

This  gives  the  following  discrete  PI  algorithm:  

We  use  the  Euler  Backward  method:  

This  algorithm  can  be  easly  implemented  in  a  


Programming  language  
Discrete  PI  Controller  -­‐  LabVIEW  

Example  of  
Implementa'on  

Students:  Implement  a  Discrete  PI  Controller  and  make  sure  to  test  it  properly  
Test  of  Discrete  PI  Controller  in  LabVIEW  
Note!  Make  sure  to  compare  
your  PI  Controller  with  the  built-­‐
in  PID  Controller!   Mathema'cal  Model  
of  the  Process  

Feedback  Node  
PC-­‐based  Control  System  –  
LabVIEW  Example  (Real  process)  

Scaling:  1-­‐5V    
-­‐>  20-­‐50  
degrees  
Celsius  
SubVI:  

SubVI  that  handles   Tf  


the  I/O  between  
LabVIEW  and  the   Ts  
Real  Process  
PC-­‐based  Control  System  –  
LabVIEW  Example  (HMI/GUI)  
Tes'ng  your  PI  Controller  on  the  Air  
Heater  Process  
•  Test  1:  Compare  your  PI  Controller  with  one  
of  the  built-­‐in  PID  Controllers  in  LabVIEW  
•  Test  2:  Test  your  PI  Controller  when  
changing  the  Reference,  to  see  if  you  get  
good  tracking  (that  the  output  follows  the  
reference)  
•  Test  3:  Make  sure  that  your  PI  Controller  can  
handle  changes  in  the  Disturbance  (e.g.,  
hold  your  hand  in  front  of  the  tube  inlet)  
Hans-­‐Pe[er  Halvorsen,  M.Sc.  
Telemark  University  College  
Faculty  of  Technology  
Department  of  Electrical  Engineering,  Informa@on  Technology  and  Cyberne@cs  

   
E-­‐mail:  hans.p.halvorsen@hit.no  
Blog:  h[p://home.hit.no/~hansha/  
 

36  

Das könnte Ihnen auch gefallen