matlab bode plots

Discussion in 'Homework Help' started by suzuki, Nov 2, 2011.

  1. suzuki

    Thread Starter Member

    Aug 10, 2011

    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: Nov 7, 2011
  2. steveb

    Senior Member

    Jul 3, 2008
    Yes, remember that j^2=-1. Hence, you can place the j with the w_n, anytime you want to.
    suzuki likes this.
  3. t_n_k

    AAC Fanatic!

    Mar 6, 2009

    Do you have the Matlab control system toolbox?
  4. mixed_signal

    New Member

    Dec 5, 2009
    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) ) ;

    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.