% mk3Dcosine(N,T, kx,ky,omega) % % This program displays a travelling 3D cosine wave (kx,ky,omega) % % cos( 2 pi / N * (kx x + ky y) + 2 pi / T * omega t) % % where kx,ky are in 0,1,.. N-1 and omega is in 0,1,..T-1 % % You need to have Mike Langer's program "showmovie" in the same directory. % function mk3Dcosine(N,T,kx,ky,omega) Ihat = zeros(N,N,T); % % MATLAB indexes the matrix I(x,y) using indices from 1 to N, % whereas, in the course notes, we have been indexing from 0 to N-1. % This is the reason why we subtract 1 from the indices when % computing the x,y coordinates in Ihat() below. % (Similarly for the time variable.) Ihat(ky+1,kx+1,omega+1) = 1; if (kx * ky * omega == 0) ['ERROR: This code only works kx,ky,omega are all > 0'] else Ihat(N-ky+1,N-kx+1,T-omega+1) = 1; end I = real(ifftn(Ihat)); % The small imaginary error is due to numerical imprecision off fft. showmovie