Matlab problem

Discussion in 'Programmer's Corner' started by alok, May 1, 2005.

  1. alok

    Thread Starter New Member

    May 1, 2005
    3
    0
    Hi
    I'm kinda new to Matlab
    Wot i'm trying to do is draw a Bode plot without using the inbuilt 'bode' function.

    i tried using logspace command for the purpose but all in vain

    can anyone help???

    Here is the code i had written

    a=[0 0 25];
    b=[1 4 25];

    w=logspace(-1,2)
    hold on
    w1=0.1:100;
    for i=1:100
    x=polyval(a,j*w1(i));
    y=polyval(b,j*w1(i));
    z=x/y;
    b=abs(z);
    plot(20*log10(B),w(i),'+')
    hold on
    end

    pls help
    thx a lot
     
  2. Brandon

    Senior Member

    Dec 14, 2004
    306
    0
    Not sure about the bode mechanics, but I can see MatLab coding issues.

    You cant do logs for negative numbers is your logspace issue. No numbers to a power cangive you a negative number using a typical log base of 10.

    w1 id forming a sequency of 0.1 1.1 2.1 3.1 ... 99.1 and never reaches 100.
    You use B in theplot, it should be b.

    You should not use the plot inside of a for next loop. You should use MatLab vector abilities to do all you looping.
    i.e.

    w=logspace(-1,2) <-- what sequence are u trying to make?
    i=[1:100]
    w1=[0.1:100] <--- what kind of numeric sequenceare you trying tomake here???
    x=polyval(a,j*w1); <-- no subscript, and it will make x into a vector
    y=polyval(b,j*w1); <-- same here
    z=x./y; <-- add the . to the / to make it a memberwise division for vectors
    b=abs(z);
    plot(20*log10(B),w,'+") <---Need to know about w before I can fix this.
     
  3. alok

    Thread Starter New Member

    May 1, 2005
    3
    0
    thx brandon for ur reply

    Wot i'm trying to do is plot

    20*log10(B) against w
    where i need the magnitude in db ie 20*log10(B) on a linear scale
    while i want w to vary logarithmically


    so thats why i used logspace w =(-1,2)
    ie w varying from 0.1 to 100 but logarithmically

    i hope u r getting wot i'm trying to convey
    i'll try n attach a figure to explain
     
  4. Brandon

    Senior Member

    Dec 14, 2004
    306
    0
    I gotcha..

    Check out the semilog function rather than plot. Its a plot which turns 1 axis into a log scale all by itself, either semilogx or semilogy. You don't need to do anything, you just need to define your overall frequency range and it will scale it for you by orders of magnitude.
     
  5. alok

    Thread Starter New Member

    May 1, 2005
    3
    0
    thx a lot brandon

    u made my day......................
    ALOK
     
  6. susi

    Active Member

    Jun 4, 2004
    31
    0
    Ok sorry for interruption but can u plz tell me what this MATLAB all abt?.I heared abt it,that it needs some codes to work on Mathematics eqs and graphs but what kinda language is this,,and can I find any tutorial on it??...Ok but I work with MathEq and MathType and it do not need any codings.
     
  7. switchfoot

    New Member

    May 14, 2005
    9
    0


    Matlab is a bit like Mathematica and Maple. In my opinion, Maple is a cross between Matlab and Mathematica. Just like Mathematica, u can create Matlab programs to handle things that are not built in..ie. to perform more complicated functions etc.
    There are many tutorials on the web..just google it...
    PS. what's MathType and MathEq?
     
  8. Brandon

    Senior Member

    Dec 14, 2004
    306
    0

    MatLab is also built around C++ and it has its own C compile built right into the program. You can take wnything you write in MatLab and convert it into an exe for calculations.

    Its great for DSP, Control Systems, statistics, and all just about anything mathmatic related you can think of. You can redefine tons of functions andf actually make your own which is where a lot of the coding comes in.

    Using MatLab I was able to make a program that would turn a text ascii file into an AM modulated waveform and hide it inside of a .wav file. You late could take the .wav file, filter out the music and reconstruct the text. If you can get a chance, check it out.
     
Loading...