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

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

SOLVED

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

I see in the magnitude - frequency graph of the bode diagram that the figure (straight line) intersects the 0db axis, and therefore there should be a certain frequency value for this.
At least at first glance, I don't see a problem with that.

CornelBejan_1-1613497739030.png

CornelBejan_0-1613497630704.png

 




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


@CornelBejan wrote:

I see in the magnitude - frequency graph of the bode diagram that the figure (straight line) intersects the 0db axis, and therefore there should be a certain frequency value for this.


Sure!

Werner_E_0-1613498580139.png

 

I also hope that you see that the frequency is about 1.6*10^-1 Hz!

 

So why are you looking for it in the range from 10 to 10^6

Werner_E_1-1613498617638.png

or in the range from 10^2 to 10^6

Werner_E_2-1613498765835.png

or in the range from 10^1 to 10^7

Werner_E_3-1613498850425.png

You should fully understand the meaning of the arguments of the functions you were given and also have a good understanding of how they work. Otherwise you may ask here if something is still unclear.

 

 

 

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

Ok.
Good!
Excellent!
Works now :).

Thank you very much for your explanation/observation.

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

@Werner_E@LucMeekes@Fred_Kohlhepp  

[This is the thank you message 🙂]

 

I wanted to add this message of thanks because your ideas and suggestions (which materialized through Mathcad files or algorithms/programs to solve the problem) related to the problems I exposed in this topic helped me very, very, very much.
But not only that but also the fact that I received an answer at any (later) 
time, which is not such a simple thing from enough points of view (time, knowledge, etc.), especially when you try to solve a problem and feel that you would like a second or a third opinion from other people.
I would have honored you with a beer, something if you were with me in my city/country.
But anyway, even in these times (with the pandemic of course), it's not so trivial to be realized.
Therefore, what I can convey to you is a kindly thank you.

Thank you very much.
Best regards.

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

You are welcome!

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

@Werner_E@LucMeekes,  @Fred_Kohlhepp 

I don't understand why the following thing happens:

The functions I use for calculating Gain Margin (GM) and Phase Margin (PM) are:

CornelBejan_0-1613754052757.png

The Plant Transfer Function is:

CornelBejan_1-1613754094244.png

 

Case 1: fmax = 10e6 => GM_Tc = -22.627 db & f0_Phase_Plot_Tc = 2.471 kHz.

CornelBejan_15-1613755171240.png

CornelBejan_16-1613755192219.png

CornelBejan_17-1613755213633.png

 

Case 2: fmax = 10e8 => GM_Tc = 138.668 db & f0_Phase_Plot_Tc = 52710 kHz.

CornelBejan_12-1613755004686.png

CornelBejan_13-1613755051498.png

CornelBejan_14-1613755070777.png

 

Does anyone have any idea what is the reason for this happening in the case of GM?

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

Thank you.
Best regards.

 

 

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

The phase of your Tc only dips across the 180° border in a very narrow frequency range, from 1894 Hz to 2795 Hz. The root function that tries to find the crossing needs two endpoints, one on each side of the crossing.

LucMeekes_0-1613758713597.png

If you stretch your range too far, root will not find any crossing:

LucMeekes_2-1613758771298.png

 

It requires a more versatile root finding function to do what you need.

 

Success!
Luc

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

@Werner_E@LucMeekes@Fred_Kohlhepp 

I think there is something wrong with these two functions, how they are built, but I do not know what, at least so "foreshadowed" and I deduce from my more detailed checks by the last resort.

CornelBejan_11-1613762635050.png

CornelBejan_1-1613760697125.png

 

Let's take the following example:

The Plant Transfer Function is:

CornelBejan_2-1613760740812.png

CornelBejan_10-1613761723337.png

 

The axis cutting frequency of 0 decibels on the magnitude-frequency plot gives well, as it results from the function.

CornelBejan_4-1613761212949.png

 

The phase-frequency plot does not even cut the axis at -180 degrees so it cannot define a cut-off frequency for this graph, but the function returns a frequency value (this means that the graph cuts the axis at -180 degrees, which is not true).

CornelBejan_7-1613761374700.png

 

Reading the value in degrees corresponding to the cutoff frequency read from the magnitude - frequency graph (approximately 13.614kHz) results in a value of -56,259 degrees, which means that the phase margin (PM) is 180 degrees - 56,258 degrees = 123,741 degrees, and the result of the function is -103,666 degrees, and 76,313 degrees, respectively, which is a discrepancy.

CornelBejan_6-1613761350396.png

 

CornelBejan_9-1613761568520.png

 

Hmm, something strange is happening, because it does not shoot the values ​​read from the graph with the values ​​calculated by functions ...

 

I was so happy :)) because it seemed to work great 🙂

What do you think is missing or wrong?

Thank you.
Best regards.

 

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

I have a mistake regarding the previous comment:

CornelBejan_0-1613766213408.png

The Phase Margin (PM) is well calculated with the corresponding function used.

CornelBejan_1-1613766415442.png


In the previous comment, from the graph, I read at the frequency of approximately 1.3 kHz, but it must be at the frequency of approximately 13 kHz (as much as the cutting frequency at 0 decibels is read from the magnitude-frequency characteristic).

CornelBejan_3-1613766545496.png

CornelBejan_4-1613766639917.png degree.

 

But the problem remains in calculating the Gain Margin (GM) with the corresponding function used

CornelBejan_2-1613766441122.png


This is because the phase-frequency graph does not cut the -180 degree line, which should normally lead to an infinite Gain Margin (GM) (or at least a large value).

 

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

As a check, I put the transfer function corresponding to Gc (s) in Matlab and drew the corresponding bode diagrams.

Mathcad:

CornelBejan_0-1613767381692.png

CornelBejan_4-1613767566204.png

CornelBejan_5-1613767592088.png

 

Matlab:

CornelBejan_1-1613767418999.png

CornelBejan_2-1613767448805.png

 

CornelBejan_3-1613767515428.png

 

 

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

Therefore, the function that I suspect would not have good results is:

 

CornelBejan_1-1613768132714.png

 

Any suggestions/ideas/opinions?

Thank you.

 

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

The 'GM' function calculates the frequency at which the phase crosses -180 deg, using the Lookup function. That is, it tries to find -180 deg in the phase array, and once found, it takes the corresponding frequency.

However, it doesn't accurately search for -180 deg in the phase array. Due to the argument "near" it is satisfied when it finds a phase value near -180 deg, hopefully the nearest value. This means that it will always find a phase 'near' -180 deg, even though the phase never crosses that line.

Note that the 'PM' function also uses the argument "near" to the Lookup function, so you will be able to find a problem there with a transfer function that remains below 0 dB...

 

As I said earlier, if you want a set of functions for GM and PM that works accurately for any transfer function, you'll need a more equipped set of functions.

 

Success,

Luc

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

Yes, it is.
I'm just trying to make my life easier, through some automation to find certain values ​​on the two graphs.
But in general, it is ok with what has been said in this topic and what solutions have been brought.

Thank you very much.
Best regards.

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

@LucMeekes@Werner_E@Fred_Kohlhepp 

I hope you didn't mind that I posted small peculiarities or questions that I found along the way while I was trying various aspects.

Thank you.
Best regards.

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

Anyway, your comments helped me a lot (and those of others, of course).

Thank you for that:).

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

They show the same results.

Tags (1)

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

I can't open the Mathcad file you posted (I use Mathcad 15).

Can you put a picture, something, of what you want to show?

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

Hi,

 for sure, in the files that I published some time ago in the community, that is: "https://community.ptc.com/t5/PTC-Mathcad/3-low-pass-I-order-digital-filter-equivalent-to- linear-classic", and others i.e 4), 5), i ran into this problem but I didn't take it into account, what do you think? if you can't open the page then in search write "3) LOW PASS", it should be reachable.

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

Only showing the same results.

 

image.png

 

Tags (1)

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

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

Ah, yes, the graphics are fine. That was not the idea, at least not in the last posts.
The graphs were discussed at the beginning of this topic, and, in principle, it was solved.

The ideas from the last posts and comments were in the context in which I could evaluate the two characteristics in certain points of them, in the sense of finding through certain functions that solve for the Phase Margin (PM) and the Gain Margin (GM) for different transfer functions in an automatic (or at least semi-automatic) way and not reading fully manually on the graphs.

CornelBejan_0-1613902793171.png

CornelBejan_1-1613902809183.png

 

CornelBejan_2-1613902853632.png

CornelBejan_3-1613902866636.png

CornelBejan_4-1613902898760.png

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

 

A few more things appear, such as:


1) If the phase-frequency graph does not cut the -180 degree axis then GM should return the value of infinity.


2) If the phase-frequency graph cuts the -180 degree axis by more than one point (2.3, etc., as shown below (*)), then a single point should be extracted or the frequency search range should be narrowed only for a single cut of the graph with the axis of -180 degrees, to get a correct answer.

But it's okay because they keep you awake and attentive to what you're doing, and then they make you not forget how to calculate the Phase Margin (PM) and the Gain Margin (GM) from the graphs when you do not have a computer :).

 ((*)

CornelBejan_6-1613903667997.png

CornelBejan_7-1613903778563.png

CornelBejan_8-1613904636556.png

CornelBejan_9-1613904672119.png

 

CornelBejan_10-1613904752830.png

CornelBejan_11-1613904783269.png

For example, Matlab takes into account, at least as far as I can see until now, the last point that cuts the -180 degree axis.

 

CornelBejan_12-1613904893353.png


For the above completeness in Mathcad:

CornelBejan_13-1613905048332.png

CornelBejan_15-1613905146472.png

 

)

 

but as @LucMeekes  says:

CornelBejan_5-1613903434155.png

 

Even so, it works well.

I'm pleased.
I am satisfied with the suggestions and solutions that came from the other colleagues and that were referred to in this topic. Also, as I said above, the results are good, from the latest research.

 

Thank you all.
Best regards.

Announcements