I have some problems with transforming my data to the f-k domain.
I could see many examples on this site about DFT using Matlab. But each of them has little difference.
Their process is almost the same, but there is a difference in the DFT algorithm.
what I saw is
%Setup domain
s = size(data);
%time domain
nt = s(1); %number of time sample
dt = time(2); %time interval
%position domain
nx = s(2); %number of position sample
dx = position(2); %position interval
%Setup wavenumber & frequency
%frequency
Nyq_f = 1/(2*dt);
df = 1/(nt*dt); % Frequency increment
f = -Nyq_f : df : Nyq_f-df; % frequency
%wavenumber
Nyq_k = 1/(2*dx); % Nyquist of data in first dimension
dk = 1/(nx*dx); % Wavenumber increment
k = -Nyq_k : dk : Nyq_k-dk; % wavenumber
for j1 = 1 : Nt
for j2 = 1 : Nt
data_frequency(j1) = data_frequency(j1) + ...
data_time(j2)*exp(-1i*(2*pi)*(f(j1)*t(j2)))*dt;
end
end
In that code, f
means frequency, t
means time, dt
means time interval.
But many of other codes, they use this code:
for k=1:nfft
for n=1:nfft
X(k) = X(k) + f(n)*exp(-j*2*pi*(k-1)*(n-1)/N);
end
end
I couldn't understand why the results of the first code and the result of fft function are the same without dividing by the data length.
And the second question is, my data's matrix size is not the power of 2. In this case, I know that when I use the FFT function, I need to use zero-padding to the data for the matrix size. So, should I use zero-padding for the data even when using the DFT code?
question from:
https://stackoverflow.com/questions/65871714/dftdiscrete-fourier-transform-using-matlab 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…