# [help] plotting transfer function on matlab

#### cupcake

Joined Sep 20, 2010
73
Hello, I did the experiment about open-loop step test, from the experiment, I got data to plot the unit step response, then the question ask me to fit a first-order plus dead-time model according Ziegler-Nichols step response method
Gp(s) = ($$\frac{Kp}{sT+1}$$ ) $$e^{-sL}$$ (sorry the delayed should go a slightly more upward) and then superimpose the unit step response from the estimated first-order plus dead-time model on the experiment.

I'm not quite sure how to do this using matlab, I meant the superimpose part.
from Gp(s) with unit step response input, I could find the y(s) and in time domain y(t)=Kp(1 - $$e^{(-t+L)/T}$$)*1(t-L)

I know we could use something called "hold on" or "hold off" in matlab, but when I tried to type in the formula of y(t). the errors come out.. can anyone advise please.

#### guitarguy12387

Joined Apr 10, 2008
359
Could ya post some code? It's a little hard to know what ya mean by the description.

#### shteii01

Joined Feb 19, 2010
4,644
Step 1. Define the range of s, in MatLab: s=0:0.01:3.14;
(0.01 is the increment, so you go 0, 0.01, 0.02, 0.03, etc.)

Step 2. Input formula of the transfer function, you need to know Kp, T, L. If you do not know values of Kp, T, and L, you are done. You are not going to plot anything. Do you have values for these three things?

Last edited:

#### cupcake

Joined Sep 20, 2010
73
I don't know the value of Kp, T and L, but I have 50 input data (for unit step) in 24.5 minutes range, from this.. I could plot unit step response graph.. could I just approximate the value of Kp, T and L from the reading...Kp is just a steady state gain, L is dead time, but what about T? I'm not quite sure.

#### shteii01

Joined Feb 19, 2010
4,644
I don't know the value of Kp, T and L, but I have 50 input data (for unit step) in 24.5 minutes range, from this.. I could plot unit step response graph.. could I just approximate the value of Kp, T and L from the reading...Kp is just a steady state gain, L is dead time, but what about T? I'm not quite sure.
There should be some formulas to approximate values of Kp, T and L. The only unknown should be the s.

#### t_n_k

Joined Mar 6, 2009
5,455
Check out Section3 in this paper - Figure 4 will be of interest.

#### Attachments

• 110.5 KB Views: 902
Last edited:

#### cupcake

Joined Sep 20, 2010
73
There should be some formulas to approximate values of Kp, T and L. The only unknown should be the s.
Check out Section3 in this paper - Figure 4 will be of interest.
ok, then from the pdf you gave me, I could approximate the value of Kp, T and L.. now, how do i superimpose this ziegler-nichols formula using mat lab? I don't know what code to use,do I plot in in time domain? or in s domain? and btw, I have the values of s (from the experiment reading).

#### shteii01

Joined Feb 19, 2010
4,644
ok, then from the pdf you gave me, I could approximate the value of Kp, T and L.. now, how do i superimpose this ziegler-nichols formula using mat lab? I don't know what code to use,do I plot in in time domain? or in s domain? and btw, I have the values of s (from the experiment reading).
In matlab, when you use plot, you can plot multiple functions. For example:
Define inputs for the first function:
x1=0:0.01:10;
Define first function:
y1=2*x1;

Define inputs of the second function:
x2=0:0.01:10
Define second function:
y2=x2-3;

Now bring them all together to plot:
plot(x1, y1, x2, y2);

Do you see what I did inside the prenticies of the plot command? MatLab will automatically plot the two functions on the same coordinate plane and keep track which values belong to which function. This way you can easily see how the two functions are similar or different from each other.

#### t_n_k

Joined Mar 6, 2009
5,455
If I understand Cupcake's dilemma it is in relation to handling plots of functions which include a time shift.

A 'simple' way around this is to recognize that the Z-N function is a first order delay with an ideal time shift.

To make the required comparison one would generate a time series pair array of the first order delay part and then apply a fixed time offset to the all the time components of the array. This could then be overlay-ed with the original experimental data for the purposes of comparison.

Another approach is to use the Pade approximation to the delay component of the Z-N 's' domain transfer function and then derive the 'approximate' time domain equivalent which could then be plotted without resort to applying the aforementioned time shift.

I don't use Matlab so I can't be of any help in relation to what relevant functions are included in the various toolboxes at your disposal.

#### cupcake

Joined Sep 20, 2010
73
-deleted-..........

Last edited:

#### cupcake

Joined Sep 20, 2010
73
In matlab, when you use plot, you can plot multiple functions. For example:
Define inputs for the first function:
x1=0:0.01:10;
Define first function:
y1=2*x1;

Define inputs of the second function:
x2=0:0.01:10
Define second function:
y2=x2-3;

Now bring them all together to plot:
plot(x1, y1, x2, y2);

Do you see what I did inside the prenticies of the plot command? MatLab will automatically plot the two functions on the same coordinate plane and keep track which values belong to which function. This way you can easily see how the two functions are similar or different from each other.
Ok, I will give a try, thanks
Btw, is there any matlab function/formula to calculate or find the area below the graph? I think I could find the Kp, L and T by using the method of area. But, I'm afraid if I'm calculating it manually, there will be an error

If I understand Cupcake's dilemma it is in relation to handling plots of functions which include a time shift.

A 'simple' way around this is to recognize that the Z-N function is a first order delay with an ideal time shift.

To make the required comparison one would generate a time series pair array of the first order delay part and then apply a fixed time offset to the all the time components of the array. This could then be overlay-ed with the original experimental data for the purposes of comparison.

Another approach is to use the Pade approximation to the delay component of the Z-N 's' domain transfer function and then derive the 'approximate' time domain equivalent which could then be plotted without resort to applying the aforementioned time shift.

I don't use Matlab so I can't be of any help in relation to what relevant functions are included in the various toolboxes at your disposal.
ok sir, from the pdf you gave me, i could estimate the value of Kp, L and T from the graph. for L and T, should they be in seconds or can be in minutes? I have my x-axis in minutes, so i shall convert them right?

#### cupcake

Joined Sep 20, 2010
73
I want to plot this y(t1)=kp*(1-e^(-t1-L)/T)*1(t1-L)
whereby Kp=0.258, L=0.565, and T=6.5 and t1 is time starting from 0 to 24.5 (in minutes)

I got this error message..
>> y1=kp*(1-exp((-t1-L))/T)*(-t1-L)
??? Error using ==> mtimes
Inner matrix dimensions must agree.

so, how should I type in the formula?