Filter löschen
Filter löschen

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

15 Ansichten (letzte 30 Tage)
L'O.G.
L'O.G. am 22 Mär. 2022
Kommentiert: KSSV am 22 Mär. 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

Antworten (2)

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

Melden Sie sich an, um zu kommentieren.


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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Fourier Analysis and Filtering finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by