Last active
November 26, 2018 20:38
-
-
Save mpreciado/b6db87e9a13a077ec96aea08774cc37c to your computer and use it in GitHub Desktop.
Example of how an optical spectral line is mapped into the propagation angles, and the corresponding spatial projection, for non-paraxial regime (high angles)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%Example of how an optical spectral line is mapped into the propagation angles, and the corresponding spatial projection, for non-paraxial regime (high angles) | |
% In short, the radial components of frequencies and angles are related with radial_frequencies = sin(radial_angles), | |
% and the radial components of the spatial projection are related with radial_angles=atan(radial_spatial_projections). | |
% For small angles these trigonotmetric relations are just proportional relations (in paraxial aproximation). | |
% I will be surprises id there are not mistakes/bugs. Comments to @miguelscilight. | |
u=(-1:0.01:1); | |
v=(-1:0.01:1); | |
[U,V]=meshgrid(u,v); | |
%% | |
ro=sqrt(U.^2+V.^2); %magnitude of spectral component | |
phi=atan(U./V)+(V>=0)*pi; %angle of spectral component | |
h = figure; | |
filename = 'nonParaxial.gif'; | |
%% | |
tol=0.025; | |
ScreenSize=5; %screen size in meters | |
flag=false; | |
for theta=pi*( [-0.2:0.02:0.2 0.2:-0.02:-0.2]); %ilumination / grating angle | |
frec_angle=sin(theta); % spatial frequency associated to this angle | |
subplot(131) | |
F=ro<1.*(abs(V-frec_angle)<tol); % line spectrum | |
imagesc(u,v,F); | |
shg; | |
axis image | |
title('Frequency Spectrum') | |
xlabel('Normalized spatial frequency \nu_x\lambda'); | |
ylabel('Normalized spatial frequency \nu_y\lambda'); | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
%ANGULAR SPECTRUM. | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
u2=(pi/2)*(-1:0.01:1); | |
v2=(pi/2)*(-1:0.01:1); | |
[U2,V2]=meshgrid(u2,v2); | |
ro2=sqrt(U2.^2+V2.^2); | |
phi2=atan(U2./V2)+(V2>=0)*pi; | |
subplot(132) | |
% the spatial frequencies are related by the angles of propagation | |
%by appying sin(.) to the radial component of the angle (ro2) | |
F2=(ro2<pi/2).*(abs(sin(ro2).*cos(phi2)+frec_angle)<tol); | |
imagesc(u2,v2,F2); | |
shg; | |
axis image | |
title('Angular Spectrum') | |
xlabel('\theta_x [rad]'); | |
ylabel('\theta_y [rad]'); | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
%Projection in the Screen | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
u3=ScreenSize*(-1:0.01:1); | |
v3=ScreenSize*(-1:0.01:1); | |
[U3,V3]=meshgrid(u3,v3); | |
ro3=sqrt(U3.^2+V3.^2); | |
phi3=atan(U3./V3)+(V3>=0)*pi; | |
% the radial component of the angles of propagation are related with the projection in the | |
% screen by applying atan(.) to the radial component of the projection | |
% (ro3). Afterwards we can appy sin() to find the spatial frequency | |
% component. | |
%Here a distance of 1 meter is asummed, d | |
d=1; | |
subplot(133) | |
F3=(abs(sin(atan(ro3/d)).*cos(phi3)+frec_angle)<tol); | |
imagesc(u3,v3,F3); | |
shg; | |
axis image | |
title('Screen projection @ 1m (cropped)[m]') | |
xlabel('x [m]'); | |
ylabel('y [m]'); | |
pause(0.1); | |
frame = getframe(h); | |
im = frame2im(frame); | |
[imind,cm] = rgb2ind(im,256); | |
if (~flag) | |
imwrite(imind,cm,filename,'gif', 'Loopcount',inf, 'DelayTime', 0.1); | |
flag=true; | |
else | |
imwrite(imind,cm,filename,'gif','WriteMode','append', 'DelayTime', 0.1); | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment