Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Microcontroller based applied digital control (D. Ibrahim, 2006)

.pdf
Скачиваний:
1682
Добавлен:
12.08.2013
Размер:
5.68 Mб
Скачать

298 APPENDIX B MATLAB TUTORIAL

As an example, suppose that we wish to find the coefficients A, B and C of the partial fraction expansion

Y (s) =

 

 

 

1

 

 

 

=

 

A

 

+

 

B

 

+

 

C

 

.

(s

+

1)(s

+

2)(s

+

3)

s

+

1

s

+

2

s

+

3

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The required MATLAB commands are

>>num = [1];

>>den = conv([1 1],conv([1 2],[1 3]));

>>[r,p,k] = residue(num,den)

r =

0.5000 -1.0000 0.5000

p =

3.0000 -2.0000 -1.0000

k =

[ ]

 

 

 

 

 

 

 

 

 

 

 

 

The required partial fraction expansion is then

 

 

 

 

 

 

 

Y (s) =

 

0.5

 

1

 

+

 

0.5

.

 

 

 

 

 

 

 

 

 

s

+

1

s

+

2

s

+

3

 

 

 

 

 

 

 

 

 

 

B.2.2 Discrete-Time Systems

The Control System Toolbox also supports the design and analysis of discrete-time systems. Some of the most commonly used discrete-time system commands and algorithms are given in this section.

Discretizing a continuous transfer function. The C2d function can be used to discretize a continuous system transfer function. The sampling time must be specified. The default method of discretization is zero-order hold at the inputs, but other methods such as linear interpolation or bilinear approximation can be selected. For example, consider the continuous-time system transfer function

1

G(s) = . s + 4

Assuming the sampling period is 0.1 s we can convert the transfer function to discrete time using the following commands:

>>G = tf(1, [1,4]);

>>Gz = c2d(G, 0.1)

CONTROL SYSTEM TOOLBOX

299

Transfer function:

0.08242

-----------

z - 0.6703 Sampling time: 0.1

Thus, the required discrete time transfer function is

G(z) =

 

0.08242

.

z

0.6703

 

 

 

 

In the following example we convert a second-order continuous-time system,

4

G(s) = , s2 + 4s + 2

to discrete form, with sampling time 1 s:

>>G = tf(4,[1 4 2]);

>>Gz = c2d(G, 1)

Transfer function:

0.6697 z + 0.1878

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

z^2 - 0.5896 z + 0.01832 Sampling time: 1

Poles and zeros. The poles and zeros can be obtained as follows:

>> [z,p,k] = zpkdata(Gz,‘v’)

z =

-0.2804

p =

0.5567

0.0329

k =

0.6697

Thus, G(z) has one zero at 0.2804 and two poles at 0.5567 and 0.0329. The d.c. gain is 0.6697.

The positions of the poles and zeros can be plotted on the complex plane using the command

>> pzmap(num,den)

Also, the positions of the poles and zeros and the unit circle in the z-plane can be plotted using the command

>> zplane(num,den)

300

APPENDIX B MATLAB TUTORIAL

 

 

 

2

Step Response

 

 

 

 

 

 

 

1.8

 

 

 

 

1.6

 

 

 

 

1.4

 

 

 

 

1.2

 

 

 

 

1

 

 

 

 

0.8

 

 

 

 

0.6

 

 

 

 

0.4

 

 

 

 

0.2

 

 

 

 

0

5

10

15

 

0

Time (sec)

Figure B.8 Step response

Step response. The unit step response of G(z) is obtained from

>>num = [0 0.6697 0.1878];

>>den = [1 -0.5896 0.01832];

>>dstep(num,den)

and the response obtained is shown in Figure B.8.

Impulse response. The impulse response of G(z) is obtained by writing

>>num = [0 0.6697 0.1878];

>>den = [1 -0.5896 0.01832];

>>dimpulse(num,den)

and the response is shown in Figure B.9.

Root locus. The root locus diagram with lines of constant damping factor and lines of constant natural frequency is shown in Figure B.10 and is obtained from

>>zgrid(‘new’);

>>rlocus(num,den)

The gain and the roots at any point on the locus can interactively be found using the command

>> [k,p] = rlocfind(num,den)

Amplitude

Impulse Response

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0

0

5

10

15

Time (sec)

Figure B.9 Impulse response

Imaginary Axis

 

 

 

Root Locus

 

 

 

 

 

1

 

 

0.5π/T

 

 

 

 

 

 

 

0.6π/T

0.4π/T

 

 

 

 

 

 

 

 

 

0.8

 

0.7π/T

 

 

0.10.3π/T

 

 

 

 

 

 

 

0.2

 

 

 

0.6

 

0.8π/T

 

 

0.3

 

0.2π/T

 

 

 

 

0.4

 

 

 

 

 

 

 

 

 

 

 

 

 

0.5

 

 

 

0.4

 

 

 

 

0.6

 

 

 

 

 

0.9 π/T

 

 

0.7

 

0.1π/T

 

0.2

 

 

 

0.8

 

 

 

 

 

 

0.9

 

 

 

 

 

 

 

 

 

 

 

0

π/T

 

 

 

 

 

 

π/T

 

 

 

 

 

 

 

 

 

 

 

 

 

0.2

 

0.9 π/T

 

 

 

 

0.1π/T

 

 

 

 

 

 

 

 

0.4

 

 

 

 

 

 

 

 

0.6

 

0.8π/T

 

 

 

 

0.2π/T

 

 

 

 

 

 

 

 

 

0.8

 

0.7π/T

 

 

0.3π/T

 

 

 

 

 

 

 

 

 

 

 

 

0.6π/T

0.5π/T

0.4π/T

 

 

 

11

 

 

 

 

 

 

0.8 0.6 0.4 0.2

0

0.2

0.4

0.6

0.8

1

Real Axis

Figure B.10 Root locus diagram

302 APPENDIX B MATLAB TUTORIAL

Magnitude (dB)

Phase (deg)

Bode Diagram

10

5

0

5

10

15 0

45

90

135

180

 

 

 

102

101

100

101

Frequency (rad/sec)

Figure B.11 Bode diagram

Bode diagram. The Bode diagram of a discrete time system can be obtained (assuming a sampling time of 1 s) as

>>dbode(num,den,1);

>>grid

The graph obtained is shown in Figure B.11.

Nyquist diagram. The Nyquist diagram of a discrete time system can be obtained as (assuming a sampling time of 1 s)

>> dnyquist(num,den,1);

The graph obtained is shown in Figure B.12.

z-Transform. The z-transform of a time function can be found using the MATLAB function ztrans. Some examples are given below.

The z-transform of f (kT ) = kT is found as

>>syms k T;

>>ztrans(k*T)

ans = T*z/(z-1)^2

CONTROL SYSTEM TOOLBOX

303

Imaginary Axis

Nyquist Diagram

1.5

1

0.5

0

0.5

1

1.5

0.5

 

 

 

 

 

 

1

0

0.5

1

1.5

2

2.5

Real Axis

Figure B.12 Nyquist diagram

Notice that k and T are defined as symbols.

Similarly, the z-transform of f (kT ) = sin(akT ) is found as follows:

>>syms a k T;

>>f = sin(a*k*T);

>>ztrans(f)

ans =

z*sin(a*T)/(z^2-2*z*cos(a*T)+1)

or

>> pretty(ans)

z sin(a T)

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

2

z - 2 z cos(a T) + 1

Inverse z-transform. The inverse z-transform of a function can be found using the iztrans function. Some examples are given below.

G(z) =

304 APPENDIX B MATLAB TUTORIAL

The inverse z-transform of F(z) = T z/(z 1)2 is obtained as follows:

>>f = T*z/(z-1)^2;

>>iztrans(f)

ans = T*n

Notice that the default independent variable is n.

Coefficients of partial fraction expansion. MATLAB can be used to determine the coefficients of the partial fraction expansion. Some examples are given below.

Consider the transfer function

2z2 z

.

z2 3z + 2

We usually expand the term G(z)/z which gives a form which is usually easy to look up in the inverse z-transform tables. Thus,

G(z)

 

2z 1

.

z

 

= z2 3z + 2

The coefficients of the partial fraction expansion are found as follows:

>> [r,p,k] = residue([2 -1], [1 -3 2])

r =

3 -1

p =

2

1

k =

[]

where r are the residues, p are the poles and k are the direct terms. Thus,

 

G(z)

 

 

 

3

 

 

 

 

 

1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

z

 

= z

2

z

1

 

 

 

and

 

 

 

 

 

 

 

 

 

 

 

 

 

G(z) =

 

 

3z

 

 

 

 

z

 

 

 

 

 

 

 

 

 

 

 

 

z

2

 

z

1

 

 

 

 

 

 

 

 

 

 

 

 

 

The time function can easily be found using z-transform tables.

Another example is given below where there is one direct term. Consider the transfer function

G(z) = 2z2 + 2z 1 . z z2 3z + 2

The coefficients are found from

>> [r,p,k] = residue([2 2 -1], [1 -3 2])

r =

11 -3

 

 

 

 

 

 

 

 

 

 

 

 

CONTROL SYSTEM TOOLBOX

305

p =

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

k =

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Thus,

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

G(z)

=

 

 

 

11

 

 

 

 

3

 

 

+ 2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

z

z

2

z

1

 

or

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

G(z) =

 

11z

 

 

 

 

3z

 

 

 

+ 2z

 

 

 

 

 

 

 

 

 

 

 

z

2

z

1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

and the inverse z-transform can be found using z-transform tables.

 

The following example has a double pole. Consider the transfer function

 

 

G(z)

 

 

 

 

 

 

z2 + 4z 1

.

 

 

z

 

 

 

 

 

 

 

 

= z3 5z2 + 8z 4

 

The coefficients are found from

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

>> [r,p,k] = residue([0 1 4

-1], [1

 

 

-5

 

8 -4])

 

r =

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

-3.0000

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

11.0000

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

4.0000

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

p =

2.0000

2.0000

1.0000

k =

[ ]

There are two poles at z = 2, and this implies that there is a double root. The first residue is for the first-order term for the double root, and the second residue is for the second-order term for the double root. Thus,

 

G(z)

 

 

3

 

 

 

 

11

 

 

 

 

4

 

 

 

 

z

= z

2

+ (z

2)2

 

+ z

1

 

 

 

 

 

 

 

or

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

G(z) = −

 

3z

 

 

+

 

11z

+

 

4z

 

 

.

 

 

 

 

 

 

 

 

 

z

2

(z

2)2

z

1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The MATLAB command residuez can be used to compute the partial fraction expansion when the transfer function is written in powers of z1.

Index

Abs, 98

Absolute address variable, 83 Acceleration sensor, 20 Accelerometer, 2

Actuator, 6

AD590, 16 AD7302, 270 ADCON0, 73, 114 ADCON1, 73, 114 Adder, 244 ADFM, 74 ADRESH, 73 ADRESL, 73 ADXL202, 21

Air flow sensor, 23 Analog comparator, 5

Analog temperature sensor, 16 Analog to digital converter, 2, 72–75 AND, logical, 86

Anemometer, 23 Arithmetic logic unit, 7

Array of Jury’s stability test, 189 Arrays, 84, 85

multiple dimension, 85 Asm, 103

Assembly language, 9 Attenuation property, 143 Auxiliary storage, 8

Back emf, 42

Backslash character, 86

Ballast coding, 12

BASIC, 9, 77

Bank0, 67

Bank1, 67

Bidirectional bus, 7

Bidirectional I/O, 71

Binary number, 89

Bit, 78

Block diagrams, 153

Bode diagram, 205

Break statement, 96

Built-in function 98

Buzzer, 119

CAN bus, 57 Capacitor, 37

Cascade\realization, 246 Centralized control, 5 Characteristic equation, 187 Choice of sampling interval, 263 Client, 6

Closed-loop system, 1 Closed-loop time response, 166 Closed-loop tuning, 237 Coefficient sensitivity, 246 Comments, 81

Compensator, 1 Configuration register, 71 Connecting an LCD, 111 Connecting an LED, 107 Continue statement, 96

Continuous time system, 2, 131 Control,

centralized, 5

direct digital control, 11 distributed, supervisory, 6

Control engineer, 1 Control unit, 7 Controller, 1

Controller algorithm, 10

Microcontroller Based Applied Digital Control D. Ibrahim

C 2006 John Wiley & Sons, Ltd. ISBN: 0-470-86335-8

308 INDEX

Controller realization, 243 cascade, 246

direct canonical, 243 direct noncanonical, 245 parallel, 249

pid, 250 Cos, 98

Cosine function, 139 Current sink, 72 Current source, 72

Dahlin controller, 217 Damping ratio, 178 Dashpot, 28, 33

Data acquisition, 6 Data memory, 8 D/A converter, 3 DC motor, 42 DCS, 6

DDC, 11

Dead-beat controller, 215 Decimal number, 89 Define, 101

Delay, 244 Delayms, 105 Delayus, 105 Derivative kick, 233

Dielectric constant, 18 Differential equation, 27 Digital controller, 214

dead-beat, 215 dahlin, 217

pole placement, 219 pid, 230

Digital temperature sensor, 16 Digital to analog converter, 3 Direct current motor, 43 Direct digital control, 6 Direct structure, 243

Direct noncanonical structure, 245 Discrete controller design, 213 Distinct real root, 150

Distributed control, 5 Disturbance, 1

Do statement, 95 Double, 78 DS1620, 16

Dynamic response, 14

EEADR, 71

EECON1, 71 EECON2, 71 EEDATA, 71 EEPROM, 5 EEPROM,

accessing, 104

Electrical system, 37 Electromechanical system, 42 Encoder, 21

Endasm, 103 Energy stored,

in a capacitor, 37 in an inductor, 37 in mass, 29

in a spring, 28 EPROM, 8 Error signal, 1,4

Exponential function, 138 External interrupt, 10, 11, 67

Factorizing characteristic equation, 187 Final value theorem, 144

Finite word length, 282 First order module, 260 Flash memory, 5 Float, 78

Flow chart, 121 Flow meter, 22 Flow rate sensor, 23 Fluid system, 44 For statement, 94 Force sensor, 21 Functions,

built-in, 98 user, 97

Gain margin, 209 Gear train, 35

General purpose computer, 7, 8 General purpose register, 7, 67

Hard disk, 8

Hardware requirements, 119

HD44780, 111

Heat flow, 49

Hexadecimal number, 89

High level language, 9

Hydraulic capacitance, 45

Hydraulic inertance, 45

Hydraulic resistance, 44

Hydraulic system, 44

Hysteresis effect, 20

Ideal sampling, 131–133

If-else, 91

Include, 103

Inductor, 37

Induced voltage, 19

Inertance, 44

Initial value theorem, 143

Intertia of load, 43