Identifying wave-number sign after applying 2-dimensional FFT
5 views (last 30 days)
Show older comments
I am applying 2D FFT to identify the direction of of wave number (kx) and frequency (w). I am testing it with a simple wave propagating in +ve x-direction having form Acos(wt-kx). After applying 2D fft using inbuid functionn of MatLab (i.e fft2) I expect to peak in amplitude at [kx, w]. As FFT also gives information for -ve frequencies, I will get additional other peak at [-Kx, -w]. However, I am getting peak at [Kx,-w] and [-kx,w] which is not correct. Can you please share opinion on it. my program is given below
%%
dx=0.1; dt=0.1;
nx=64; nt=128;
dkx=2*pi/(nx*dx);
dw=2*pi/(nt*dt);
xt=1:nx;xt=xt*dx;
tt=1:nt;tt=tt*dt;
nxh=nx/2;
nth=nt/2;
%% generating frequency matrix
kx1=0:nxh;
kx1=kx1*dkx;
fkx1=flip(kx1);fkx1(nxh+1)=[]; kx1(nxh+1)=[];
kx1f=[0-fkx1 kx1];
w1=0:nth;
w1=w1*dw;
fw1=flip(w1);fw1(nth+1)=[];w1(nth+1)=[];
w1f=[0-fw1 w1];
%% generate wave with amplitude 1, wave number 1 and frequency 2
w=2; Kx=1;
A0=1;
for jj=1:nt
for ii=1:nx
xy(jj,ii)=A0*cos(w*dt*jj-Kx*ii*dx);
end
end
%% performing 2D fft
out=fft2(xy);
out=fftshift(out);
P=2*abs(out)/(nx*nt);
%% plotting data and fft2 output
subplot(1,2,1)
imagesc(xt,tt,xy);
axis xy
xlabel('x')
ylabel('time');
colorbar
caxis([-A0 A0]);
axis xy
subplot(1,2,2)
imagesc(kx1f,w1f,P);
xlabel('kx')
ylabel('w');
colorbar
axis xy
caxis([0 A0]);
xlim([-5 5])
ylim([-5 5])
0 Comments
Answers (1)
David Goodmanson
on 26 Jan 2019
HI Bharati,
WIthout going through the code in and detail (nice plot) I think the reason is the following. The cos wave is
(1/2) ( exp(i(k0x-w0t)) + exp(i(-k0x+w0t)) )
Take the first term, and and look at the continuous integral version of fft2. Not counting overall constants this is
Integral exp(i(k0x-w0t)) exp(-ikx) exp(-iwt) dx dt
^ ^
For the fft2, each of the exponential functions comes in with a minus sign as shown. The integral is
Integral exp(i((k0-k)x-(w0+w)t)) dx dt
and the result is proportional to the product of two delta functions, delta(k0-k) delta(w0+w) which gives a 2d peak at (k0,-w0) which is what you get. Similarly the second term gives a peak at (-k0,w0).
The fft is set up with the minus sign so that a function like exp(+ik0x) gives a corresponding peak at +k0. But for the wave, w0 comes in with a negative sign and consequently the fft gives a peak at -w0. You could say that fft2 is not ideally set up to handle this situation.
2 Comments
David Goodmanson
on 27 Jan 2019
Well, it's fine if you recognize what's going on and after you define w1f, add a line
w1f=[0-fw1 w1];
% wave has the form exp(+-i(k0x-w0t)) so after fft2, sign of resulting
% w variable must be reversed
w1f = -w1f;
with some kind of annotation like what is above. For me, if I made that change without annotation and took a look in a couple of years, that line would be very mysterious.
See Also
Categories
Find more on Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!