How to I plot Laplace transfer function characteristics using the symbolic toolbox?

118 次查看(过去 30 天)
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!

采纳的回答

Star Strider
Star Strider 2020-5-19
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 个评论
Star Strider
Star Strider 2020-5-19
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
Andrew Krill 2022-6-19
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Plot Customization 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by