Effacer les filtres
Effacer les filtres

How to properly take fft in MATLAB plus take real and imaginary components?

15 vues (au cours des 30 derniers jours)
L'O.G.
L'O.G. le 22 Mar 2022
Commenté : KSSV le 22 Mar 2022
I wish to calculate the real and imaginary parts of the fft of a function f(t) that I can determine with arbitary time spacing. How do I do this, and how can I adjust the sampling frequency of the resulting fft? When I change dt for the time vector, I no longer sample that function as precisely, but then df for the fft (I think) is more finely spaced. I guess I am misunderstanding something. Also, when I take the absolute value to obtain the one-sided fft, I no longer have any imaginary component. I think I misunderstanding some basic aspects of the fft that I hope somebody can walk me through.
t = linspace(0.01,100,10000); % arbitrary time spacing here
nfft = 2^nextpow2(numel(t)); % not sure why this must be the case, but I've seen this in examples
dt = t(2) - t(1); % linear spacing
df = 1/dt;
Freq = (df/2)*linspace(0,1,nfft/2+1); % I guess df/2 is the Nyquist criterion as is the nfft/2 ?
f_w = abs(fft(f_t,nfft)); % Take one-sided of f_t
A = real(f_w);
B = imag(f_w); % doesn't return anything

Réponses (2)

KSSV
KSSV le 22 Mar 2022
You have used abs at the fft, how do you expect aa complex out put? You should not take abs if you want the complex output.
t = linspace(0.01,100,10000); % arbitrary time spacing here
nfft = 2^nextpow2(numel(t)); % not sure why this must be the case, but I've seen this in examples
dt = t(2) - t(1); % linear spacing
df = 1/dt;
Freq = (df/2)*linspace(0,1,nfft/2+1); % I guess df/2 is the Nyquist criterion as is the nfft/2 ?
f_w = fft(f_t,nfft); % Take one-sided of f_t
A = real(f_w);
B = imag(f_w); % doesn't return anything
  2 commentaires
L'O.G.
L'O.G. le 22 Mar 2022
Shouldn't I take the one-sided fft here? If so, how?
KSSV
KSSV le 22 Mar 2022
You may take the one-sided fft, but to have real and complex parts; you need not to do abs.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 22 Mar 2022
Arbitrary time values means your times might not be uniform intervals. You should use nufft
https://www.mathworks.com/help/matlab/ref/double.nufft.html
  1 commentaire
L'O.G.
L'O.G. le 22 Mar 2022
By arbitrary, I just meant that I can calculate the function f(t) with any time values that I want.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange

Tags

Produits


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by