Output of a transfer function with input
60 views (last 30 days)
Show older comments
Hello there.
I have a transfer function:
M=2;
b=14;
q=20;
num=[1];
G=tf(num,[M b q])
And a input: 2*(heaviside(t)-heaviside(t-2))
Applying laplace: 2/s - (2*exp(-2*s))/s
How do I find out the tf output using the input I just mentioned?
I think I might use lsim, but I have no idea how to.
Thanks
0 Comments
Answers (2)
Paul
on 13 Feb 2023
Moved: Walter Roberson
on 14 Feb 2023
The HeavisideAtOrigin should be 1 when using lsim
M=2;
b=14;
q=20;
num=[1];
G=tf(num,[M b q]);
syms t
F = 2*(heaviside(t)-heaviside(t-2));
T = linspace(0, 3);
sympref('HeavisideAtOrigin', 0);
u = double(subs(F, t, T));
y1 = lsim(G, u, T);
sympref('HeavisideAtOrigin', 1);
u = double(subs(F, t, T));
y2 = lsim(G, u, T);
% exact answer
syms s
y3 = ilaplace(1/(M*s^2 + b*s + q)*(2/s - 2*exp(-2*s)/s),s,t);
y3 = double(subs(y3,t,T)).';
plot(T,y1,T,y2,T,y3,'o')
legend('HeavisdeOrigin = 0','HeavisdeOrigin = 1','exact','Location','South')
6 Comments
Paul
on 15 Feb 2023
Edited: Paul
on 15 Feb 2023
We can also examine some other approaches.
Let's consider the case with the proper transfer function so we can see the discontinuity. And we'll make the delay of the second step a not-nice value.
M = 2;
b = 14;
q = 20;
num = [.03 0 1];
G = tf(num,[M b q]);
delay = 1.96;
First, the exact symbolic solution
syms s t
ysym = ilaplace((0.03*s^2 + 1)/(M*s^2 + b*s + q)*(2/s - 2*exp(-delay*s)/s),s,t);
One option that comes to mind would be as follows
tempsys = G - tf(G.num{:},G.den{:},'InputDelay',delay);
[y1,t1] = step(tempsys,5); % allow the CST to pick the time vector
y1 = 2*y1; % gain of 2 on the input
figure
fplot(ysym,[0 5],'-o')
hold on
plot(t1,y1),grid
At a a distance, that seems pretty good. Zoom in
copyobj(gca,figure)
xlim([1.85 2.1])
We see that the autogenerated time vector from lsim does not include a point at the delay time (I was surprised by this), but lsim does seem to be computing a very accurate solution on both sides of the discontinuity.
tempsys has an internal delay
hasInternalDelay(tempsys)
I think I've seen somewhere in the doc that lsim handles systems with internal delays differently than systems without internal delays. I wouldn't be surprised if the solution was computed accurately at the delay time, even if the returned solution doesn't include that point. But that's just speculation on my part.
If one were so inclined to really catch the effect of the step at the delay time, we can use the properties of superposition and time invariance.
First, define a time vector that has a point exactly (as close as we can get) at the delay time
t2 = linspace(0,delay,150);
t2 = [t2, (delay+t2(2)):t2(2):5];
Compute the step response with the gain
ystep = 2*step(G,t2);
They delayed step response is
ystepdelayed = [zeros(149,1) ; ystep(1:(numel(t2)-149))];
The total response is the difference between the step and the delayed step.
y2 = ystep - ystepdelayed;
Plot and zoom
figure
fplot(ysym,[0 5],'-o')
hold on
plot(t2,y2),grid
copyobj(gca,figure)
xlim([1.85 2.1])
Now y2 has a point at the delay time that matches the sym response at t = delay+.
We can manually add another point into y2 and t2 for the value at t = delay- to get a clean step at the delay
t3 = [t2(1:149) , delay, t2(150:end)];
y3 = [y2(1:149) ; ystep(150); y2(150:end)];
figure
fplot(ysym,[0 5],'-o')
hold on
plot(t3,y3),grid
copyobj(gca,figure)
xlim([1.85 2.1])
Walter Roberson
on 13 Feb 2023
M=2;
b=14;
q=20;
num=[1];
G=tf(num,[M b q])
syms t
F = 2*(heaviside(t)-heaviside(t-2));
T = linspace(0, 3);
sympref('HeavisideAtOrigin', 0);
u = double(subs(F, t, T));
plot(T, u);
hold on
lsim(G, u, T); xlim([-.1 3.1]); ylim([-0.1 2.1]);
0 Comments
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!