Azzera filtri
Azzera filtri

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

15 visualizzazioni (ultimi 30 giorni)
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

Risposte (2)

KSSV
KSSV il 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 Commenti
KSSV
KSSV il 22 Mar 2022
You may take the one-sided fft, but to have real and complex parts; you need not to do abs.

Accedi per commentare.


Walter Roberson
Walter Roberson il 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

Categorie

Scopri di più su Fourier Analysis and Filtering in Help Center e File Exchange

Tag

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by