Hann/Hanning & Hamming window functions in C#

By | 2011.07.15

Not so much output from me lately. The reason is that I’m occupied with an exciting and extremely complex hobby project. My geeksuperpower (or one of them) is that I’m able to keep extremely focused for long periods of time (months). Even when its boring, tough and seems impossible to solve the task I work my self through it. The prerequisite being that its complex and interesting enough. A quality many coders possess, for good and for bad.

Anyway, I’ve been thinking I should share some of my findings. So here goes.

Hann (Hanning) and Hamming window functions which you apply to the wave stream frame before passing it to the FFT. I looked everywhere and couldn’t find it for C#, but with some help of Wikipedia and the good people at StackOverflow I managed to put it together.


Note: Parts of Hamming code borrowed from this file which is part of a C# project that can do autotuning.

5 thoughts on “Hann/Hanning & Hamming window functions in C#

  1. dummy

    Dunno what you’re trying to achieve, but I guess it’ll work better if you implement the Hann window correctly …

    iwv[n].Re *= 0.5f – 0.5f * (float)Math.Cos((2 * Math.PI * n) / (N – 1));

  2. Kresna Tito

    i’m sorry for my misplaced question, but i’m working on phase coding steganography for that requires fft

    and i get stuck in the hanning window and complex data in aforge. can you give me a help? i will very pleased if you help me

    thanks.. and sorry for my bad english. i’m from Indonesia

  3. Vladislav

    There is a classic mistake in both loops (for Hamming and Hann functions):
    for (int n = 1; n < N; n++)
    it must be
    for (int n = 0; n < N; n++)


Leave a Reply