5
$\begingroup$

When I use Mathematica to draw a bode plot, it always gives the precise version, like this:

BodePlot[(10 (s + 3))/(s (s + 2) (s^2 + s + 2))]

enter image description here

How can I draw the asymptotic version, the kind where 1/(1 + jw) is represented as a -20dB straight line but not a curve?

$\endgroup$
1
  • $\begingroup$ Could you provide an example? $\endgroup$
    – partial81
    Commented Jun 24, 2013 at 11:53

1 Answer 1

10
$\begingroup$

We can draw the asymptotes using Epilog. The frequencies of interest are the max and min values and the corner frequencies.

tfm = (10 (3 + s))/(s (2 + s) (2 + s + s^2));
minF = Log10[0.001];
maxF = Log10[100];
cF1 = Log10[Sqrt[2]];
cF2 = Log10[2];
cF3 = Log10[3];
xcoords = {minF, cF1, cF2, cF3, maxF};

The magnitude at the lowest frequency.

mag0 = 20 Log10@Abs[tfm /. s -> I 0.001];

The magnitudes computed at the other frequencies of interest based on the slopes of the asymptotes. For example, between $minF$ and $cF1$ the slope is -20 db/decade.

ls = {mag0, -20 (cF1 - minF), -60 (cF2 - cF1), -80 (cF3 - 
  cF2), -60 (maxF - cF3)};
ycoords = FoldList[Plus, ls[[1]], ls[[2 ;; -1]]];

Finally render the plot.

BodePlot[tfm, Epilog -> {{Dashed, Line[Thread[{xcoords, ycoords}]]}, {}}][[1, 1, 1]]

enter image description here

The same process repeated for 10/(s+1).

tfm = 10/(s + 1);
minF = Log10[0.001];
maxF = Log10[100];
cF1 = Log10[1];
xcoords = {minF, cF1, maxF};
mag0 = 20 Log10@Abs[tfm /. s -> I 0.001];
ls = {mag0, 0, -20 (maxF - cF1)};
ycoords = FoldList[Plus, ls[[1]], ls[[2 ;; -1]]];
BodePlot[tfm, Epilog -> {{Dashed, Line[Thread[{xcoords, ycoords}]]}, {}}][[1,1,1]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you very much! maybe I could try to convert this to a more general function. Matlab's already got bode_as() by Valerio Scordamaglia, though. But Mathematica's results look much better. $\endgroup$
    – Lewen
    Commented Jun 25, 2013 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.