Message Boards Message Boards

How to unwrap the Phase plot of BodePlot?

Posted 1 year ago

Hello,

a=s^2+1/L1+1/(L2*C1)
b=s^3+1/(L1*L2)*s^2+1/(L1*L2*C1)*s
a/b//Together
a/b/.{L1->1,L2->1,C1->1}
test=TransferFunctionModel[a/b/.{L1->1,L2->1,C1->1},s]
BodePlot[test,GridLines->Automatic,PlotRange->{Automatic,{-270,0}}]
GainPhaseMargins[test]

enter image description here

So, I want to unwrap the phase diagram of the Bode Plot. The Phase diagram of Bode Plot should look something like that after unwrapping:

enter image description here

I tried this (from https://reference.wolfram.com/applications/insydes/ReferenceManual/BodePlot.html) but does not function:

test=TransferFunctionModel[a/b/.{L1->1,L2->1,C1->1},s]
BodePlot[test,GridLines->Automatic,PlotRange->{Automatic,{-270,0}}, UnwrapPhase -> True]
GainPhaseMargins[test]

enter image description here

Thank you.

POSTED BY: Cornel B.
8 Replies

Which Mathematica are you using. The documentation you're showing is a very old package.

Check this doc: https://reference.wolfram.com/language/ref/BodePlot.html

Specifically the PhaseRange option.

POSTED BY: Sander Huisman
Posted 1 year ago

The documentation you're showing is a very old package.

Yes, it looks like older documentation, but that's all I found when I searched for UnwrapPhase for Bode Plot...

I'll also look at PhaseRange (I tried now quickly by putting PhaseRange -> {-Pi, Pi} (but also other combinations), but it didn't work for me so far...I didn't manage to find the right combination until now. If anyone has found a solution then it is welcome.

POSTED BY: Cornel B.

I might be wrong, but your jump is 180 degrees, so it is a fundamentally different jump than a phase-wrap which is 360 degrees.

POSTED BY: Sander Huisman
Posted 1 year ago

Other sugestions? So, i want to be able to change the Phase Plot of Bode Plot in following manner from (0, 360) degrees, (90, 450) degrees, (180, 540) degrees, and so on, i think that it is the idea (or at least something like that)

POSTED BY: Cornel B.

Cornel,

I have no experience with BodePlot[] whatsoever and so I do not know whether this unwrapping makes sense in this case. But anyway - here is a simple approach:

bpl = BodePlot[test, GridLines -> Automatic, PlotRange -> {Automatic, {-270, 0}}, PlotLayout -> "Phase"];
(* extracting point values from the plot: *)
pts0 = First@Cases[bpl, Line[pts__] :> pts, All];
(* "true" x-value: *)
pts = {10^#1, #2} & @@@ pts0;
{{xmin, xmax}, {ymin, ymax}} = MinMax /@ ({xVals, yVals} = Transpose[pts]);
xGrid = Flatten[Range[10] # & /@ PowerRange[xmin, xmax]];

For the unwrapping there is an elegant algorithm from @Peter Karpov in this discussion:

unWrap[\[Tau]_][a_] := a - \[Tau] Prepend[Accumulate[Round[Differences[a]/\[Tau]]], 0]

So - we get:

(* unwrapped result: *)
ptsUnWrapped = Transpose[{xVals, unWrap[ymax - ymin][yVals]}];
ListLinePlot[ptsUnWrapped, ScalingFunctions -> {"Log", None}, GridLines -> {xGrid, Automatic}, Frame -> True]

enter image description here

Does that help? Regards -- Henrik

POSTED BY: Henrik Schachner
Posted 1 year ago

Hi Henrik,

Thank you for your response.

POSTED BY: Cornel B.
Posted 1 year ago

I am looking also for other solutions If exists, more simpler more better.

POSTED BY: Cornel B.
Posted 1 year ago

It is wired because for what I saw until now it is not possible to do unwrapping of phase of bode plot inside the BodePlot[...] command in a more simple manner in Mathematica, and only way is to extract the points from the PhasePlot of BodePlot and then doing something like Henrik did, which is something not so straight forward, mainly if someone is a beginner. And we are talking here that this unwrapping of phase plot of bode plot is something that someone who deals with control systems and signal processing will encounter very often, therefore unwrapping of phase of bode plot I think it should have already taken into account and have been implemented by the developers of wolfram mathematica...

POSTED BY: Cornel B.
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract