Hanning Window

Status
Not open for further replies.

Emil09

New Member
I know how to find the amplitude spectrum of a sine wave
Code:
t=(0:99)/100;
S=sin(2*pi*25*t);
Y=fft(S);
plot(abs(Y))
and I know how to generate a Hanning window
Code:
n=100;
whann=hanning(n);
[Px,f]=freqz(whann/sum(whann),1,512,2);
plot(f,20*log10(abs(Px)))
but how do I use a Hanning window to plot the amplitude spectrum of a sine wave?
I've tried all kinds of variations on what I would imagine should work but it just doesn't happen.
 
The hanning window is applied to the time-domain data first, and then the data is passed to fft(). Because the sample you are using may have discontinuities (large assumed jumps) at the beginning and end of the sample, this puts unwanted harmonics into your fft - the hanning et al. windows reduce the size of the discontinuity.

So, your first example, but applying the hanning window:
Code:
t=(0:99)/100;
S=sin(2*pi*25*t);
Y=fft(S .* hanning(length(S))');
plot(abs(Y))
 
Last edited:

Thanks. I was surprised to see that it looks almost identical to the plot without the Hanning window.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…