Advanced plotting
Consider the following problem:
Display the 2D Fourier transform intensity of a square slit.
(The 2D Fourier transform intensity is the diffraction pattern). Enter the following into square_
fft.m :
echo on
colormap(hsv);
x=zeros(32);
x(13:20,13:20)=ones(8);
mesh(x)
pause % strike a key
y=fft2(x);
z=real(sqrt(y.^
2));
mesh(z)
pause
w=fftshift(z);
surf(w)
pause
contour(log(w+1))
prism
pause
plot(w(1:32,14:16))
title('fft')
xlabel('frequency')
ylabel('modulus')
grid
echo off
The echo function displays the operation being currently executed. The program creates a 8-by-8 square on a 32x32 background and performs a 2D FFT on it. The intensity of the FFT (the real part of y) is stored in z and the D.C. term is moved to the centre in w. Note that the plot command when given a 3 by 32 array displays 3 curves of 32 points each.