General > General Technical Chat
FFT window function calculation detail
(1/8) > >>
electr_peter:
I have a question w.r.t. FFT and window function usage. Calculation details of triangle window function values is not 100% clear.
Let's say we want to use triangle window on sampled data - which weighting option is correct? See simple examples with only 5 and 6 data points.

With sample size of 5 weights could be:
* a) start at zero, end with non-zero (0, 0.5, 1, 1, 0.5)
* b) start at zero, end with zero (0, 0.5, 1, 0.5, 0)
* c) start at non-zero, end with non-zero (0.33, 0.67, 1, 0.67, 0.33)With sample size of 6 weights could be:
* a) start at zero, end with non zero (0, 0.33, 0.67, 1, 0.67, 0.33)
* b) start at zero, end with zero (0, 0.5, 1, 1, 0.5, 0)
* c) start at non-zero, end with non-zero (0.33, 0.67, 1, 1, 0.67, 0.33)

Should flat top peak (in some cases) reach 1 or be below 1? EDIT: irrelevant, scaling takes care of this afterwards. Area under filter is normalized to 1 with scaling.

Which definition is correct? Same question go for other window functions. IMO option a)"zero - non-zero" makes the most sense as it is "periodic" (full period with no repeating points).

One negative thing is that zeros at the start/end make you lose information about 1 or 2 raw samples when using inverse FFT on windowed data.
radar_macgyver:
A window function, by definition, must be symmetric and must have the end values equal to zero. According to that definition, the only one that matches is the 'zero-zero' definition. If followed strictly, this means that the popular Hamming window is not a true window function, since it will allow the samples at either end of the input to the DFT to be unequal, resulting in discontinuities in the circular convolution process inherent to the DFT. It's a good enough compromise that everyone uses it anyway.
SiliconWizard:
Yes it should be symmetric.

Now of course since the window is discrete, the least samples you have and the more 1 sample matters. Obvious. So depending on the actual resolution of your FFT anyway and the number of samples, either of your 6 versions may get you pretty similar results. For just a few samples, not so much.
electr_peter:
Thanks for input. I am asking because I saw different implementations of window functions in various math packages. With higher sample size it makes little difference, but I would like to have it implemented properly.

General window filter implementation could be:
* pick a window function, which is symmetric and has 0 at both ends
* define discrete weights such that 1st and last sample have zero weights.
* intermediate samples have weights of windows function above them (see graph below)In case of triangle window and even number of sample points, middle sample weights have flat top and do not reach exactly 1.


With sample size of 5 weights are (0.0, 0.5, 1.0, 0.5, 0.0)
With sample size of 6 weights are (0.0, 0.4, 0.8, 0.8, 0.4, 0.0)

EDIT: I came to conclusion that logic above is not entirely correct. Zero - non-zero fashion is best option, see msg4537295
electr_peter:
Window function gateway Matlab allows both window versions for most filter with opt parameter. "Symmetric" has zero on both ends, "periodic" has zero on one end.
https://www.tutorialspoint.com/execute_matlab_online.php

--- Code: ---hanning(6, "symmetric")
hanning(6, "periodic")

hanning(5, "symmetric")
hanning(5, "periodic")
--- End code ---

Still not sure which is better after looking through DFT definitions. Difference is only +/- 1 sample, but that is not insignificant.
Considering that windowed function is viewed as repeating function from DFT perspective, case can be made for both zero - nonzero & zero - zero type windows.
If window is [0, 0.5, 1, 0.5], then repetition is [0, 0.5, 1, 0.5, 0, 0.5, 1, 0.5, 0, 0.5, 1, 0.5, ...]
If window is [0, 0.5, 1, 0.5, 0], then repetition is [0, 0.5, 1, 0.5, 0, 0, 0.5, 1, 0.5, 0, 0, 0.5, 1, 0.5, ...]
Both are period, but case with zero-zero leaves additional 0 in the sequence (a flat spot).

Is there a good calculator online for window weights/FFT that I can cross reference windowed FFT results?
Navigation
Message Index
Next page
There was an error while thanking
Thanking...

Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod