Borrar filtros
Borrar filtros

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

15 visualizaciones (últimos 30 días)
L'O.G.
L'O.G. el 22 de Mzo. de 2022
Comentada: KSSV el 22 de Mzo. de 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

Respuestas (2)

KSSV
KSSV el 22 de Mzo. de 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 comentarios
L'O.G.
L'O.G. el 22 de Mzo. de 2022
Shouldn't I take the one-sided fft here? If so, how?
KSSV
KSSV el 22 de Mzo. de 2022
You may take the one-sided fft, but to have real and complex parts; you need not to do abs.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 22 de Mzo. de 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 comentario
L'O.G.
L'O.G. el 22 de Mzo. de 2022
By arbitrary, I just meant that I can calculate the function f(t) with any time values that I want.

Iniciar sesión para comentar.

Categorías

Más información sobre Fourier Analysis and Filtering en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by