Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Bode function not working

Subject: Bode function not working

From: Alex Thiele

Date: 21 Jun, 2010 07:23:05

Message: 1 of 7

Dear all,

I have written and used the following code under MATLAB ver 7.3 without any problem but it does not work correctly under ver 7.10;

Numerator = ones(1,24);
Denominator = zeros(1,24);
Denominator(1,1) =24;
Averager_TF_z = tf([Numerator],[Denominator],1/6000);
bode(Averager_TF_z)

The code just generates the gain/phase responses for a simple 24 point averager.

The probelm is in the BODE function. The gain response returned from bode is correct, but the phase response is incorrect. The phase at 0Hz should be 0° and this is what ver 7.3 returned. Ver 7.10 however returns a phase of 4pi (720°) at 0Hz. The whole phase response is lifted.

I have tried searching for a change history of the bode function to see why it doesnt work anymore but cannot find it.

Any suggestions as to why bode doesn't work in this instance greatfully received. Many thanks,

Alex Thiele

Subject: Bode function not working

From: Alec Stothert

Date: 21 Jun, 2010 10:57:37

Message: 2 of 7


Try right click the bode reponse plot and select the "Properties..." menu
item. From the properties dialog select the options tab and under the phase
response check "Adjust phase offsets". Does this give the phase you exepect?

Note that 720 is a multiple of 360 so the phase isn't wrong just offset by a
couple of revolutions.

-Alec

"Alex Thiele" <bert1234@yahoo.com> wrote in message
news:hvn40o$2e8$1@fred.mathworks.com...
> Dear all,
>
> I have written and used the following code under MATLAB ver 7.3 without
> any problem but it does not work correctly under ver 7.10;
>
> Numerator = ones(1,24);
> Denominator = zeros(1,24);
> Denominator(1,1) =24;
> Averager_TF_z = tf([Numerator],[Denominator],1/6000); bode(Averager_TF_z)
>
> The code just generates the gain/phase responses for a simple 24 point
> averager.
>
> The probelm is in the BODE function. The gain response returned from bode
> is correct, but the phase response is incorrect. The phase at 0Hz should
> be 0 and this is what ver 7.3 returned. Ver 7.10 however returns a phase
> of 4pi (720) at 0Hz. The whole phase response is lifted.
>
> I have tried searching for a change history of the bode function to see
> why it doesnt work anymore but cannot find it.
>
> Any suggestions as to why bode doesn't work in this instance greatfully
> received. Many thanks,
>
> Alex Thiele

Subject: Bode function not working

From: Alex Thiele

Date: 21 Jun, 2010 11:57:05

Message: 3 of 7

Hi alec, thank you very much for your reply.

Yes, checking 'adjust phase offsets' does then give the correct phase repsonse. It there any way I can automate this option?

I tried;

p=bodeoptions;
p.PhaseMatching='on';

but this didn't work. The problem is that this needs to be automated in the software I am creating. (actually it's an exe I created in ver 7.3 that people use. But I'm now updating the exe in ver 7.10 but cannot compile it until I get the bode function working again)

Regards,

Subject: Bode function not working

From: Alec Stothert

Date: 22 Jun, 2010 12:25:06

Message: 4 of 7

Hi Alex,

You need to pass the bodeoptions to the bode command, the follwoing worked
for me:

>> opt = bodeoptions;
>> opt.PhaseMatching = 'on';
>> bode(Averager_TF_z,opt)

-Alec

-Alec
"Alex Thiele" <bert1234@yahoo.com> wrote in message
news:hvnk2h$kl3$1@fred.mathworks.com...
> Hi alec, thank you very much for your reply.
>
> Yes, checking 'adjust phase offsets' does then give the correct phase
> repsonse. It there any way I can automate this option?
>
> I tried;
>
> p=bodeoptions;
> p.PhaseMatching='on';
>
> but this didn't work. The problem is that this needs to be automated in
> the software I am creating. (actually it's an exe I created in ver 7.3
> that people use. But I'm now updating the exe in ver 7.10 but cannot
> compile it until I get the bode function working again)
>
> Regards,

Subject: Bode function not working

From: Alex Thiele

Date: 28 Jun, 2010 07:57:05

Message: 5 of 7

Hi Alec,

Thank you very much for your help - problem solved.

Best regards,

Alex

Subject: Bode function not working

From: Alex Thiele

Date: 28 Jun, 2010 14:15:11

Message: 6 of 7

Ahhh, actually I've just discovered that when you invoke the function using just bode(etc) it works, but when you actually want the data and invoke it using [a b c]=bode(etc) it doesnt work.

It appears that the bode options only work for the display and not when actually using the function to return data.

So unfortunately, problem not solved! Looks like I might have to just work out the phase wrapping thing and fix it myself in real time. Ooh I wish Mathworks would stop changing functions in every release!!! It causes us so much trouble here.

Subject: Bode function not working

From: Ottmar Beucher

Date: 29 Oct, 2014 09:54:11

Message: 7 of 7

"Alex Thiele" wrote in message <hvn40o$2e8$1@fred.mathworks.com>...
> Dear all,
>
> I have written and used the following code under MATLAB ver 7.3 without any problem but it does not work correctly under ver 7.10;
>
> Numerator = ones(1,24);
> Denominator = zeros(1,24);
> Denominator(1,1) =24;
> Averager_TF_z = tf([Numerator],[Denominator],1/6000);
> bode(Averager_TF_z)
>
> The code just generates the gain/phase responses for a simple 24 point averager.
>
> The probelm is in the BODE function. The gain response returned from bode is correct, but the phase response is incorrect. The phase at 0Hz should be 0° and this is what ver 7.3 returned. Ver 7.10 however returns a phase of 4pi (720°) at 0Hz. The whole phase response is lifted.

Hi,
I've got the same problem with this code:
s = tf('s');
H = (1-s)/(1+s)
omega=(0:0.01:pi);
[a,ph]=bode(H,omega);

The phase is starting with 360 degrees instead of the correct value 0 degrees.

After reading the posting I tried out the option
opt.PhaseMatching = 'on';

and it worked well for
bode(H,omega,opt);

But if I try
[a,ph]=bode(H,omega,opt);

(because I want to plot the bode plot for myself with my annotations)

it turned out that ph still contains the wrong values!!!

My questions:
1) is there a work-around for that problem?
2) why does bode behave like this? What is it good for?
Why does MathWorks alter a well working function to make a bad working function
out of it? ........

Regards
Ottmar

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us