DSPRelated.com
Forums

Freqz and fft question

Started by rudykeram April 12, 2013
Hi, 

This is a Matlab specific question. I posted this question on Matlab DSP
discussion group, but it never showed up. So, I am asking the question here
(I have posted questions on the Matlab group before, but it would always
show up).

But anyways, here is my question:

I have always been unclear about why freqz behaves this way, and to me this
doesn’t really make sense.

Let me explain:

Let’s say that I have a hamming window

% hamming window
L=64
w = hamming(L);

And, if I take the fft of this function (with some known frequency), I will
endup with this:

Fs = 1000;
NFFT = 1024;
W = fft(w,NFFT);
f = 1/2*linspace(0,1,NFFT/2+1);
plot(f,2*abs(W(1:NFFT/2+1)));

This makes perfect sense. The actual fft gives an even function, and by
looking at the first half, the above will plot its frequency response.
We can even ignore the sampling frequency, and always look at it on a
normalized frequency axis [0:0.5]

I believe the above result makes perfect sense.

Now, I want to get the same thing using "freqz":

If I do the following:

[W2 f2]=freqz(w);
magdb = 20*log10(abs(W2));
plot(f2,magdb)

I can see that the frequency axis makes one full circle. The x-axis goes
from [0:pi].

But here is exactly, what I think doesn’t make sense !!

Because obviously our hamming window (vector “w”) should have an even
distribution on the frequency axis. And what I would’ve expected was to
see the result of "freqz" going from [0:pi/2]

To me it seems like what "freqz" reports is the half of the response, but
it uses the full normalized [0:1] frequency axis to view the plot, which
wouldn't really make sense.

Even if we do:

wvtool(w);

the result is identical to “freqz”. This may be because "wvtool"
implements "freqz" algorithm under the hood.

But, I think the fft result makes lot more sense.

In other words, let’s say if we want to measure the cut-off frequency by
merely looking at the plots, the cutoff frequency would always be off by a
factor of 2, depending on whether we are using “fft” to plot the
frequency response, or we are using “freqz” or “wvtool”

Which I still think “fft” result makes more sense.

Can someone please explain this?

Thanks, 
--Rudy

On Fri, 12 Apr 2013 12:12:28 -0500, rudykeram wrote:

> Hi, > > This is a Matlab specific question. I posted this question on Matlab DSP > discussion group, but it never showed up. So, I am asking the question > here (I have posted questions on the Matlab group before, but it would > always show up). > > But anyways, here is my question: > > I have always been unclear about why freqz behaves this way, and to me > this doesn’t really make sense. > > Let me explain: > > Let’s say that I have a hamming window > > % hamming window > L=64 > w = hamming(L); > > And, if I take the fft of this function (with some known frequency), I > will endup with this: > > Fs = 1000; > NFFT = 1024; > W = fft(w,NFFT); > f = 1/2*linspace(0,1,NFFT/2+1); > plot(f,2*abs(W(1:NFFT/2+1))); > > This makes perfect sense. The actual fft gives an even function, and by > looking at the first half, the above will plot its frequency response. > We can even ignore the sampling frequency, and always look at it on a > normalized frequency axis [0:0.5] > > I believe the above result makes perfect sense. > > Now, I want to get the same thing using "freqz": > > If I do the following: > > [W2 f2]=freqz(w); > magdb = 20*log10(abs(W2)); > plot(f2,magdb) > > I can see that the frequency axis makes one full circle. The x-axis goes > from [0:pi]. > > But here is exactly, what I think doesn’t make sense !! > > Because obviously our hamming window (vector “w”) should have an even > distribution on the frequency axis. And what I would’ve expected was to > see the result of "freqz" going from [0:pi/2] > > To me it seems like what "freqz" reports is the half of the response, > but it uses the full normalized [0:1] frequency axis to view the plot, > which wouldn't really make sense. > > Even if we do: > > wvtool(w); > > the result is identical to “freqz”. This may be because "wvtool" > implements "freqz" algorithm under the hood. > > But, I think the fft result makes lot more sense. > > In other words, let’s say if we want to measure the cut-off frequency by > merely looking at the plots, the cutoff frequency would always be off by > a factor of 2, depending on whether we are using “fft” to plot the > frequency response, or we are using “freqz” or “wvtool” > > Which I still think “fft” result makes more sense. > > Can someone please explain this?
I'm no Matlab guru -- but one full circle spans 2 pi radians, not 1 pi. So if freqz is returning frequencies from 0 to pi, then that's _half_ a circle. -- My liberal friends think I'm a conservative kook. My conservative friends think I'm a liberal kook. Why am I not happy that they have found common ground? Tim Wescott, Communications, Control, Circuits & Software http://www.wescottdesign.com
>On Fri, 12 Apr 2013 12:12:28 -0500, rudykeram wrote: > >> Hi, >> >> This is a Matlab specific question. I posted this question on Matlab
DSP
>> discussion group, but it never showed up. So, I am asking the question >> here (I have posted questions on the Matlab group before, but it would >> always show up). >> >> But anyways, here is my question: >> >> I have always been unclear about why freqz behaves this way, and to me >> this doesn’t really make sense. >> >> Let me explain: >> >> Let’s say that I have a hamming window >> >> % hamming window >> L=64 >> w = hamming(L); >> >> And, if I take the fft of this function (with some known frequency), I >> will endup with this: >> >> Fs = 1000; >> NFFT = 1024; >> W = fft(w,NFFT); >> f = 1/2*linspace(0,1,NFFT/2+1); >> plot(f,2*abs(W(1:NFFT/2+1))); >> >> This makes perfect sense. The actual fft gives an even function, and by >> looking at the first half, the above will plot its frequency response. >> We can even ignore the sampling frequency, and always look at it on a >> normalized frequency axis [0:0.5] >> >> I believe the above result makes perfect sense. >> >> Now, I want to get the same thing using "freqz": >> >> If I do the following: >> >> [W2 f2]=freqz(w); >> magdb = 20*log10(abs(W2)); >> plot(f2,magdb) >> >> I can see that the frequency axis makes one full circle. The x-axis
goes
>> from [0:pi]. >> >> But here is exactly, what I think doesn’t make sense !! >> >> Because obviously our hamming window (vector “w”) should have an
even
>> distribution on the frequency axis. And what I would’ve expected was
to
>> see the result of "freqz" going from [0:pi/2] >> >> To me it seems like what "freqz" reports is the half of the response, >> but it uses the full normalized [0:1] frequency axis to view the plot, >> which wouldn't really make sense. >> >> Even if we do: >> >> wvtool(w); >> >> the result is identical to “freqz”. This may be because "wvtool" >> implements "freqz" algorithm under the hood. >> >> But, I think the fft result makes lot more sense. >> >> In other words, let’s say if we want to measure the cut-off frequency
by
>> merely looking at the plots, the cutoff frequency would always be off
by
>> a factor of 2, depending on whether we are using “fft” to plot the >> frequency response, or we are using “freqz” or “wvtool” >> >> Which I still think “fft” result makes more sense. >> >> Can someone please explain this? > >I'm no Matlab guru -- but one full circle spans 2 pi radians, not 1 pi. >So if freqz is returning frequencies from 0 to pi, then that's _half_ a >circle. > >-- >My liberal friends think I'm a conservative kook. >My conservative friends think I'm a liberal kook. >Why am I not happy that they have found common ground? > >Tim Wescott, Communications, Control, Circuits & Software >http://www.wescottdesign.com >
Thanks, You are totally right. I don't know why I was keep thinking of "pi" being a full circle, where in fact it is half a circle. --Rudy