Basic FFT Question: What range to sample the function in.
Afficher commentaires plus anciens
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)),"*")
Réponse acceptée
Plus de réponses (1)
Mitchell Thurston
le 29 Mar 2024
Modifié(e) : Mitchell Thurston
le 29 Mar 2024
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])

Catégories
En savoir plus sur Fourier Analysis and Filtering dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




