How to I plot Laplace transfer function characteristics using the symbolic toolbox?
118 views (last 30 days)
Show older comments
Rogier Reerink
on 19 May 2020
Commented: Andrew Krill
on 19 Jun 2022
Hi there,
I'd like to be able to use the symbolic toolbox for plotting the amplitude and phase response of a transfer function in the Laplace domain. Reason is because I find symbolic functions to keep my work neat and easily readable.
I've tried plotting the transfer functions' amp and phase characteristics using the following piece of code. Transfer function H describes a simple passive RC low pass filter where R*C = 0.001 in Vx = Vy + R*C*Vy*s.
syms s;
H = 1/(0.001*s+1);
figure; fplot(abs(H), [0 100000]);
figure; fplot(angle(H), [0 100000]);
I would expect the phase shift between Vy and Vx to go from 0 to -pi/2 (or -90 deg), as in the bode plot below:
bode([0 1], [0.001 1]);
However, when plotting the angle with fplot I see no phase shift:
fplot(angle(H), [0 100000]);
I'd be glad if anyone could explain to me why bode and fplot give different results.
Thanks in advance!
0 Comments
Accepted Answer
Star Strider
on 19 May 2020
Here, ‘s’ needs to be complex:
syms s;
H = 1/(0.001*1j*s+1);
figure; fplot(20*log10(abs(H)), [0 100000]);
% set(gca, 'XScale','log')
figure; fplot(angle(H), [0 100000]);
% set(gca, 'XScale','log')
For some reason, setting the 'XScale' to 'log' (so that it matches the bode plot) fails for fplot plots. I will experiment with that and post back if I can figure out a way to get it to work.
3 Comments
Star Strider
on 19 May 2020
As always, my pleasure!
Symbolic variables are ‘complex’ by definition, however by defaault the imaginary parts are equal to 0, making them real. I set ‘s’ to be purely imaginary in my code.
I also had no problems creating logarithmic x-axis (and y-axis) scaling, however I could not get it to work correctly when I converted ‘H’ to decibels and plotted the y-axis linearly after the transformation to dB, with logarithmic x-axis scaling. That is what I wanted to do, and could not.
Andrew Krill
on 19 Jun 2022
Oh man, this entire thread was really helpful.
Thing I noticed,
figure; fplot(20*log10(abs(H)), [0 100000]);
Doesn't work, because log(0) is undefined.
figure; fplot(20*log10(abs(H)), [1 100000]);
Worked just fine.
More Answers (0)
See Also
Categories
Find more on Plot Customization 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!