# Blog Archives

## An Introduction to compensator Design with matlab

This will be a series of posts where I will be dealing with Control system Compensator design using matlab. This is intended primarily for Btech Electrical and Electronics students.

I will try to be as brief as possible the underlying concepts have to be studied from standard text books.

If there are any mistakes please point them out.

Basically the compensators have to be designed based on the time domain specifications like rise time, maximum overshoot,damping ratio and settling time. these are the transient state specifications. And in frequency domain the transient state specifications are phase margin, gain margin, resonant peak and bandwidth.

The steady state responses in both cases are the error constants.

We will start with what compensators are. Compensators are devices added to a control system so that it meets the given specifications. They introduce poles and zeroes to the system.

The main types of compensators are the lag, lead and lag lead.

**Lag Compensator**

A compensator that introduces a phase lag to an input signal is called a lag compensator. It improves the steady state performance of the system, but reduces the bandwidth and results in a slower transient response too. It is basically a low pass filter.

### Lead Compensator

A compensator that introduces a phase lead to an input signal is called a lead compensator. It increases bandwidth and improves speed ofresponse but there is only a small change in the steady state response. It is basically a high pass filter.

Please do refer text books for more details on compensators.

Compensators can be designed with time domain specifications and it is done using root locus technique and If frequency domain techniques are used then Bode plot is used( other frequency domain plots can also be used but here we deal with bode Plot).

**Commonly used functions in matlab**

**tf** – converts system representation from transfer function to “system” format. This format provides an efficient way to store and manipulate the system model, but does not allow direct access to the system’s numerator and denominator orpoles and zeros. The syntax to convert from transfer function to “system” format is:

*sys = tf (num, den);*

**tfdata** – converts system representation from “system” format back to transfer function format. The syntax (for single-input, single-output systems) is:

*[num, den] = tf data(sys, v );*

**series** – forms the series combination of 2 blocks to produce the equivalent transfer function. The output of block 1 is the input to block 2. The syntax for the function in transfer function and in “system” formats are:

*[num, den] = series(num1, den1, num2, den2);*

*sys = series(sys1, sys2);*

**parallel** – forms the parallel combination of 2 blocks to produce the equivalenttransfer function. The outputs of block 1 and block 2 are added together. The same input is applied to both block 1 and block 2. The syntax for the function in transfer function and in “system” formats are:

*[num, den] = parallel(num1, den1, num2, den2);*

*sys = parallel(sys1, sys2);*

**feedback** – forms the closed-loop system that has block 1 in the forward path and block 2 in the feedback path. The default configuration is for negative feedback. In the syntax example shown below, the −1 for negative feedback is shown explicitly. For positive feedback, a +1 would be used in the function’s input argument list. For unity feedback, num2 = den2 = 1. The syntax for the function in transfer function and in “system” formats are:

*[num, den] = f eedback(num1, den1, num2, den2, −1);*

*sys = f eedback(sys1, sys2, −1);*

**cloop** – forms the closed-loop system when unity feedback is used. This function is obsolete, but is still available in most MATLAB versions. It can only be used when the block in the feedback path is unity, and it can only be used with the system model expressed in transfer function form, not in “system” format. The syntax for the function is:

*[num, den] = cloop(num1, den1, −1);*

**rlocus** – computes and plots the root locus for a system, using an internally generated set of gain values. A user-specified vector of gain values can be included as an input argument if desired. Output arguments of closed-loop poles and the corresponding gain values can also be obtained. In this case, no plot is made. If the root locus plot for negative gain values is desired, a minus sign is placed in front of num or sys. The syntax for the function in transfer function and in “system” formats are:

*rlocus(num, den);*

*rlocus(sys);*

**rlocfind** – computes the gain and the corresponding closed-loop pole locations for a specified point on the root locus. A crosshair is made available to select a point on the root locus plot. The gain corresponding to that point is returned, as well as all the closed-loop poles for that gain. The syntax for the function in transfer function and in “system” formats are:

*[K, poles] = rlocf ind(num, den);*

*[K, poles] = rlocf ind(sys);*

Instead of graphically selecting a point, one or more desired closed-loop pole locations can be input to the function. The gains and closed-loop poles cor- responding to those specified pole locations are returned. No error message is given if the specified pole locations are not actually on the root locus for the system. The syntax for the function in transfer function and in “system” formats are:

*[K, poles] = rlocf ind(num, den, P );*

*[K, poles] = rlocf ind(sys, P );*

**bode** – computes the magnitude (absolute value) and phase (degrees) of a system evaluated on the jω axis. If no frequency vector is provided as an input argument, MATLAB selects a set of frequency values. If no output arguments are specified, the Bode plots are automatically made. If output arguments are specified, no plots are made. Specifying a frequency vector and output

arguments, the syntax for the function in transfer function and in “system” formats are:

*[mag, ph] = bode(num, den, w);*

*[mag, ph] = bode(sys, w);*

**margin** – computes the following measures of relative stability based on the frequency response of a system: gain margin (Gm), phase margin (Pm), phase crossover frequency (Wcg), gain crossover frequency (Wcp). These measures

provide information about how much perturbation to a system can be tolerated without becoming unstable and are often used as design specifications. If no frequency vector is included as an input argument, the values are computed

analytically from the transfer function. If a frequency vector is included, the values are obtained by searching the magnitude and phase arrays at those frequencies. If no output arguments are specified, Bode plots are made with the gain and phase margins shown on the plots. The syntax for the function in transfer function and in “system” formats are:

*[Gm, P m, W cg, W cp] = margin(num, den);*

*[Gm, P m, W cg, W cp] = margin(sys);*

*[Gm, P m, W cg, W cp] = margin(mag, ph, w);*

**nyquist** – computes the real and imaginary components of the frequency response of a system (rather than magnitude and phase). A frequency vector is an optional input argument. If no output arguments are specified, a plot of the imaginary part vs. the real part of the frequency response is plotted, and the s = −1 + j0 point is indicated on the plot. If output arguments are specified, the real and imaginary parts are returned, and no plot is made. The syntax for the function in transfer function and in “system” formats are:

*[re, im] = nyquist(num, den, w);*

*[re, im] = nyquist(sys, w);*

**step** – computes the unit step response for a system. A time vector is an optional input argument. The vector of values of the step response is an optional output argument. If no output argument is specified, a plot of the response is made. The syntax for the function in transfer function and in “system” formats are:

*c = step(num, den, t);*

*c = step(sys, t);*

If you have learned the basics then please move on to the next Post.