how to claculate fft with window function?
227 views (last 30 days)
Show older comments
Jack Daniels
on 9 Nov 2022
Commented: Star Strider
on 10 Nov 2022
I saw several code implementation fft with window fcn.
size(window)
ans =
1 44100
size(z)
ans =
1 44100
% calculate fft
z = fft(s.*window);
or
size(x)
ans =
1 1001
size(winvec)
ans =
1001 1
xdft = fft(x'.*winvec);
How it should be calculated fft argument by column product or row product?
0 Comments
Accepted Answer
Star Strider
on 9 Nov 2022
The first is correct. Note that ‘s’ needs to be a column vector.
Fs = 1000;
L = 1E+4;
t = linspace(0, L-1, L).'/Fs; % Column Vector
s = sum(sin([1;100;200;300;400]*2*pi*t.')).'; % Column Vector
figure
plot(t, s)
grid
Fn = Fs/2;
NFFT = 2^nextpow2(L);
FTs = fft(s,NFFT)/L;
Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(Fv, abs(FTs(Iv)))
grid
xlabel('Frequency')
ylabel('Magnitude')
title('Without Window')
FTs = fft(s.*hamming(L),NFFT)/L;
figure
plot(Fv, abs(FTs(Iv)))
grid
xlabel('Frequency')
ylabel('Magnitude')
title('With Window')
.
2 Comments
Star Strider
on 10 Nov 2022
My pleasure!
The code creates a time vector and then a signal vector by summing the rows of ‘s’, creating column vectors.
A slightly easier approach would have been:
t = linspace(0, L-1, L)/Fs; % Row Vector
s = sum(sin([1;100;200;300;400]*2*pi*t)).' % Column Vector
t = t(:); % Column Vector
The (.') is the simple transpose operator, with (') being the complex conjugate transpose operator. For real arrays there’s no difference, however most of us here have gotten used to specifying the simple transpose and complex conjugate transpose to avoid the unintended consequences of using the complex conjugate transpose when we intended to use the simple transpoise.
.
More Answers (0)
See Also
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!