Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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:
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))

Thanks. I was surprised to see that it looks almost identical to the plot without the Hanning window.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top