# N-point DFT of window function

I am currently choosing a window function to analyze signals in frequency domain. While I understand the reasoning behind using a window function and what to look for concerning main lobe and side lobe forms, I have stumbled across the fact that the frequency domain representation of a window function that Matlab generates with the wvtool looks a lot different to what I can obtain from simply applying the fft command to my respective window function.

After some research, I now understand that the shape of the window function in frequency domain depends on how many points the fft command uses. E.g. when applying the fft command with 100 points to a window of length n=100, the result is a continuous curve. The more points I use for the fft, the more accurately the lobes start to form that are also visible in the wvtool.

I have also read in this Stack Exchange question that an fft with more points than the signal length n basically interpolates between the samples of the n-point fft and that every second point of a 2n-point fft coincides with the n-point fft.

So, can I assume that the 2n-point fft is more accurate than the n-point fft? And how would that be considering that the 2n-point fft is just created from adding n zeros to the original signal and therefore doesn't add meaningful information to the signal? And when applying ffts to signals that are not window functions: Am I generally better off just adding more points to the fft? Normally, to increase frequency resolution, I would perform an n-point fft over a larger sample size n. But no matter how large the sample size, I can never obtain the lobes of the window functions without performing an fft with more points than samples. So am I somehow missing information when performing only an n-point fft on a real-world signal?

Thanks for any help, the more I research this the more I am confused at the moment.

I have added a minimal code sample to better illustrate what I mean. ws is the window size and m is a factor to increase fft points. So e.g. use m=2 to perform a 2n-point fft.

ws = 1000;
m = 1;

hanning = abs(fft(hann(ws), m * ws)) / sum(hann(ws));
hanning = hanning / max(hanning);
hanning = hanning(1:ws/2+1);

f = (0:(1/m):(ws/(2*m)));
f = f';

figure;
plot(f, 20*log10(hanning));

• maybe you need to zero-pad the window function (making it longer and requiring a larger $N$ for the FFT) before the FFT. Commented Sep 9, 2023 at 15:44
• As far as I understand that is exactly what a 2n-point fft does, adding n zeros to the window function and then performing a normal fft. I'm interested in why this leads to the (better?) result. Commented Sep 9, 2023 at 15:50
• You should be careful using "hanning" as a symbol in your MATLAB code because MATLAB uses that for the Hann window. Sorta like redefining pi. Commented Sep 9, 2023 at 16:29
• I don't see any zero-padding in the code. Maybe if m=2 but it's not. Remember that the FFT (which is a fast DFT) periodically extends the data presented to it. So which is closer to reality? A window function that is repeated right away with copies or a window function separated by some zeros. Because in the continuous-time real life, that window function is supposed to be isolated with zeros on both sides extending forever. Commented Sep 9, 2023 at 16:39
• It’s a good question. You’re basically wondering about frequency resolution, which is the minimum distance between two frequency components the dft can resolve, and frequency precision, which is simply the distance between two dft bins. Please see this answer which might help understand the difference between the two.
– Jdip
Commented Sep 9, 2023 at 16:43

So, can I assume that the 2n-point fft is more accurate than the n-point fft?

No. The N-point FFT contains all independent information that is required to completely represent the spectrum.

And how would that be considering that the 2n-point fft is just created from adding n zeros to the original signal and therefore doesn't add meaningful information to the signal?

And when applying ffts to signals that are not window functions: Am I generally better off just adding more points to the fft?

Depends on the application. Sometimes yes, sometimes no, but that really depends on what you want to do with the data.

This is priamrily a function of "visual intepretation". Let's look at a simple sine wave at a normalized frequency of $$\pi/2$$

$$x[n] = \sin(\frac{\pi}{2}n+\pi/4)$$

Here is a graph using a standard plot() function

This looks like a trapezoid wave but it is a true sine wave. The misconception is created by the plot() function which simply connects the individual samples with straight lines. That assumption is wrong and creates a substantial visual error. The correct way to draw this would be sinc() interpolation.

So interpolation can be quite useful especially if you want to actually look (with your eyes) at the data. However, mathematically it's not required. All the information is there.

• Sounds to me like padding is generally sensible when trying to visually identify frequency components in a signal, rule of thumb being more padding is better. But padding is generally not sensible when using ffts to calculate transfer functions using the H1 or H2 estimator because the extra zeroes add no information to the cross and auto spectra calculation. Then again, if you wanted to visualize the transfer function, the interpolation may be useful. Can you think of a scenario where padding would actually do harm? Commented Sep 9, 2023 at 18:09
• I can’t unless you’re very concerned with computational costs (very very)
– Jdip
Commented Sep 9, 2023 at 18:52