### FFT window type

Hi,

I’m using the Hann and Hamming windows for FFT processings.

I have the following C++ code for the Cosine window (works fine!):

long fftFrameSize = pow(2, fftLog2n);

switch(mWindowType) {

case WINDOW_COS:

for (long k = 0; k < fftFrameSize; k++) {

mWindow[k] = (double) -.5*cos(2.*M_PI*(double)k/(double)fftFrameSize)+.5;

}

break;

For the Blackman, I have:

w(n) = 0.42 – 0.8 cos(2*Pi*n/N) + 0.08cos(4*Pi*n/N)

The window length L = N+1

I’d like to test some other windows (like the Sine window) but I don’t find the algorithms.

Does someone could bring me help?

A Max expression would be very cool.

A C code would be perfect.

And if you have a C++, it would be wonderful!

Best regards,

Philippe

greetings phillepe,

more like a c expression than a c++ one…unless you’re inquiring

about a hanning/window representation of a signal as a

class/inheritance representation? obviously you didn’t list your

implementation and definition. it seems to me in your former question

you’re addressing what happens in the first element (simply a division

on 32-bit integers):

mWindow[k] = (double) -.5*cos(2.*M_PI*(double)k/(double)fftFrameSize)+.5;

whether this expression is valid granted in the class you’ve defined,

you’re invoking the correct libraries (i.e.

somewhat working list of windowing functions:

http://en.wikipedia.org/wiki/Hann_window

hann up in there (aka raised cos), which is what you’re attempting to invoke…

hope that is helpful…

brandon nickell.

On 2/27/07, Philippe Gruchet

>

> Hi,

>

> I’m using the Hann and Hamming windows for FFT processings.

> I have the following C++ code for the Cosine window (works fine!):

>

> long fftFrameSize = pow(2, fftLog2n);

> switch(mWindowType) {

> case WINDOW_COS:

> for (long k = 0; k < fftFrameSize; k++) {

> mWindow[k] = (double) -.5*cos(2.*M_PI*(double)k/(double)fftFrameSize)+.5;

> }

> break;

>

>

> For the Blackman, I have:

> w(n) = 0.42 – 0.8 cos(2*Pi*n/N) + 0.08cos(4*Pi*n/N)

> The window length L = N+1

>

>

> I’d like to test some other windows (like the Sine window) but I don’t find the algorithms.

>

> Does someone could bring me help?

> A Max expression would be very cool.

> A C code would be perfect.

> And if you have a C++, it would be wonderful!

>

> Best regards,

> Philippe

>

Hello Brandon,

mWindow[k] = (double) -.5*cos(2.*M_PI*(double)k/(double)fftFrameSize)+.5;

This cosine window works very fine here in Xcode.

I already and successfully implemented the Hann and Hamming windows based on the Accelerate.framework.

> here’s a somewhat working list of windowing functions:

> http://en.wikipedia.org/wiki/Hann_window

I was looking for some other windows and this link to Wikipedia is great and very useful, thanks!

From there, I just find what seems the original resource at the MathWorks website:

< http://www.mathworks.com/access/helpdesk/help/toolbox/signal/f11-708.html>

And I found the sine window in the MaxMSP examples (!?):

in [p ---windo] …

[expr (1.1* (sin(($f1/1024. )* (2. * 3.1415926))) - .1)]

As I can’t find it anywhere else, is it the right sine window for FFT too?

Best,

Philippe

Hi Phillipe,

I looked at the example patch you’re referring to and see that the

sample size is being ramped up into expr (1.1* (sin(($f1/1024. )* (2.

* 3.1415926))) – .1). This is correct, they note that the -.1 is to

just offset the amplitude of the signal so that there’s no clipping.

The Sine Window is best known for its use in mp3 compression but

higher resolution Window Types have been experimented with for

different codecs like Ogg Vorbis for better signal representation. The

Sine Window is defined as sin*((3.1415926/2*sample length)(k + 0.5).

What they’re really doing in that expression is tweaking the k (where

it’s defined as 1.1). The Sine Window takes the entire sample range

(hence 2*512 = 1024 in the denominator) so it seems the creator of the

patch played around with the coefficients to get different subjective

results (see the comment "in listening tests, several classic window

functions (hanning, hamming, squareroot, sinusoid) were tried. the

sine function sounded best. go figure")…that’s always an excellent

strategy!

BTW, I noticed that your coefficient in the second term for the

expansion of the Blackman Window should be 0.5 instead of 0.8, so:

w(n) = 0.42 – 0.8 cos(2*Pi*n/N) + 0.08cos(4*Pi*n/N)

should be:

w(n) = 0.42 – 0.5 cos(2*Pi*n/N) + 0.08cos(4*Pi*n/N)

Glad the reference to window types was helpful…

Brandon Nickell

On 2/28/07, Philippe Gruchet

>

> Hello Brandon,

>

> mWindow[k] = (double) -.5*cos(2.*M_PI*(double)k/(double)fftFrameSize)+.5;

>

> This cosine window works very fine here in Xcode.

> I already and successfully implemented the Hann and Hamming windows based on the Accelerate.framework.

>

> > here’s a somewhat working list of windowing functions:

> > http://en.wikipedia.org/wiki/Hann_window

>

> I was looking for some other windows and this link to Wikipedia is great and very useful, thanks!

> >From there, I just find what seems the original resource at the MathWorks website:

>

> < http://www.mathworks.com/access/helpdesk/help/toolbox/signal/f11-708.html>

>

> And I found the sine window in the MaxMSP examples (!?):

>

>

> in [p ---windo] …

> [expr (1.1* (sin(($f1/1024. )* (2. * 3.1415926))) - .1)]

>

> As I can’t find it anywhere else, is it the right sine window for FFT too?

>

> Best,

> Philippe

>

Hi Brandon,

Thank you very much for your explanation about the sine window.

I keep it in safe place!

> BTW, I noticed that your coefficient in the second term

> for the expansion of the Blackman Window should be 0.5

> instead of 0.8, so:

Yes, sorry. Just a typo by typing 8 instead of 5, just below ;-)

> Glad the reference to window types was helpful…

Oh yes, thanks again!

I can start my tests and see what works the best.

Kindest regards,

Philippe

> For the Blackman, I have:

> w(n) = 0.42 – 0.5cos(2*Pi*n/N) + 0.08cos(4*Pi*n/N)

> The window length L = N+1

I finally found the double-precision Blackman window inside Xcode/vecLib.framework

extern void

vDSP_blkman_windowD(

double * __vDSP_C,

vDSP_Length __vDSP_N,

int __vDSP_FLAG)

Thanks again for the NON-help about that :-(

PG

I like the info at MathWorld:

http://mathworld.wolfram.com/ApodizationFunction.html

_Mark

On Mar 7, 2007, at 2:58 PM, Philippe Gruchet wrote:

>

>> For the Blackman, I have:

>> w(n) = 0.42 – 0.5cos(2*Pi*n/N) + 0.08cos(4*Pi*n/N)

>> The window length L = N+1

>

> I finally found the double-precision Blackman window inside Xcode/

> vecLib.framework

>

> extern void

> vDSP_blkman_windowD(

> double * __vDSP_C,

> vDSP_Length __vDSP_N,

> int __vDSP_FLAG)

>

> Thanks again for the NON-help about that :-(

> PG

I realise this is 6 years late but in case anyone in future has the same issue, pretty much ever frequently used windowing function can be found at : http://en.wikipedia.org/wiki/Window_function

Forums > Dev