Basic FFT Question: What range to sample the function in.
显示 更早的评论
Sorry about this basic question, and what may just be a bug.
I have been playing with the fft, and as a sanity check I thought I would the case of cosine, which we know only has two nonzero terms in the fft, both equal to 1/2. How ever when I sample cosine in the range
it gives me the coefficients equal to -1/2.
test_func = @(t) cos(t);
M = 10;
ms = (-M/2:(M/2-1));
dx = 2 * pi / M;
xn = ms * dx;
fs = test_func(xn);
cms = (1/M) * fft(fs);
plot(real(fftshift(cms)),"*")
However when I change my range to
everything works as expected. However I am under the impression that the fft should not be sensitive to this change. Can you tell me where I am going wrong?
test_func = @(t) cos(t);
M = 10;
ms = (0:M-1);
dx = 2 * pi / M;
xn = ms * dx;
fs = test_func(xn);
cms = (1/M) * fft(fs);
plot(real(fftshift(cms)),"*")
采纳的回答
更多回答(1 个)
Mitchell Thurston
2024-3-29
编辑:Mitchell Thurston
2024-3-29
When you perform an FFT, it is assumed that the original signal is on a timespan from [0 to 2*pi]. When you pass these signals as arguments using fft, the program is seeing these signals as:

The negative signs you're seeing essentially mean "same magnitude of the frequencies, but 180° out of phase"
You can recreate any signal from fftshift output with:
A = fftshift(cms);
mag = abs(A); % frequency magnitude
phase = angle(A); % phase shift for each frequency
w = floor((1-M)/2):floor((M-1)/2); % angular rates
S = @(t) sum(real( mag.*(cos(w.*t+phase)) ));
figure
plot(xn, fs); hold on
fplot(@(t) S(t), [0 2*pi])

类别
在 帮助中心 和 File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




