Search code examples
matlabplot

How to plot the spatiotemporal evolution of the fourier transform of my solution


I have a system of ODEs which I solve using ode113 and want to plot the spatiotemporal evolution of the squard modulus of the Fourier Transform of the solution data.

My space is defined using L = 256; % Grid size dx=1; % Unit grid spacing x=[-L/2:dx:L/2-dx]'; % Grid

and I want to define the frequency for the FT to go from -pi to pi: n=length(x); freq = 2*pi*(-n/2 : n/2 - 1) / L;

Then to compute the FT:

freq = 2*pi*(-n/2 : n/2 - 1) / L;
uhat = fft(u,n,2);
uhat = fftshift(uhat);
M = max(abs(uhat)'.^2,[],"all");
%uhat = uhat./M;
imagesc(tt,freq,log(abs(uhat)'.^2));
colormap('jet');
colorbar;
shading interp;
xlabel("TIME");
ylabel("Freq"), 

title('FT of solution')
subtitle("\kappa="+kappa+", A="+A+", \alpha="+alpha+", \delta="+delta)

However, what is plotted I do not understand. There is an abrupt change in behavior at t=50. I want to verify that I am plotting the FT correctly.

enter image description here


Solution

  • When using the function fftshiftwith a matrix as input there is more than one direction (row and columns). As the docu of fftshift states there is a second input argument:

    Y = fftshift(X,dim) operates along the dimension dim of X. For example, if X is a matrix whose rows represent multiple 1-D transforms, then fftshift(X,2) swaps the halves of each row of X.

    As in your example you haven't provided the second argument, the default behavior is the following:

    If no value is specified, then fftshift swaps along all dimensions.

    This can also be seen in your figures. To avoid that you should set the second argument dim accordingly to your data.