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

7 ビュー (過去 30 日間)
Martin Sulcan 2022 年 1 月 26 日

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.

サインインしてコメントする。

### 採用された回答

Star Strider 2022 年 1 月 26 日
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])
g1 = 1.529e-08 --------------- 4.859e-15 s + 1 Continuous-time transfer function.
[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
y1 = 113×1
1.0e+00 * 0 1.341858259149421e-09 2.565915825616636e-09 3.682514330570055e-09 4.701087521423007e-09 5.630240964242317e-09 6.477824749144440e-09 7.250999812941425e-09 7.956298439373388e-09 8.599679448072640e-09
t1 = 113×1
1.0e+00 * 0 4.464285714285715e-16 8.928571428571430e-16 1.339285714285715e-15 1.785714285714286e-15 2.232142857142857e-15 2.678571428571429e-15 3.125000000000000e-15 3.571428571428572e-15 4.017857142857144e-15
figure
plot(t1,y1,'.-')
grid
[y2,t2] = step(g1,0.3) % Completely Loses Detail
y2 = 50001×1
1.0e+00 * 0 1.528500000000000e-08 1.528500000000000e-08 1.528500000000000e-08 1.528500000000000e-08 1.528500000000000e-08 1.528500000000000e-08 1.528500000000000e-08 1.528500000000000e-08 1.528500000000000e-08
t2 = 50001×1
1.0e+00 * 0 6.000000000000000e-06 1.200000000000000e-05 1.800000000000000e-05 2.400000000000000e-05 3.000000000000000e-05 3.600000000000000e-05 4.200000000000000e-05 4.800000000000000e-05 5.400000000000000e-05
figure
plot(t2,y2,'.-')
grid
.

サインインしてコメントする。

### その他の回答 (1 件)

Star Strider 2022 年 1 月 26 日
It may not be the desired result (I have no way of knowing what that is), however it appears to be exactly what step was asked to do. In the top plot image, note that the time goes from 0 to seconds. The step response reaches in about seconds, and maintains that value forever. The lower plot image (that goes from 0 to 3 seconds) simply reinforces that observation.
##### 5 件のコメント表示非表示 4 件の古いコメント
Paul 2022 年 1 月 26 日
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])
g1 = 1.529e-08 --------------- 4.859e-15 s + 1 Continuous-time transfer function.
[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)
ans = 1.5285e-08
This result obtains becuase of how lsim() discretizes g1
g1d = c2d(g1,tt2(2),'zoh')
g1d = 1.529e-08 --------- z Sample time: 0.0012048 seconds Discrete-time transfer function.
g1d.num
ans = 1×1 cell array
{[0 1.5285e-08]}
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)

サインインしてコメントする。

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by