matlab bode plots

Thread Starter

suzuki

Joined Aug 10, 2011
119
Hi,

I'm trying to plot the following transfer function as a bode plot in matlab (tried posting in the mathworks forums but no luck)


it appeared to be a trivial task, but here i am. The problem is that to be able to plot in Matlab, the transfer function needs to be in a certain form

e.g. A s^2 + B s + C

so basically, i need to have an expanded form in terms of s = j*w_n. For my above equation, there is a 1/w_n term in the denominator, which, in the bode plot varies and makes matlab unhappy when calling the tf( function call.

I tried to expand the denominator but even then, you always have a w_n term that doesn't have imaginary part j, which means you cannot rewrite it as s.

Does anyone have a way around this? or some tricks to simplify this transfer function?
 
Last edited:

steveb

Joined Jul 3, 2008
2,436
Hi,

I'm trying to plot the following transfer function as a bode plot in matlab (tried posting in the mathworks forums but no luck)

http://i.imgur.com/tVToE.png

it appeared to be a trivial task, but here i am. The problem is that to be able to plot in Matlab, the transfer function needs to be in a certain form

e.g. A s^2 + B s + C

so basically, i need to have an expanded form in terms of s = j*w_n. For my above equation, there is a 1/w_n term in the denominator, which, in the bode plot varies and makes matlab unhappy when calling the tf( function call.

I tried to expand the denominator but even then, you always have a w_n term that doesn't have imaginary part j, which means you cannot rewrite it as s.

Does anyone have a way around this? or some tricks to simplify this transfer function?
Yes, remember that j^2=-1. Hence, you can place the j with the w_n, anytime you want to.
 
Matlab can make vectored calculations very quickly and it can calculate with complex numbers. Take advantage of that and let it calculate the complex valued response for your function then plot the magnitude and angle.

Try this code, below. Note the .* and .^ and ./ that indicate element-by-element operations rather than matrix operations. Also, j and pi are predefined constants. (j is i.)

% Matlab bode plot example

f = logspace(1,8,300) ; % 300 points from 1Hz to 100MHz
s = j*2*pi*f ;

wz = 2*pi*1e5 ;
wp1 = 2*pi*1e3 ;
wp2 = 2*pi*1e6 ;

h = (1 + s/wz) ./ ( (1+s/wp1) .* (1+s/wp2) ) ;

figure;
subplot(2,1,1) ;
semilogx(f, 20*log10(abs(h))) ; grid on ; % mag in dB
subplot(2,1,2) ;
semilogx(f, angle(h)*180/pi) ; grid on ; % phase in deg

By the way, most of this works in Octave, as well, which is free... Also the Matlab website has many user contributed functions.
 

Attachments

Top