bugGNU Octave - Bugs: bug #61355, [octave forge] (control) Error on...

 
 

bug #61355: [octave forge] (control) Error on phase value of bode and margin plots

Submitted by:  Luiz Antonio Maccari Junior <luiz>
Submitted on:  Tue 19 Oct 2021 04:23:03 PM UTC  
 
Category:  Octave Forge Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  None Assigned to:  None
Originator Name:  Luiz Antonio Maccari Jr. Open/Closed:  Open
Release:  6.3.0 Operating System:  GNU/Linux

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Mon 25 Oct 2021 09:08:55 PM UTC, comment #6: 

An additional bug was detected. If you insert the values of the frequencies in the bode  function for frequencies after the resonance the phase values return NaN. Example:

s = tf('s');

TF2 = 1/(s^5*(s+2)*(s+10)*(s^2+100))

w = [9:0.1:11];
[mag, fase] = bode(TF2,w)

However if we use the bode function without specifying the frequencies the bode plot can give a phase plot with finite values.

 Studying the bode function I see the problem related with the function unwrap which uses a summation and when we have an ideal resonance the argument of the frequency response is NaN. To bypass this error it is needed to put a damping values for the resonant. As for example:

s = tf('s');

TF2 = 1/(s^5*(s+2)*(s+10)*(s^2+0.001+100))

w = [9:0.1:11];
[mag, fase] = bode(TF2,w)

Luiz Antonio Maccari Junior <luiz>
Mon 25 Oct 2021 08:57:13 PM UTC, comment #5: 

An additional example of the error with the phase plots. The code below results in the same phase plot. Bode function does not make difference between the phase of doubled poles or doubled zeros.

s = tf('s');

TF1 = (s^2+100)/(s^5*(s+2)*(s+10))

TF2 = 1/(s^5*(s+2)*(s+10)*(s^2+100))

bode(TF1,TF2)

Luiz Antonio Maccari Junior <luiz>
Wed 20 Oct 2021 12:35:50 AM UTC, comment #4: 

I am posting two additional examples of error in margin and bode functions.

Example 4 in file "bug_report_bode_ex4.m".

The bode plot of matlab and octave are the same both are correct. However, the margin function is incorrect in octave. The phase plot in octave margin phase plot starts in +180 and it should be -180.
See files: matlab_output_margin_ex4.jpg and octave_output_margin_ex4.jpg

Example 5 in file "bug_report_bode_ex5.m".

Here the bode function phase plot is wrong. It should start with 0 degree but it is starting with +180.

Sometimes the phase plot is wrong in bode function and sometimes is wrong in margin function. In margin function the error also leads to an error on gain margin. It seems that the error is in the wrapping of the phase plot. In example 5 bode function plotted a wrong phase range and in example 4 the error is in the phase range of margin function.

As I mentioned before, Matlab does not put wrap as default giving an option to choose it. Also in matlab it is important to note that the wrapping does not interfere on the results of gain or phase margin.

Thank for your time.  

(file #52130, file #52132,

Luiz Antonio Maccari Junior <luiz>
Tue 19 Oct 2021 11:21:38 PM UTC, comment #3: 

I can confirm that you have found a bug.
It seems to appear when there are 2 oscillators.
I am doing more tests.

Doug Stewart <dastew>
Tue 19 Oct 2021 08:58:45 PM UTC, comment #2: 

Now I was reviewing the functions in matlab and there they have an option named wrap phase. Using this all the phase plots will be plotted between the range -180 to +180. However, this option does not affect the value of gain margin. And for octave it affects causing errors. As for example in Example 3.

Another thing is that in octave there is not a standard form to plot phase. Sometimes the phase plots using bode and margin are different.

The ideal would be a non wrapped bode and margin functions or an option to choose the phase plot form.

Luiz Antonio Maccari Junior <luiz>
Tue 19 Oct 2021 04:33:15 PM UTC, comment #1: 

I have attached the results of the example 3 for matlab margin function (ex3_matlab.jpg) and octave margin function (ex3_octave.jpg). The result in octave is wrong.


Luiz Antonio Maccari Junior <luiz>
Tue 19 Oct 2021 04:23:03 PM UTC, original submission:  

Hello,

I am using bode function and I got wrong results when the system has two poles in the same position. The phase should be plotted as -180 (as two poles) however in some cases it is plotted as +180 (as two zeros). ? This behavior leads to a wrong plot and phase margins when I call margin function.

Above I give three examples with distinct results.

Example 1:

First one in the file "bug_report_bode.m" is a system with 4 poles, two at the frequency of 10^2 rad/s and two at 10^4 rad/s.

The expected behavior is -180° and after -180°. However the bode plot presents +180 and after -180. Bode and margin functions give the same phase plot. I have tested the same script in matlab and there the results are correct, as you can see on figures attached.

right result = matlab_output_bode.jpg
wrong result = octave_output_bode.jpg

Example 2:

On this example the bode plot gives the correct plot but the margin function does not. The example "bug_report_bode_teste3.m" has two poles at origin and additional one at 10 rad/s.The phase plot of function bode is correct but the margin one is wrong.

Example 3:
These wrong phase plot can lead to a problem to identify the correct gain margin as for example in the file "bug_report_bode_ex3.m" where because the wrong plot there is no crossover at -180 phase angle.

Best Regards

Luiz Antonio Maccari Junior <luiz>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #52130:  bug_report_bode_ex4.m added by luiz (171B - text/x-objcsrc)
file #52132:  bug_report_bode_ex5.m added by luiz (192B - text/x-objcsrc)
file #52127:  ex3_matlab.jpg added by luiz (25KiB - image/jpeg)
file #52128:  ex3_octave.jpg added by luiz (63KiB - image/jpeg)
file #52124:  octave_output_bode.jpg added by luiz (56KiB - image/jpeg)
file #52125:  bug_report_files.zip added by luiz (844B - application/zip)
file #52126:  matlab_output_bode.jpg added by luiz (19KiB - image/jpeg)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dastew (Posted a comment)
  • -email is unavailable- added by luiz (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-10-20 mmuetzel Carbon-CopyRemoved 102357 => -
    2021-10-20 mmuetzel SummaryError on phase value of bode and margin plots => [octave forge] (control) Error on phase value of bode and margin plots
    2021-10-20 luiz Attached File- => Added bug_report_bode_ex4.m, #52130
        Attached File- => Added matlab_output_margin_ex4.jpg, #52131
        Attached File- => Added bug_report_bode_ex5.m, #52132
        Attached File- => Added octave_output_margin_ex4.jpg, #52133
    2021-10-19 luiz Attached File- => Added ex3_matlab.jpg, #52127
        Attached File- => Added ex3_octave.jpg, #52128
    2021-10-19 luiz Attached File- => Added octave_output_bode.jpg, #52124
        Attached File- => Added bug_report_files.zip, #52125
        Attached File- => Added matlab_output_bode.jpg, #52126

    Back to the top


    Powered by Savane 3.7