freqz function in MATLAB.

Status
Not open for further replies.

triquent

Full Member level 3
Joined
Oct 13, 2004
Messages
166
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
1,826
freqz matlab

I am trying to use the freqz function in matlab to plot an FIR filter (coefficient b=[.5 .5 .5 .5])magnitude and phase response. I tried two different method to plot the magnitude, but I got different results. anything wrong?
1) directly use freqz(b,1) , it automatically plot both of magitude in db and phase.
2)I use [h,w]=freqz(b,1)
plot(w, 20*log(abs(h)))
For these two methods, I got different magnitude plot. What's wrong with my code?
I suppose they will get same plot.
 

matlab freqz

The plot is the same. The normalized frequency is what is different in the plots.

In one it is normalized from -pi*pi or 0 to pi as it appears.

In the other it is normalized from -0.5 to 0.5 or 0 to 1 as it appears

Either way is correct but take care , once using one approach, keep on this.
 

freqz function in matlab

I guess if u add the following line before the plot line they will be the same:
Code:
w = w / pi;

Regards,
amraldo.
 

freqz plot

There is another thing that I didn't quote in the first answer. Typing the commands exactly how you presented, there is also a difference in magnitude in the plots. Actually that was your question.

This is because you did type >> plot(w, 20*log(abs(h)))
you should type >> plot(w, 20*log10(abs(h))) otherwise you are gonna have the Neperian Logarithm and not the base 10 log.

Well, now I think the answer is completed.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…