views:

144

answers:

3

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...

+1  A: 

Wikipedia is your friend: Hanning window

Surely your googling came up with wikipedia?! Anyway just create a function that returns an array of length N with the Hanning coefficients and multiply this array by your dataIn[2048].

Simon Walker
Yeah, I've read that, I guess my maths is too bad to work out exactly what I should be doing with each element!
Tim
+3  A: 

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];
}
Joonas Pulakka
You're right. My maths is quite rusty and it is quite a straightforward function. I thought there was more to it than that!
Tim
+1  A: 

Not an answer to your question, but an aside on your problem. Windowing helps solve spectral leakage problems, not aliasing problems.

Spectral-leakage effects occur when the frequency components of your waveform are not exact integer sub-multiples of your sample rate.

If you have aliasing, then you're fundamentally screwed. You'll either need to increase your sample rate, or put in a (better) anti-aliasing filter before you sample.

Oli Charlesworth
The issues I'm having ARE spectral-leakage. So I have poor maths and poor terminology...
Tim