Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement Hann Window

I take blocks of incoming data and pass them through fftw to get some spectral information. Everything seems to be working, however I think I'm getting some aliasing issues.

I've been trying to work out how to implement a hann window on my blocks of data. Google has failed me for examples. Any ideas or links I should be looking at?

double dataIn[2048] > /* windowing here? */ > FFT > double freqBins[2048]

Update

Thanks to Oli for pointing out the issue I'm actually trying to fix is spectral-leakage, NOT aliasing...

like image 633
Tim Avatar asked Aug 24 '10 09:08

Tim


2 Answers

http://en.wikipedia.org/wiki/Hann_function . The implementation follows from the definition quite straightforwardly. Just use the w(n) function as multiplier, loop through all your samples (changing n as you go), and that's it.

for (int i = 0; i < 2048; i++) {
    double multiplier = 0.5 * (1 - cos(2*PI*i/2047));
    dataOut[i] = multiplier * dataIn[i];
}
like image 127
Joonas Pulakka Avatar answered Oct 23 '22 05:10

Joonas Pulakka


This is fine but most people probably want to do this on thousands of arrays full of data. You can fill an array of just constant multipliers once as your program's initializing (use the same size array you feed to FFT) then just multiply each point in your real array by each point in the multiplier array. Faster/cheaper than taking all those cosines over again each time.

like image 22
Alan Corey Avatar answered Oct 23 '22 05:10

Alan Corey