cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Discrepancy in Bode Plot: Phase - Frequency Plot -> Mathcad vs Matlab

Cornel
19-Tanzanite

Discrepancy in Bode Plot: Phase - Frequency Plot -> Mathcad vs Matlab

Hello Dear Friends,

How can it be solved that the phase - frequency graph of the bode diagram in Mathcad looks like the phase - frequency graph of the bode diagram in Matlab?

CornelBejan_0-1613214031741.png

CornelBejan_1-1613214067968.png

CornelBejan_2-1613214089823.png

 

Calculations and graphs were made in Mathcad 15.
Attached is the Mathcad 15 file with the details.

Thank you.
Best regards.

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:Cornel)

Matlab's bode somehow finds a way to examine the transfer function and so to determine the best range the phase should be placed at.

Mathcads arg function doesn't know anything about the transfer function - its simply receives a complex number and returns its argument, the angle, and this will always be in the range (-pi; +pi]. This range is as good as any other and its similar to the atan2 function. And thats also the reason you get the jump up to +180° step when the angle would go below -180°. "arg" would never give you an angle below (or equal to) -180°.

 

Easiest solution is to write an alternative "arg" function which returns the angle in a different 2 pi interval.

Werner_E_0-1613218601733.png

Put it at the top of the sheet (maybe in a collapsed region).

Or you may use an all-purpose "Arg" function where you can choose the start of the 2pi interval as its second argument:

Werner_E_1-1613218709691.png

The drawback of these simple solutions are, that you have to determine and chose the range for the angle manually yourself and that they only work OK as long as the range of angle values does not exceed a 2 pi interval.

 

View solution in original post

49 REPLIES 49
Werner_E
25-Diamond I
(To:Cornel)

Matlab's bode somehow finds a way to examine the transfer function and so to determine the best range the phase should be placed at.

Mathcads arg function doesn't know anything about the transfer function - its simply receives a complex number and returns its argument, the angle, and this will always be in the range (-pi; +pi]. This range is as good as any other and its similar to the atan2 function. And thats also the reason you get the jump up to +180° step when the angle would go below -180°. "arg" would never give you an angle below (or equal to) -180°.

 

Easiest solution is to write an alternative "arg" function which returns the angle in a different 2 pi interval.

Werner_E_0-1613218601733.png

Put it at the top of the sheet (maybe in a collapsed region).

Or you may use an all-purpose "Arg" function where you can choose the start of the 2pi interval as its second argument:

Werner_E_1-1613218709691.png

The drawback of these simple solutions are, that you have to determine and chose the range for the angle manually yourself and that they only work OK as long as the range of angle values does not exceed a 2 pi interval.

 

Cornel
19-Tanzanite
(To:Werner_E)

Ok.

Thank you very much for your response (for both comments/answers/suggestions).

Thank you.
Best regards.

Werner_E
25-Diamond I
(To:Cornel)

I just noticed that most of what i said above was already covered in a thread of yours with a similar question

In this detailed discussion I provided a "bode" function which you could have used - why didn't you?

https://community.ptc.com/t5/PTC-Mathcad/Phase-Plot-Error-Bode-Diagrams/m-p/686828/highlight/true#M191806

 

Werner_E_0-1613219790007.png

Furthermore later in the very same discussion the "phasecor" function was brought to my/our attention and it could also help with the problem of discontinuities in bode plots:

Werner_E_1-1613220421977.png

 

 

 

 

ttokoro
20-Turquoise
(To:Werner_E)

image.pngimage.png

Cornel
19-Tanzanite
(To:Werner_E)

@Werner_E , @Fred_Kohlhepp , @LucMeekes , @ValeryOchkov 

Is there any way to result in the corresponding value of the phase margin as shown in the graph, but using the above functions (or others, is not a problem), and not looking at the graph and reading from it???

CornelBejan_1-1613319065615.png

Bode Diagram: Magnitude - Frequency Plot:

CornelBejan_2-1613319099973.png

CornelBejan_6-1613319323929.png

 

CornelBejan_9-1613320058587.png

 

CornelBejan_10-1613320101235.png

 

CornelBejan_7-1613319835456.png

 

CornelBejan_8-1613319921418.png
Calculations and graphs were made in Mathcad 15.
Attached is the Mathcad 15 file with the details.

Thank you.
Best regards.

 

 

 

Werner_E
25-Diamond I
(To:Cornel)

Werner_E_1-1613323448233.png

 

Werner_E_2-1613323488886.png

 

Werner_E_3-1613323532825.png

 

Did you notice that you can also plot the magnitude using the results of "bode". You may consider modifying "bode" to do the log and times 20 itself.

Werner_E_4-1613323656258.png

Werner_E_5-1613324212986.png

I can image that you are looking for something like this:

Werner_E_6-1613325601801.png

 

 

 

 

Werner_E
25-Diamond I
(To:Werner_E)

Not able to edit my previous post.

Here is the MC15 file attached.

I also added a function to do the job - may come handy.

Werner_E_0-1613327144805.png

I wasn't sure about the adding of 180° which you did, so I did without it. You may add it in the function if thats more appropriate.

Cornel
19-Tanzanite
(To:Werner_E)

"I wasn't sure about the adding of 180° which you did, so I did without it. You may add it in the function if thats more appropriate."

Is used in control engineering for system stability.

CornelBejan_1-1613329058829.png

You can read more in this article:
https://www.electrical4u.com/bode-plot-gain-margin-phase-margin/

 

Phase Margin Formula:
The formula for Phase Margin (PM) can be expressed as:

CornelBejan_3-1613329222303.png

Where CornelBejan_1-1613329501025.png is the phase lag (a number less than 0). This is the phase as read from the vertical axis of the phase plot at the gain crossover frequency.




 

Werner_E
25-Diamond I
(To:Cornel)

So I guess you should add the 180° already in the function, in case you decide to use it.

Cornel
19-Tanzanite
(To:Werner_E)

Ok.

If I encounter any more "adventures" in the future I will post.

Until then... thanks for suggestions, answers, and time.

Thank you.
Best regards.

Cornel
19-Tanzanite
(To:Werner_E)

@Werner_E 
First of all, thank you for your support in creating those functions, your time, and your suggestions.

I came up with a new idea/challenge (as I said in the previous message, I'm coming back :))) to which I still can't find an answer/solution.
Maybe you have a solution/idea.

CornelBejan_0-1613410232020.png

 

I would like to find out using a function, something, from the bode diagram of the phase - frequency graph, the frequency at which the graph cuts the value of -180 degrees, and not looking at the graph and reading from it.

 

CornelBejan_1-1613410663054.png


I can't find the right option/variant.

Could you take a look?

Than you.
Best regards.

 

 

Cornel
19-Tanzanite
(To:Cornel)

And then to find gain margin (GM) as in the chart above, from a previous comment.

CornelBejan_2-1613411839272.png

 

This is the final idea I want to reach, to find an answer.

LucMeekes
23-Emerald III
(To:Cornel)

To find the phase crossover, how about:

LucMeekes_0-1613414881222.png

Instead of finding the phase 180°, turn the phase function and search for 0°.

And of course, to find the 0 dB in the gain, search for gain=1:

LucMeekes_0-1613415162294.png

 

Success!

Luc

Cornel
19-Tanzanite
(To:LucMeekes)

Thank you.

LucMeekes
23-Emerald III
(To:Cornel)

So your margins can be easily calculated, without a phase correction function:

LucMeekes_0-1613424538482.png

(Note: this was on the function:

LucMeekes_1-1613424570087.png

with

LucMeekes_2-1613424588762.png

)

 

Success!
Luc

LucMeekes
23-Emerald III
(To:LucMeekes)

Of course this must be corrected (function parameter is H, not Tc, so function should use H, not Tc):

LucMeekes_0-1613488024553.png

 

Sorry for any inconvenience caused.

Luc

Cornel
19-Tanzanite
(To:LucMeekes)

@Werner_E@LucMeekes@Fred_Kohlhepp@ttokoro@-MFra- 

As far as I know, so far, I think the next option seems to be good (inspired by @LucMeekes  suggestion:))):

CornelBejan_0-1613845430448.png

For testing let's take the following example:
The Plant Transfer Function is:

CornelBejan_1-1613846778991.png

CornelBejan_2-1613846902317.png

 

CornelBejan_4-1613847185495.png

 

CornelBejan_5-1613847206238.png

 

The fact that the function does not return a value for:

CornelBejan_6-1613847285276.png

CornelBejan_7-1613847299030.png

CornelBejan_8-1613847312803.png

 

is due to the fact that in the phase-frequency graph from the bode characteristic, this graph does not cut the -180 degree axis, which translates into:

CornelBejan_9-1613847544433.png

CornelBejan_10-1613847557619.png

CornelBejan_11-1613847574276.png

 

Which sounds good, that is, okay with what it looks like on the graphs.

 

Now if you have any idea if it can be realized that when the phase-frequency characteristic from the bode diagram does not cut the -180 degree axis, that the three values ​​directly return infinite values, and not be red as shown above?

Even so, if you can't, it's fine, very good because I know what that means now. :))


Matlab verification:

CornelBejan_12-1613848049881.png

 

CornelBejan_13-1613848067811.png

 

CornelBejan_14-1613848094016.png


Thank you.
Best regards.

Werner_E
25-Diamond I
(To:Cornel)

Hmmm ...

Werner_E_0-1613415146018.png

 

Fred_Kohlhepp
23-Emerald I
(To:Cornel)

One feeble attempt (Prime 4)

Cornel
19-Tanzanite
(To:Fred_Kohlhepp)

I can't open the Mathcad file (Prime 4).
Can you put a picture, something?

Fred_Kohlhepp
23-Emerald I
(To:Cornel)

Can you put a picture, something?

 

Phase margin plot

Fred_Kohlhepp_0-1613425021651.png

 

Gain Margin plot

Fred_Kohlhepp_1-1613425097617.png

 

Werner_E
25-Diamond I
(To:Cornel)

Test_1: "phasecor" can only be applied to vector arguments, not functions. So Test_1 has to fail

Test_3: "root" will only work on continuous functions, not on vectors like B<2>

Test_2: "root" will only work on continuous functions. Unfortunately arg(...) has a discontinuity, a jump, at +/- pi and so the function has to fail.

 

You may use a modified arg-function as described elsewhere in this thread which creates a continuous function at -180°. Using this function your Test_2 approach may work. The drawback is that using a modified arg-function requires you to decide on how to modify the arg function dependent on the specific transfer function and the range of angles you'd like to see.

 

But you could use the second "flavor" of the root function, where you don't have to provide a range (10^1 to 10^7 in your example) but a reasonable guess value:

Werner_E_0-1613414459995.png

Note that root finds the zeros of a function and to solve the equation f(x)=-180 you have to look for the zeros of the function f(x)+180

 

Another way I could think of is to do it similarly as I had shown it for the frequency where the magnitude equals 1. That means creating a large vector of frequency values and corresponding phase values which are "corrected" using phasecor. Then look in the phase vector for a phase near -180!

Werner_E_1-1613414806381.png

 

Cornel
19-Tanzanite
(To:Werner_E)

That turned out well.
Excellent.

CornelBejan_0-1613421311834.png

 

CornelBejan_1-1613421359129.png

Now I'm struggling with this function because I'm trying to do code-like with the function above.

CornelBejan_2-1613421619514.png

 

CornelBejan_3-1613421686846.png

It doesn't go well :((.

CornelBejan_0-1613422100360.png

 

Why?

What am I wrong or omitted?

 

 

Werner_E
25-Diamond I
(To:Cornel)


Why?

What am I wrong or omitted?

 


??? The values you mark as "Not good" seem to be the same as the ones you mark as "Good value", just shown in radiant and not in degrees.

Werner_E_0-1613423261730.png

 

Cornel
19-Tanzanite
(To:Werner_E)

Good!

I found a special case for a system (or rather, for several systems, as if its power increases, for example: s ^ 2, s ^ ​​3, etc.), I receive the same message.

CornelBejan_0-1613484700851.png

CornelBejan_1-1613484741737.png

CornelBejan_2-1613484784010.png

 

CornelBejan_3-1613484811863.png

How could this be remedied?

Thank you.
Best regards.

 

Werner_E
25-Diamond I
(To:Cornel)

> How could this be remedied?

I don't known

 

maybe there is no way to deal automatically with all possibly eventualities in Mathcad, maybe there is and we have not yet found it 😉

Cornel
19-Tanzanite
(To:Werner_E)

@Werner_E@Fred_Kohlhepp@LucMeekes 

In any case, I would like to thank you very, very, very much so far for your ideas, suggestions, and for your time and involvement. These suggestions were very useful to me in the turning points.
if in the future you will find new ideas and suggestions about what has been discussed so far here, this is the good topic to post :).
Likewise, if I find any more "doubts"/more "questions", I will post them as well.

Thank you very much.
Best regards.

LucMeekes
23-Emerald III
(To:Cornel)

With 1/s you have a first-order function. It'll not come near instability.

You may want to use symbolic functions to assess the order of the H function (or of its numerator and denominator) to find if you need to check for instability at all.

 

Success!
Luc

Fred_Kohlhepp
23-Emerald I
(To:Cornel)

If you calculate and plot the gain of 1/s, you get

Fred_Kohlhepp_0-1613491703798.png

Since the gain NEVER gets to 0 dB, so there is no root, and you can't find that frequency.

Announcements

Top Tags