Implementing Digital Versions Of Analog Systems
(Under Construction)
Why Not Just Use Analog?
Conversion Algorithms
Rectangular Integration - Euler
Trapezoidal Integration - Bilinear Transformation
Examples And Thoughts On The Algorithms
Integral Controllers
Lead Compensators
Lag Compensators

Why Not Just Use Analog?

        There are numerous situations in which you need to process signals.  Examples include:

        Increasingly, those signals are digital, and even though they may eventually have to act on something in the analog word, we have a choice of processing them while they are digital or when they are analog.  Analog signal processing can be used to manipulate signals, but there are several disadvantages.
Goals For This Lesson

        Processing signals digitally is more than a course in itself.  However, here we can adopt some limited goals.


Conversion Algorithms

        To convert an analog transfer function into a digital form which - when implemented - will act to mimic the analog system is not something that works automatically.  There are numerous different ways to effect the conversion, and each has its advantages and disadvantages.  In this section we will start by examining the simplest possible conversion algorithm.

        There is a small family of conversion algorithms based on the idea that some function of z - the Z Transform variable - can be substituted in an analog transfer function, replacing the s variable there.  We'll start with a very simple algorithm from that family.

        A basic operation in the time-domain is integration.  If u(t) is integrated to give y(t), we write that operation in the time domain as:

        In the Laplace transform domain, this operation is:

Y(s)/U(s) = 1/s

        Now, if we can determine a way to represent the integration operation as a difference equation in a sampled system that will correspond to the 1/s operation in the Laplace transform domain.

        There are lots of ways to approximate integrals.  That's how we have a family of different conversion algorithms.  We get a different conversion algorithm for different integration methods.  We will start with a very simple integration method.  This method approximates an integral using a sequence of rectangles to estimate the area under the curve of the variable to be integrated.

        Below is a pictorial representation of the integral approximation.

        At a given time, kT, the area of the next rectangle is u(kT)T.  We can then write a difference equation for the computed value of the integral.

 y((k + 1)T) = y(kT) + u(kT)T

This reflects the fact that the additional area - of the next rectangle - is u(kT)T.

        Now, take the Z Transform of both sides of the difference equation.

        The critical conceptual leap is to identify the form T/(z - 1) with the form 1/s that appears as the transfer function for an analog integration.         We use this new-found equivalence between s and (z - 1)/T when we convert transfer functions.
Example

E1   Consider a transfer function, G(s) = 4/(s + 3).  We convert that transfer function to an equivalent z-form using (z - 1)/T in the z-form where we find s in the original transfer function.



        Every sampled system obeys a difference equation, and that difference equation determines the transfer function - or conversely, we can get the difference equation from the transfer function.  The difference equation and the transfer function are just two different ways of representing the same system.  We can illustrate that better by continuing with the example system.
Example

E2   Consider that transfer function some more.  Let's find the difference equation that the equivalent sampled system would satisfy.  We have:



        Now, the problem is how to implement the difference equation you get when you convert an analog system to a digital system.  We'll show that by continuing with the example system.
Example

E2   The difference equation:

yk+1 + (3T - 1)yk =  4Tuk

can be implemented with a computer program using the scheme below.

        The actual code would look something like the following:

 Unew = MeasureInput;    /* Measure a new input*/
 Ynew = (4*T*Uold) - (3*T - 1)*Yold; /* Compute new output*/
 Uold = Unew;     /* Store old values. */
 Yold = Ynew;
 OutputVoltage(Ynew);    /* Output the computed value*/
 Wait(T);
This code would have to be embedded in a loop and run continuously.

How would the system respond?  The picture below shows the response of a mimic system using T = 1.0 sec.

        Here you can see the response when the sample time is 0.5 sec.  It's useful to compare this response to the one with a sample time of 1.0 sec.

 There is a fundamental question that arises here.

v Which of these two systems more accurately mimics the original
 continuous system?

 To answer that question we need to look at the step response of the sampled system and compare that to the step response of the original system.

 The system has a transfer function of:

 G(s) = 4/(s + 3)

So, the step response is:
 

"
"
Using A Conversion Algorithm - 9

 The two plots are superposed below.  Since one plot is a function of time and the other is a function of sample number, we have blotted out the scales and substituted the actual time for both the sampled version and the time function.

v The sampled version - for T = .05 sec - is always above the true response.

v The sampled version - for T = .1 sec -
 is always above the sampled version
 for T = 0.5.

v The sampled system with T = .05 sec
 is the more accurate."
"
Using A Conversion Algorithm - 10

 Generally, if you want to mimic a continuous analog system, the following rules apply.

v The faster the sampling rate the better the representation of the
 continuous analog system.

v In the limit, as the sampling rate becomes arbitrarily large, the
 representation gets closer and closer to the analog system."
"
The Bilinear Transformation

 The example we have just examined was based on a particular integration method.  Other integration methods will produce different results.  For example, another numerical integration method is the trapezoidal integration algorithm.  Here we give you an opportunity to compare the two types of integration, trapezoidal and rectangular.  (Click back and forth to compare.)"
"
The Bilinear Transformation - 2

 Comparing these two integration methods, it is clear that the trapezoidal method is more accurate than the rectangular integration method (Click back and forth to compare.)  What we need to do is to determine an equivalent z-transform expression for the trapezoidal method.  Note that we ought to expect the z-transform equivalent for this integration method to be different from what we have for the rectangular method."
"
The Bilinear Transformation - 3

 We can compute the area under the curve from t = 0 to t = kT.  The expression for the estimated area under the kth interval is:

Areak = (uk  + uk-1)(T/2)

The total area is the sum of all the individual areas up to that point."
"
The Bilinear Transformation - 4

 Since: y(kT) = Areak = (uk  + uk-1)(T/2)

Then, y((k + 1)T) = y(kT) + [u(kT) + u()k + 1)T)](T/2)

We will need this expression to compare the two integration algorithms later."
"
The Bilinear Transformation - 5

 Although we can express the total area in terms of a sum, we need to get a difference equation that tells how to update the total area.  That difference equation is:

yk+1 = yk + (uk  + uk-1)(T/2)

This difference equation can be transformed to give:

zY[z] = Y[z] + (U[z] + zU[z])(T/2)

In turn, this can be rearranged to get the area in terms of the variable being integrated, u.

Y[z](z - 1) = U[z](z + 1)(T/2)

or: Y[z]/U[z] = (T/2)((z + 1)/(z - 1))"
"
The Bilinear Transformation - 6

 In other words, the transfer function of the integration is:

 (T/2)((z + 1)/(z - 1))

This is not the same result that was obtained for the rectangular integration algorithm.  If we want to use this integration algorithm to mimic a system we would end up with a completely different computer code.

 On the next page, we'll compare the two methods."
"
The Bilinear Transformation - 7

 The two transformations from the s-plane to the z-plane that we have considered so far can be compared here.  Click the hotwords to compare.

v The rectangular integration algorithm (a.k.a the Forward Euler Algorithm).

v The trapezoidal integration method (a.k.a the Bilinear Transformation)

"
"
Reflecting On These Two Transformations

 These two transformations are similar.  There is one very important characteristic that they share.

v An integration factor in a transfer function - (1/s) - puts a pole
 at s = 0 for a continuous system.  In the sampled case, no matter
 how the transformation is effected it will have a pole at z = 1.

 v That pole at z = 1 has to be present for any transfer function that
 implements an integration.  Consider a sampled step.  It has a
 pole at z = 1.  Another pole at z = 1 in the system is needed to
 give a sampled ramp in the output - and you need to have that
 if you are integrating."
"
Reflecting On These Two Transformations - 2

 In the next section we will examine using these two transformations.  As we do that remember the following:

v We are looking at only two of the many difference algorithms that can be
 used for conversion of an analog system to an ""equivalent"" sampled
 system.

 v We really haven't defined ""equivalent"" in this context.  In some sense, the
 resulting sampled system will do approximately what the continuous system
 - from which the sampled system is derived - would do.

v Using either of these transformations the approach is the same.  There is some
 function of z which replaces s wherever s appears in the transfer function
 for the continuous system."
"
Using The Rectangular and Bilinear Transformations

 Once you've learned about the rectangular and bilinear transformations you can use them to implement various kinds of different systems.  One important class of systems to implement is a digital compensator or controller for a control system.  Basically, a compensator is just a system with one or more poles, and possibly as many zeroes, used to influence stability properties of control systems, and other behavior in those systems.

v One important class of controller is the integral controller.  It's easy to
 implement a digital integral controller.  Click to learn how.  (Although
 it is just the next section.)

v Lead compensators are important.  Click here to get to that section.

v Lag compensators are also important.  Click here to get to that section."
"
Implementing Digital Integral Controllers

 A control system with an integral controller will have a controller with a transfer function G(s) = Ki/s.  In order to implement that integration digitally, we need to do the following:

& Implement a controller with a sampled (z-form) transfer function of:

 G[z] = KiT/[z - 1]  using the rectangular algorithm,

 G[z] = Ki(T/2)[z + 1]/[z - 1] using the bilinear transformation."
"
Implementing Digital Integral Controllers - 2

 This field has some code that implements
the rectangular algorithm.  There are three
things you need to do:

v Define variables,

v Initialize variables and instruments,

v Loop through measurements, integral
 updates and outputting the control signal."
"
Implementing Digital Integral Controllers - 3

 Implementing the bilinear transformation takes more code, but follows the same steps.  Notice how the new area (integral) is just added to the old value using the trapezoidal formula.  The code makes sense if you remember how the algorithm came about!
"
"
Implementing Digital Lead Compensators

 Lead compensators are an important kind of subsystem that you may need to produce desired behavior in a control system you are designing.  In this section we will discuss implementing lead compensators with digital systems.

 The transfer function of a compensator is shown below.  If the compensator is a lead compensator, then there is one pole and one zero in the lead compensator transfer function, and we must have:

v wz < wp

 In other words, the corner frequency for the zero in the transfer function has to be smaller than the corner frequency for the pole."
"
Implementing Digital Lead Compensators - 2

 Now, we are going to examine how to implement a lead compensator using the rectangular integration method and using the bilinear transform.

v If you want to review the rectangular integration method, click here.

v If you want to review the bilinear transformation method, click here.

v We will assume that you have a compensator transfer function of the form below.
 Click here to go to the next page - implementing the rectangular method."
"
Implementing Digital Lead Compensators - 3

 The algorithm using the rectangular integration method is simple.

v Replace every s in the transfer function with the z-equivalent, (z - 1)/(z DT).

v Then, simplify to polynomial form.

v From the polynomial form you can get a difference equation.

v The difference equation will lead directly to a simple code implementation.

v The next page starts an example."
"
Implementing Digital Lead Compensators - 4

 Assume that we have a lead compensator.  The transfer function we will assume we have is:
 
 
 

We choose this transfer function only because it has numbers that won't get confusing as we go along.  We start with the first step in the algorithm.

v Replace every s in the transfer function with the z-equivalent, (z - 1)/(z DT).

 We immediately realize that we need to know the sampling rate, DT.  This system has a time constant of 1/15 sec. and the sampling period should be less than that.  Let's assume that we are sampling at a rate of 50 samples/second, so:

 DT = 0.02

"
"
Implementing Digital Lead Compensators - 5

 Replacing s, we get:
 
 
 
 

v Next, we have to simplify to polynomial form.
 We get the result at the right by multiplying
 numerator and denominator by z DT.
 

v Then, we're on to the difference equation.

"
"
Implementing Digital Lead Compensators - 6

v From the polynomial form you can get a difference equation.

 Rewriting the expression for the transfer function, we note that the transfer function is the ratio of the lead compensator output to the lead compensator input in the z-domain.  Manipulating the expression above, we get:
 
 
 
 

where:
 Output is the output of the lead compensator, and
 Input is the input of the lead compensator.
"
"
Implementing Digital Lead Compensators - 7

 The expression - in the z-domain - relating the input and output of the compensator can give us the difference equation we want.
 
 
 
 
 
 

This difference equation is easy to implement in code."
"
Implementing Digital Lead Compensators - 8

v Here's the difference equation.  It's not hard at all.

OldInput = 0.; /* Initialize OldInput and OldOutput */
OldOutput = 0.;
.
.
NewInput = Error;
NewOutput = (OldOutput + NewInput*(1+15*DT) - OldInput)/(1 + 3*DT);
OldOutput = NewOutput;
OldInput = NewInput;

 The code in blue would be inside a control loop.  Note how the code directly corresponds to the difference equation repeated below."
"
Implementing Digital Compensators

 In the preceding section we looked at implementation of a lead compensator using the rectangular integration (Euler) method.  In this section we will use the bilinear transformation to implement a lag compensator.  That way we look at both methods and we look at two different kinds of compensators.  There is nothing about a lead that favors rectangular integration or a lag that favors the bilinear transformation.  We're just doing that to illustrate as much as possible."
"
Implementing Digital Lag Compensators

 The algorithm using the bilinear transformation method to implement a lag compensator is simple, and is essentially the same as using the rectangular integration method.

v Replace every s in the transfer function with the z-equivalent:

 (2/T)(z - 1)/(z + 1).

v Then, simplify to polynomial form.

v From the polynomial form you can get a difference equation.

v The difference equation will lead directly to a simple code implementation.

v The next page starts an example."
"
Implementing Digital Lag Compensators - 2

 Assume that we have a lag compensator.  The transfer function we will assume we have is:
 
 
 

We choose this transfer function only because it has numbers that won't get confusing as we go along.  We start with the first step in the algorithm.

v Replace every s in the transfer function with the z-equivalent,
 (2/T)(z - 1)/(z + 1).

 We immediately realize that we need to know the sampling rate, T.  This system has a time constant of 1/15 sec. and the sampling period should be less than that.  Let's assume that we are sampling at a rate of 50 samples/second, so:

 T = 0.02

"
"
Implementing Digital Lag Compensators - 3

 Replacing s in the transfer function with the z-equivalent, (2/T)(z - 1)/(z + 1).
 

    becomes
 
 
 

and this form can be simplified to:
"
"
Implementing Digital Lag Compensators - 4

 The difference equation we must implement in computer code now becomes:

Output(k+1) = [(112+T)Input(k+1) + (112-T)Input(k) + (14-T)Output(k)]/(14+T)

Check that code against the transfer function given again below."
"
Some Thoughts On Digital Forms For Analog Systems

 In this lesson we have considered some ways to get digital forms for analog systems.  That's the way much design is done today.  Perhaps we are moving toward a day when the design is done directly in the digital domain.  Who knows?  Ultimately, we need to deal with analog signals so there is an argument for design in the analog/continuous domain.  However you design systems you will probably need to be conversant with both kinds of systems, and you will surely need to know how to move back and forth between the two different domains.  That may keep life interesting for you, so have fun doing it.

 And, that's it for this lesson."