Search code examples
fftmath.netwindowing

Hann window starts and ends with values that don't seem to make sense


I am playing around with mathdotnet and am experimenting with the different windows for use in FFTs. I am specifically curious about the Hann window (though i'm sure this applies to the others as well). When I generate a Hann window of, say, 2048 samples wide, I expect to get a set of variables gradually increasing to a peak and then gradually decreasing at the same rate. What i get instead is this:

    [0] 0                       double
    [1] 2.3553948388377322E-06  double
    [2] 9.421557163713512E-06   double
    [3] 2.11984204002702E-05    double
    [4] 3.768587359187503E-05   double
    [5] 5.8883761400674306E-05  double
    [6] 8.4791884109036708E-05  double
    [7] 0.0001154099976216072   double
    [8] 0.00015073781346730541  double
    [9] 0.0001907749988023788   double
    [10]0.00023552117641323367  double
    ....
    [2039]  0.00015073781346730541  double
    [2040]  0.00011540999762155169  double
    [2041]  8.4791884109036708E-05  double
    [2042]  5.8883761400674306E-05  double
    [2043]  3.768587359187503E-05   double
    [2044]  2.11984204002702E-05    double
    [2045]  9.421557163713512E-06   double
    [2046]  2.3553948388377322E-06  double
    [2047]  0                       double

As you can see, the values at the beginning and end of the hann window seem to be completely meaningless especially considering that anything over 1 doesn't make sense...

Generating a window with much less samples (I tried 20) works just fine.

As I don't feel I know enough about FFTs or the library itself, I don't feel comfortable posting a bug report before getting your opinion.


Solution

  • The numbers look correct to me. Note that 2.3553948388377322 E-06 is just the scientific notion of writing 0.0000023553948388377322.

    Note that when using this for FFTs, you may want to use Window.HannPeriodic instead of Window.Hann, which is available since v3.14.0-beta01.