0
$\begingroup$

I've got the frequency response $H(e^{j\omega}) = \frac{2 + 3.125e^{-2j\omega}}{1-0.9e^{-j\omega}+0.81e^{-2j\omega}}$, and I'm trying to figure out how to plot the magnitude response and the phase response in Matlab. Is there a simple way to do this?

Thank you in advance. This is my first post here, so please tell me if there's anything I forgot to add.

Hal

$\endgroup$
  • 1
    $\begingroup$ Start by looking at the documentation for fft, fftshift, abs and arg. $\endgroup$ – MBaz Sep 27 '15 at 16:32
  • $\begingroup$ I am sorry, but I still don't quite get it. I am really a beginner at Matlab, and at signal processing. I've found out I can use abs and angle to get the magnitude and phase, but when I try to plot it over omega = -pi:0.1:pi it doesn't look right. I really have no idea how to construct this, and I've been trying for days now to get it working. I think I need a more detailed explanation to learn from. Thank you. $\endgroup$ – enpi Sep 27 '15 at 17:26
  • $\begingroup$ My best advice, then, is to go to your school's library, and check out any books with 'signal processing' and 'Matlab' in their title, and start from there. I'm not trying to be rude or anything, but some things are better learned from books, rather than internet fora. $\endgroup$ – MBaz Sep 27 '15 at 18:49
  • $\begingroup$ Well, that's exactly what I am doing, but the book doesn't present it in a way that's easy to understand. I generally learn best from examples which I copy and then modify to learn how it works. So stackexchange was kind of my last resort at this point. Thanks for the input though. $\endgroup$ – enpi Sep 27 '15 at 19:15
0
$\begingroup$

Write the frequency response in function of $ z = e^{j\omega} $, we have:

$ H(z) = \frac{2 + 3.125z^{-2}}{1-0.9z^{-1}+0.81z^{-2}} $

You can use the function freqz to plot the impulse response of this transfer function (both magnitude and phase). Here is the code I used:

b = [2 0 3.125]; % numerator coefficients
a = [1 -0.9 0.81]; % Denominator coefficients
freqz(b, a);

I strongly suggest you to read the freqz documentation to see why we put the parameters in such a way and to find other options.

I hope it helps.

$\endgroup$
  • $\begingroup$ Thank you! This made it all a lot clearer, especially with how you explained the way the function takes its values. You and Richard both answered almost at the same time, and both were very helpful. I'm accepting your answer since I felt yours was clearer and explained more. $\endgroup$ – enpi Sep 28 '15 at 0:30
2
$\begingroup$

@Hal: Unlike MBaz, I realize you weren't asking for information on the theory of signal processing. But, rather, you were asking a Matlab implementation question. I only have an old version of Matlab so I couldn't try Anthony's code. (Anthony was smart to insert that zero-valued coefficient.) But to plot the frequency mag. and phase responses of a discrete version of your filter, try these:

figure(1), freqz([2,0,3.125],[1,-0.9,0.81]);

or

freqz([2,0,3.125],[1,-0.9,0.81], 512, 'whole');
$\endgroup$
  • $\begingroup$ Thank you! This looks what I wanted. Finally something I can play around with! I'm looking through the freqz documentation, but so far I haven't found a way to display the y-axis on the phase response in radians. Do you know if that's possible? $\endgroup$ – enpi Sep 28 '15 at 0:11
  • $\begingroup$ Try this: [H,W]=freqz([2,0,3.125],[1,-0.9,0.81],512,'whole'); figure(1), subplot(2,1,1), plot(W/pi,abs(H)) ylabel('Mag.'), grid on subplot(2,1,2), plot(W/pi,angle(H)), ylabel('Radians') grid on, xlabel('Rad./sample (times pi)') $\endgroup$ – Richard Lyons Sep 29 '15 at 20:08
0
$\begingroup$

this is wrong, use freqz because bode() evaluates H(s), not H(z). s=jomega, while z = e^jomega

If you have the system identification toolbox, it's very easy.

http://www.mathworks.com/help/ident/ref/bode.html

H = tf([2 0 3.125],[1 -0.9 0.81]); bode(H);

Why a zero in the numerator? because you don't have a first-order term in the numerator of H, so you assume it's zero.

$\endgroup$
  • $\begingroup$ Can you explain the downvote? Is this technically wrong? This is an easy way in matlab to do this unless I'm mistaken. $\endgroup$ – panthyon Sep 27 '15 at 20:29
  • $\begingroup$ Thanks, this was interesting. It doesn't look quite like it does in my book's examples, but at least I've got it to output something! :D $\endgroup$ – enpi Sep 27 '15 at 20:50
  • 1
    $\begingroup$ I think Richard's answer is the correct one to use because bode evaluates s = jomega, while freqz() evaluates the complex exponential z which is substituted as e^jomega $\endgroup$ – panthyon Sep 27 '15 at 21:24
  • 1
    $\begingroup$ This is useful to know though, thanks! $\endgroup$ – enpi Sep 28 '15 at 0:31
  • 1
    $\begingroup$ Yep, I have. It just won't show until I have more reputation I think : ) $\endgroup$ – enpi Sep 28 '15 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.