pcolor with complex data
7 views (last 30 days)
Show older comments
my all code is this:
a=imread('plus_white.gif');
[m n]=size(a);
lambda=600e-9;
f=16.5e-9;
w=4e-3;
k = (fftshift(fft2(a))).^2;
x = linspace(-lambda*f*n/(2*w), lambda*f*n/(2*w), n);
y = linspace(-lambda*f*m/(2*w), lambda*f*m/(2*w), m);
pcolor(x,y,k);
the code is taken from Stephen Schultzs' Using MATLAB to compute diffraction patterns of complex apertures.
??? Error using ==> pcolor at 62 Data inputs must be real.
k is like that 2.645177387196637e+02 + 2.156307053870210e+02i I don't want to loose my data by changing it int type what i can do for it?
0 Comments
Accepted Answer
Image Analyst
on 1 Jan 2013
First of all, you should change the name of the badly-named I to something else. It looks too much like a 1 or an l. Call it something descriptive, like theSpectrum. Then you should use image() or imshow() instead because pcolor does not display the last column or row of your matrix (proof: pcolor(rand(4))).
imshow(log(real(theSpectrum)));
or you can use imag() or norm() or whatever. Taking the log will compress the display so you can actually see it, since usually the DC spike is so huge that it makes all the higher frequencies hard to see. Or impossible, if they are less than 1/255 the height of the DC spike.
After that, you can apply a colormap if you want:
colormap(jet(256));
colorbar;
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!