Matlab difference equations

Discussion in 'Programmer's Corner' started by kenny-one, Apr 21, 2010.

  1. kenny-one

    Thread Starter Member

    Apr 21, 2010
    37
    0
    please i need help in this matlab homework, we havent covered in class but my lecturer gave us as a homework, please help ASAP....

    a) Using MATLAB, generate the impulse response to the following difference equation:

    y[n ] -1.8cos( pi/16)y[n-1]+ 0.81y[n-2]=x[n]+0.5x[n-1].

    Plot h[n] in the range of -10=< n=<100 .

    b)Determine the impulse response analytically to verify your results.
    Hint: You may use Impz or filter command to find the impulse response

    c) Use freqz to make plots of the magnitude and phase responses for the difference
    equation above. Use 512 points, equally spaced between 0 and 2pi
     
    Last edited: Apr 21, 2010
  2. johndoe45

    Member

    Jan 30, 2010
    364
    1
    Last edited: Apr 22, 2010
  3. kenny-one

    Thread Starter Member

    Apr 21, 2010
    37
    0
    thanks Johndoe45....really appreciate.....

    ppl if you can help with c), i dnt really know what to do here.....for b) i was able to do..

    help with c) pls........
     
  4. johndoe45

    Member

    Jan 30, 2010
    364
    1
    actually. correct it.

    i think it is
    n = -10:100;
    a = [1 -1.8*cos(pi/16) 0.81]; % left hand side of difference equation
    b = [1 0.5 0]; % right hand side of difference equation
    h=filter(b,a,n); %find h from difference equation
    plot(n,h)
    h=filter(b,a,n)


    go to matlab help > function browser > type freqz.
    and i think it is the same format as filter.

    so just change it and put freqz instead of filter
    looks like this

    n = -10:100;
    a = [1 -1.8*cos(pi/16) 0.81]; % left hand side of difference equation
    b = [1 0.5 0]; % right hand side of difference equation
    h=freqz(b,a,n); %find h from difference equation
    plot(n,h)

    i've never worked with impulse responses before in matlab. so all it takes is a little researching and you can do it yourself kenny-one. but if you need help you can always ask on the forum.

    if you are really stuck. just let us know what functions you think you have to use and how to use them. that way it is one less step that i/we have to do. which is go look to see what the function does.
     
    Last edited: Apr 23, 2010
Loading...