How to extract only data points from BodePlot chart?

I am trying to fix part of the BodePlot phase portion as it does not wrap correctly. And there is no option that I can use to report this.

So, instead of doing the full storyline myself (I can do it if I need to), I'm thinking of creating a BodePlot, capturing data points, wrapping data (as soon as I get x, y, the rest is easy), then I need to put a new list of points back to the chart, and then use Show to display it.

The part I'm stuck on is extracting points from FullForm. I cannot get the correct template for this.

This is what I'm going for:

hz=z/(z^2-z+0.3); tf=TransferFunctionModel[hz,z,SamplingPeriod->2]; phasePlot=BodePlot[tf,{0.001,2 Pi}, ScalingFunctions->{Automatic,{"Linear","Degree"}},PlotLayout->"List"][[2]] 

enter image description here

You see how it does not wrap around 180 degrees. In dsp, flow around Bode phases is more common. Here's how it should look:

enter image description here

So this is what I did:

  FullForm[phasePlot] Graphics[List[ List[List[], List[], List[Hue[0.67, 0.6, 0.6], Line[List[List[0.0010000243495554542, -0.2673870119911639], List[0.0013659538057574799, -0.36521403872250247], List[0.0017318832619595053, -0.46304207336414027], .... 

I see the data there (x, y) But how to get it out? I tried this:

  Cases[FullForm[phasePlot], List[x_, y_] -> {x, y}, Infinity]; 

But the above coincidences are in addition to the list of items, other things that I don't need. I tried many other things, but I can not get only a list of points.

I was wondering if someone knows how to get only points (x, y) from the above graph. Is there a better way to do this other than using FullForm?

thanks

Update:

I just found a post here that shows how to extract data from the plot. So I used it:

  points = Cases[ Normal@phasePlot , Line[pts_] -> pts, Infinity] 
+6
source share
2 answers

You can try nesting replacement rules, for example

 phase2 = phasePlot /. Line[a_] :> (Line[a] /. {x_?NumericQ, y_?NumericQ} :> {x, Mod[y, 360, -180]}); Show[phase2, PlotRange -> {Automatic, {-180, 180}}, FrameTicks -> Automatic] 

Conclusion:

Bodeplot with wrapping

+6
source

The list you are looking for will be wrapped in Line[] , and this seems to be the only case in your plot. So you can use

 Cases[phasePlot, Line[list_] :> list, Infinity] 

Edit: When I sent my answer, the page refreshed and I saw that you were faced with exactly what I suggested. In any case, I will leave my answer.

Edit2: Sabolics indicated that FullForm[] has no effect, so I removed it from the original post.

+3
source

Source: https://habr.com/ru/post/893666/


All Articles