I'm using Mathematica v12.3 student edition, running on Windows 10 Home (AMD Ryzen 5 4500U with Radeon Graphics 2.38 GHz).

I'm trying to get a Bode plot of an example function. I try to do it with the BodePlot function, to compare it with the result I obtained "directly" (meaning by calculating 20*Log10[Abs[..]] and plotting the results with LogLinearPlot).

function = TransferFunctionModel[1000/(1 + s/10), s];
functionF[f_] := 1000/(1 + (2 Pi I f)/10)

Show[BodePlot[function[I 2 Pi f], {f, 0.1, 10}, PlotStyle -> Red, 
GridLines -> Automatic, FrameStyle -> Black, 
FrameLabel -> {{"Frequenza [Hz]", 
   "Guadagno [dB]"}, {"Frequenza [Hz]", "Fase[\[Degree]]"}}, 
ImageSize -> Large][[1]][[1]],LogLinearPlot[20 *Log10[Abs[functionF[f]]], {f, 0.1, 10},PlotStyle -> Green, GridLines -> Automatic, FrameStyle -> Black, FrameLabel -> {{"Frequenza [rad Hz]", 
 "Guadagno [dB]"}, {"Frequenza [rad Hz]", "Fase[\[Degree]]"}}, ImageSize -> Large]]

comparison between the output of BodePlot and the manual calculation

The two graphs displayed above are different; I'm pretty sure, though, that what is being calculated with BodePlot (the magnitude graph) is 20*Log10 [Abs[ ...something]].

What am I missing?

  • $\begingroup$ Added control-systems tag. $\endgroup$
    – Cassini
    Nov 7 '21 at 15:00

Your understanding of what BodePlot (with the default ScalingFunctions->{Automatic,"dB"}) computes is correct.

However, unfortunately, it 'hijacks' the Ticks attribute of plot-related functions to display it with the x-axis you see. As such, when you combine it with LogLinearPlot which itself uses a transformation function for its axes - they don't line up.

Here's a workaround/demonstration these are indeed identical by extracting the points from BodePlot:

functionF[f_] := 1000/(1 + (2 Pi I f)/10)
functionDB[f_] := 20 Log10[Abs[functionF[f]]]

bodePlot = BodePlot[functionF[f], {f, 0.1, 10}, PlotLayout -> "Magnitude"];
extractedBodePoints = Cases[bodePlot, Line[pts__] :> pts, Infinity][[1]];
extractedBodePoints = MapAt[10^# &, extractedBodePoints, {All, 1}];

equallySpacedFrequencyPoints = Power[10., Subdivide[-1, 1, 100]];
manualPoints = Thread[{equallySpacedFrequencyPoints,functionDB /@ equallySpacedFrequencyPoints}];

ListLogLinearPlot[{extractedBodePoints, manualPoints}, Joined -> True,PlotStyle -> {Red, Directive[Blue, Dashed]}]

enter image description here

  • $\begingroup$ Ah, all clear. Thank you so much! $\endgroup$
    – Merro
    Nov 7 '21 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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