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

조회 수: 32(최근 30일)
Rogier Reerink 19 May 2020
댓글: Star Strider 19 May 2020
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.

### 채택된 답변

Star Strider 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.

#### 댓글 수: 2

Rogier Reerink 19 May 2020
Thank you! I find the need to convert 's' to a complex number a bit strange, since the Symbolic Toolbox states that sym variables are complex by default. But it did solve the problem.
I found a post that answers how to fplot logarithmically by starting the plot at a value (slightly) greater than 0 and setting the XScale to log as your answer suggests.
Star Strider 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.