# Unable to plot transfer function properly by using step(tf,array)

9 views (last 30 days)

Show older comments

Hello,

I have a transfer function which I want to plot but the final plot is not representative of said TF.

This is step(g1), where g1 is my transfer function. That is working properly.

Now I want to plot g1 in correlation to my variable "tt", which is a array of values. tt=0:0.0074:0.3;

When I use command step(g1,tt), I get the following result, which is not what I wanted.

I am not sure if my question was clear but I dont know how to make sure that step(g1,tt) is the same curve as my transfer function.

Thank you a lot for your help.

##### 0 Comments

### Accepted Answer

Star Strider
on 26 Jan 2022

I do not usually post multiple answers to the same question, however my original answer is in the process of being sabotaged, so I am posting my last comment to it as a separate answer here:

—————

There is an easy (and creative) work-around for that —

K=1.5285e-08;

Tp=4.8586e-15;

g1=tf(K,[Tp 1])

[y1,tt1] = step(g1);

tt2 = linspace(tt1(end), 0.3, 250);

u2 = ones(size(tt2));

y2 = lsim(g1,u2,tt2);

y2(1) = y2(2);

figure

plot(tt1, y1, '-b', tt2, y2, '-b')

figure

plot(tt1, y1, '-b', tt2, y2, '-b')

xlim([0 4.4E-14])

figure

semilogx(tt1, y1, '-b', tt2, y2, '-b')

So, it maintains the original initial values and detail, and appends the subsequent values.

EDIT — (26 Jan 2022 at 19:42)

I gave some more thought to this with respect to defining the 'tFinal' value argument to both step and stepplot. (Those results were essentially the same.) The step function simulates the system based on system characteristics, and chooses the time intervals accordingly. The problem with choosing a 'tFinal' value of 0.3 is that the plot then loses all the detail necessary to define the initial transient response. The ‘t2’ interval in the second plot is , while the initial transient response is complete by , as demonstrated by the first step call that produced ‘t1’ and ‘y1’.

The only way to depict everything and show all the detail is to calculate the two responses separately (as I did above) and plot them together. A time vector (created by linspace) that produces the correct time resolution and extends to 0.3 seconds requires on the order of elements or bits, exceeding the available computer memory, and may take a while to calculate even if the memory were adequate.

It is simply easier to calculate them separately (and correctly, as I did above), and then splice them together.

format longE

[y1,t1] = step(g1,5E-14) % Preserves Initial Detail

figure

plot(t1,y1,'.-')

grid

[y2,t2] = step(g1,0.3) % Completely Loses Detail

figure

plot(t2,y2,'.-')

grid

.

##### 0 Comments

### More Answers (1)

Star Strider
on 26 Jan 2022

##### 5 Comments

Paul
on 26 Jan 2022

Disclaimer: I have no idea what the OP is asking for, so don't know whether or not this approach answers the Question.

Having said that, I'd be concerned about using lsim() on a continuous system with time constant on the order of 1e-15 with an lsim time step on the order of 1e-3. Also, according to the doc the first element of the time vector input to lsim should be t(1) = 0, whereas tt2(1) ~= 0.

If we look carefully at what's happening here

K=1.5285e-08;

Tp=4.8586e-15;

g1=tf(K,[Tp 1])

[y1,tt1] = step(g1);

tt2 = linspace(tt1(end), 0.3, 250);

u2 = ones(size(tt2));

y2 = lsim(g1,u2,tt2);

y2(1) = y2(2);

plot(diff(y2))

We see that y2 is constant and the value of that constant is

y2(1)

This result obtains becuase of how lsim() discretizes g1

g1d = c2d(g1,tt2(2),'zoh')

g1d.num

So output of lsim is just a scaled and one sampled delay of the constant input, which is why that line y2(1) = y2(2) is needed. But note that this approach results in exactly a flat response during tt2, and the disconituity at the transition from tt1 to tt2

figure

plot(tt1,y1,'b',tt2,y2,'r')

xlim([4e-14 tt1(end)+tt1(20)])

ylim([1.528085 1.5286]*1e-8)

So this plot could be developed w/o the second call to lsim()

figure

plot(tt1,y1,[tt1(end) 0.3],[y1(end) y1(end)])

figure

plot(tt1,y1,[tt1(end) 0.3],[y1(end) y1(end)])

xlim([4e-14 tt1(end)+tt1(20)])

ylim([1.528085 1.5286]*1e-8)

### See Also

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!