Is the window function automatically used when doing the fft function, or do I have to enter code to use the window function?
62 次查看(过去 30 天)
显示 更早的评论
I used the fft function to make frequency measurements from the data.
At this time, I would like to know what the window function is using.
When using only the fft function, please tell me what kind of window function is used or if the window function is not applied
t = 0:0.01:1;
data = sin(2*pi*t);
plot(t,data)
fftdata = abs(fft(data));
% At this time, is the window function automatically used?
f = (0:length(data)-1)*1/length(data);
plot(f,fftdata)
0 个评论
回答(1 个)
Star Strider
2023-1-27
The fft defaults to a rectangular window that is the length of the signal. That is the only one that is ‘autoomatically’ used. Any others would have to be provided specifically as part of the fft call.
There are several window funcitons available in the Signal Processing Toolbox.
t = (0:0.01:1).'; % Transpose To Column Vector
data = sin(2*pi*t);
plot(t,data)
L = numel(data)
fftdata = abs(fft(data.*hann(L))); % Use Hanning Window
% At this time, is the window function automatically used?
f = (0:length(data)-1)*1/length(data);
plot(f,fftdata)
.
5 个评论
Star Strider
2025-7-2
No correction should be necessary. The purpose of the window function is to correct for the discrete Fourier transform being finite. The symbolic Fourier transform assumes an infinitely-long argument and produces an infinitely long result.
Note that the second half of the fft result is the complex conjugate fo the first half. (The result would be symmetric about the centre D-C offset using the fftshift function.) This has the effect of distributing the original energy of the signal between the two 'halves' of the discrete Fourier transform. To recover the approximate amplitudes of the original signal components, it is necessary to multiply them by 2. This is a property of the fft calculation, not the result of windowing.
Paul
2025-7-2
Hi Lorenz,
If you want the amplitude plot scaled to the magintude of the underlying complex sinusoids, then divide the FFT by the sum of the elements of the window.
t = 0:0.01:1;
x = sin(2*pi*t);
N = numel(x);
X1 = fft(x);
h = hann(N).';
X2 = fft(x.*h);
f = (0:N-1)/N/0.01;
Without scaling
figure
plot(f,abs(X1),'-o',f,abs(X2),'-x')
With scaling. Note that the sum of the elements of the rectangular window is simply N.
figure
plot(f,abs(X1)/N,'-o',f,abs(X2)/sum(h),'-x')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!