% % ffttest.m -- djm, 30 june 2005 % clear N = 32; dx = 2*pi/N; % matlab fft works well on 0 < x < 2*pi x = (0:dx:2*pi-dx); k0 = (-N/2:N/2-1); k1 = fftshift(k0); % single fourier mode (note normalizations of fft & ifft !!!) j = 4; y0 = exp(i*j*x); yf = fft(y0)/N; y1 = ifft(yf)*N; figure(1); clf subplot(2,1,1); hold on plot(x,real(y1),'y',x,imag(y1),'y') plot(x,real(y0),'r--',x,real(y0),'k.',x,imag(y0),'b--',x,imag(y0),'k.') axis([0 2*pi -1 1]) title('\bf real (r) & imag (b) parts of y(x)') subplot(2,1,2) plot(k1,real(yf),'r',k1,real(yf),'k.',k1,imag(yf),'b',k1,imag(yf),'k.') axis([-N/2 N/2 -1 1]) title('\bf real & imag parts of fft of y(x)')