Created
October 6, 2018 01:13
-
-
Save mpreciado/787d7dfe9abe2f2e6b73abe340c94691 to your computer and use it in GitHub Desktop.
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
%% PARAMETERS | |
BeamAngle=90; | |
lambda=500e-9; %green wavelength 500 nm | |
%% | |
c=2.9979e8; %speed of light | |
xx=2e-6*(-1:0.01:1); | |
zz=2e-6*(-1:0.01:1); | |
[Z X]=meshgrid(zz,xx); | |
k0=2*pi/lambda; | |
kx=k0*sind(BeamAngle); | |
kz=k0*cosd(BeamAngle); | |
freq0=c/lambda; | |
w0=2*pi*freq0; | |
tt=(0:0.1:0.9)/freq0; | |
h=figure(234); | |
filename = sprintf('testAnimated_%.1f.gif',BeamAngle); | |
for(t=tt) | |
planeWavefun=cos(kx*X+kz*Z-w0*t); | |
imagesc(xx*1e6,zz*1e6,planeWavefun); | |
title(sprintf('Plane wave, \\lambda=%d nm, angle=%.1f deg.',lambda*1e9,BeamAngle)); | |
xlabel('z [\mum]'); | |
ylabel('x [\mum]'); | |
colormap jet; | |
axis image; | |
shg;pause(0.1);drawnow; | |
frame = getframe(h); | |
im = frame2im(frame); | |
[imind,cm] = rgb2ind(im,256); | |
% Write to the GIF File | |
if t == 0 | |
imwrite(imind,cm,filename,'gif', 'DelayTime',0.1, 'Loopcount',inf); | |
else | |
imwrite(imind,cm,filename,'gif', 'DelayTime',0.1,'WriteMode','append'); | |
end | |
end | |
%% | |
t=0; | |
planeWavefun=cos(kx*X+kz*Z-w0*t); | |
h2=figure(232); | |
subplot(1,3,1:2) | |
imagesc(xx*1e6,zz*1e6,planeWavefun); | |
title(sprintf('Plane wave, \\lambda=%.1f nm, angle=%.1f deg.',lambda,BeamAngle)); | |
xlabel('z [\mum]'); | |
ylabel('x [\mum]'); | |
colormap jet; | |
hold on; | |
plot([0 0],1e6*[min(xx) max(xx)],'w:','linewidth',2); | |
hold off; | |
axis image; | |
subplot(1,3,3) | |
plot(cos(kx*xx-w0*t),zz*1e6); axis tight; xlim([-1 1]); | |
ylabel('x [\mum]'); | |
xlabel('Electric field @ z=0, t=0 [a.u.]'); | |
set(gca,'Ydir','reverse'); | |
set(gca,'xdir','reverse'); | |
set(gca,'YAxisLocation', 'Right'); | |
frame = getframe(h2); | |
im = frame2im(frame); | |
[imind,cm] = rgb2ind(im,256); | |
% Write to the GIF File | |
filename = sprintf('testAnimated_%.1f.png',BeamAngle); | |
imwrite(imind,cm,filename,'png'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment