3
$\begingroup$

I'm trying to do a Bode plot in 3D for the function below, but there is no built-in function for that.

How can I do that? It would also be nice if you could use a mesh to make it easier to see.

tf = s^2/(s^2 + 2 s + 5) 

The shape of the plot may not be same as in the image, but it is a 3D object like that.

In a 2D Bode plot, s is replaced with i*w and then the magnitude/modulus of the function with frequency w is plotted. However, in a 3D plot you replace s with σ + i*w and plot the magnitude of the function with a different σ and w.

tf = s^2/(s^2 + 2 s + 5); mag = Abs[ComplexExpand[tf /. s -> \[Sigma] + I*w]]; Plot3D[mag, {\[Sigma], -1000, 1000}, {w, -100, 100}, ScalingFunctions -> {None, None, "Log"}] 

Enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ what is a Bode plot, mathematically? the wikipedia article is a bit hard to parse for someone without the EE background. (hopefully someone who already knows comes along, but in the event they don't...) $\endgroup$ Commented Jun 2, 2021 at 23:00
  • $\begingroup$ In 2D bode plot, they replace s with i*w and then plot the magnitude/modulus of the function with frequency w. However, in 3D plot you should replace s with σ + i*w and plot the maginitude of the function with different σ and w. $\endgroup$ Commented Jun 2, 2021 at 23:04
  • $\begingroup$ Like this?: ComplexPlot3D[tf, {s, -2 - 3 I, 0 + 3 I}, AxesLabel -> {\[Sigma], I*\[Omega]}, BoxRatios -> {2, 3, 1}] $\endgroup$ Commented Jun 2, 2021 at 23:18
  • $\begingroup$ @MichaelE2 that is nice. Adding mesh may be easier to see though. How can I make a bold red curve in the intersection of the graph and the plane forming by σ = 0 and w? $\endgroup$ Commented Jun 2, 2021 at 23:22

2 Answers 2

6
$\begingroup$

May be like this.

tf = s^2/(s^2 + 2 s + 5); mag = Abs[ComplexExpand[tf /. s -> σ + I*w]]; SetOptions[Plot3D, BoundaryStyle -> None, PlotRange -> {0, 8}, ViewPoint -> {2.54, 1.27, 1.8}, BoxRatios -> {1, 1, 1}, ClippingStyle -> Yellow]; fig1 = Plot3D[mag, {σ, -2, 0}, {w, -3, 3}, MeshFunctions -> {#3 &}, MeshShading -> {Yellow, Pink, Brown, Gray, Blue, Orange, Purple, Cyan}, Mesh -> {20, 20, 8}]; fig2 = Plot3D[mag, {σ, -2, 1}, {w, -3, 3}, MeshFunctions -> {#1 &, #2 &}, MeshShading -> None, PlotStyle -> None, Mesh -> {20, 20}]; fig3 = Plot3D[mag, {σ, -2, 1}, {w, -3, 3}, MeshFunctions -> {#1 &}, Mesh -> {{0}}, PlotStyle -> None, MeshStyle -> {Thick, Red}]; Show[fig1, fig2, fig3] 

enter image description here

$\endgroup$
1
  • $\begingroup$ the plot is very nice $\endgroup$ Commented Jun 3, 2021 at 3:50
6
$\begingroup$
Clear["Global`*"] tf = s^2/(s^2 + 2 s + 5); Manipulate[ Show[ ComplexPlot3D[tf, {s, -2 - 3 I, 1/4 + 3 I}, MeshFunctions -> mf, MeshStyle -> {Black, Darker[Green]}, Mesh -> 9, PlotPoints -> 50, MaxRecursion -> 5, PlotLegends -> BarLegend[Automatic, LegendLabel -> HoldForm[Arg[tf]]], PlotRange -> {0, 10}], ComplexPlot3D[tf, {s, -2 - 3 I, 1 + 3 I}, PlotStyle -> Opacity[0], MeshFunctions -> {Re[#1] &}, Mesh -> {{0.}}, MeshStyle -> {{Red, Thick}}], AxesLabel -> (Style[#, 14, Bold] & /@ {σ, ω, "|tf|"}), BoxRatios -> {2, 3, 1}, SphericalRegion -> True, ImagePadding -> 30], {{mf, {Abs[#2] & , Arg[#2 ] & }, "MeshFunctions"}, {{Abs[#2] & , Arg[#2 ] & } -> {"|tf|", "arg(tf)"}, {Re[#2] &, Im[#2] &} -> {"Re(tf)", "Im(tf)"}, {Re[#1] &, Im[#1] &} -> {"Re(s)", "Im(s)"}}, ControlType -> PopupMenu}] 

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.