surface plasmon field scans an optical fiber field

Hi Everyone: I am attaching my code which is about a surface plasmon field scans an optical fiber located in a much bigger domain than the surface plamons field's domain. the scan result should be circle and centered at (0,0). However, it is shifted down by about 4microns for some reason. I hope someone can see the code and tell me if there is any error to fix.
Also, I will answer any questions about this problem so everyone interested in helping can have enough information.
clear all;
close all;
clc;
%%%%inputs%%%%%%%%%%% x1=-5:1e-3:5; y1=-5:1e-3:5; step=30; %step size 1=1nm; randomscannb=100; %%%%%%%%%%%%%%%%%%%%%
lambda0=1.31;
sfinalmatrix=size(x1);sfinalmatrix=sfinalmatrix(2);
% V=2*pi*a*NA/lambda0; % rf=a*(0.65+1.619/V^(3/2)+2.879/V^6); rf=((2.25)/2);
[X1,Y1]=meshgrid(x1,y1); Ey2a4=exp((-X1.^2-Y1.^2)/rf^2); Ey1a4=dlmread('K:\investigations for sweeping the position\New folder\ccccc_10t_10w_1nmstep.txt'); %248x;300y; Ey1a4c=conj(Ey1a4);
%display fields axis square; figure(1);subplot(1,2,1);imagesc(real(Ey1a4));title('Ey1a4 real part') axis square; figure(2);subplot(1,2,1);imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],real(Ey2a4));title('Ey2a4 real part');xlabel('um') axis square; figure(1);subplot(1,2,2);imagesc(imag(Ey1a4));title('Ey1a4 imag part') axis square; figure(2);subplot(1,2,2);imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],imag(Ey2a4));title('Ey2a4 imag part');xlabel('um')
fiberscan=Ey2a4+1;
selectedscan=round(rand(1,randomscannb)*(sfinalmatrix*sfinalmatrix)/(step^2));
match=0; %calculate overlap C=zeros(sfinalmatrix,sfinalmatrix); Norma = sum(sum(Ey2a4.*conj(Ey2a4)))*sum(sum(Ey1a4.*conj(Ey1a4))); tic c=0; %counter
for b=1:step:sfinalmatrix-300+1
for a=1:step:sfinalmatrix-248+1
c=c+1;
display(strcat('fractionexecuted=',num2str(c*(step^2)/(sfinalmatrix*sfinalmatrix))))
fib=Ey2a4(b:b+300-1,a:a+248-1);
C(b+150,a+124)=(sum(sum(conj(fib).*Ey1a4)))./sqrt(Norma);
for k=1:randomscannb
if c==selectedscan(k)
match=1;
end
end
if match==1
fiberscan(b:b+300,a:a+5)=0;
fiberscan(b:b+300,a+243:a+248)=0;
fiberscan(b:b+5,a:a+248)=0;
fiberscan(b+295:b+300,a:a+248)=0;
match=0;
end
end
end
toc
pack
result=abs(C);
%display fiberscan
figure(100);;imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],real(fiberscan));title('Ey2a4 with 100 random scan positions indicated');xlabel('um')
%fill in the blanks: if step>1 resultx=real(result)*0; for a=1:sfinalmatrix for b=1:sfinalmatrix if result(b,a)==0 elseif a>step+1 & b>step+1 & a<sfinalmatrix-step-1 & b<sfinalmatrix-step-1 hs=round(step/2); resultx(b-hs:b+hs,a-hs:a+hs)=0*result(b-hs:b+hs,a-hs:a+hs)+result(b,a); end end end else resultx=result; end
%display overlap axis square; figure(3);subplot(1,2,1);imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],real(resultx));title('real part of overalp');xlabel('um')
axis square; figure(3);subplot(1,2,2);imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],imag(resultx));title('imaginary part of overlap');xlabel('um') axis square;
% contourf(CC); % colorbar; % shading flat; % axis image; % axis square; % xlabel('x(\mum)', 'fontsize', 12); % ylabel('y(\mum)', 'fontsize', 12); %

Answers (4)

I do not know why my code looks that way. Can I upload a txt file here? if yes, please tell me how. thanks

6 Comments

In MATLAB, type control-A then control-i to fix up the indenting. Then control-c to copy it to the clipboard. Then paste it in to an edit box here. Make sure there's a blank line before your code. Then select/highlight all your code (but not the blank line before it) and click the {}Code button. All of the code will then look properly formatted.
I just followed your steps. Hopefully, the code will look much better. thanks a lot for helping!
clear all; close all; clc;
%%%%inputs%%%%%%%%%%% x1=-5:1e-3:5; y1=-5:1e-3:5; step=30; %step size 1=1nm; randomscannb=100; %%%%%%%%%%%%%%%%%%%%%
lambda0=1.31;
sfinalmatrix=size(x1);sfinalmatrix=sfinalmatrix(2);
% V=2*pi*a*NA/lambda0; % rf=a*(0.65+1.619/V^(3/2)+2.879/V^6); rf=((2.25)/2);
[X1,Y1]=meshgrid(x1,y1); Ey2a4=exp((-X1.^2-Y1.^2)/rf^2); Ey1a4=dlmread('K:\investigations for sweeping the position\New folder\ccccc_10t_10w_1nmstep.txt'); %248x;300y; Ey1a4c=conj(Ey1a4);
%display fields axis square; figure(1);subplot(1,2,1);imagesc(real(Ey1a4));title('Ey1a4 real part') axis square; figure(2);subplot(1,2,1);imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],real(Ey2a4));title('Ey2a4 real part');xlabel('um') axis square; figure(1);subplot(1,2,2);imagesc(imag(Ey1a4));title('Ey1a4 imag part') axis square; figure(2);subplot(1,2,2);imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],imag(Ey2a4));title('Ey2a4 imag part');xlabel('um')
fiberscan=Ey2a4+1;
selectedscan=round(rand(1,randomscannb)*(sfinalmatrix*sfinalmatrix)/(step^2));
match=0; %calculate overlap C=zeros(sfinalmatrix,sfinalmatrix); Norma = sum(sum(Ey2a4.*conj(Ey2a4)))*sum(sum(Ey1a4.*conj(Ey1a4))); tic c=0; %counter
for b=1:step:sfinalmatrix-300+1 for a=1:step:sfinalmatrix-248+1 c=c+1; display(strcat('fractionexecuted=',num2str(c*(step^2)/(sfinalmatrix*sfinalmatrix)))) fib=Ey2a4(b:b+300-1,a:a+248-1); C(b+150,a+124)=(sum(sum(conj(fib).*Ey1a4)))./sqrt(Norma);
for k=1:randomscannb
if c==selectedscan(k)
match=1;
end
end
if match==1
fiberscan(b:b+300,a:a+5)=0;
fiberscan(b:b+300,a+243:a+248)=0;
fiberscan(b:b+5,a:a+248)=0;
fiberscan(b+295:b+300,a:a+248)=0;
match=0;
end
end
end
toc
pack
result=abs(C);
%display fiberscan
figure(100);;imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],real(fiberscan));title('Ey2a4 with 100 random scan positions indicated');xlabel('um')
%fill in the blanks: if step>1 resultx=real(result)*0; for a=1:sfinalmatrix for b=1:sfinalmatrix if result(b,a)==0 elseif a>step+1 & b>step+1 & a<sfinalmatrix-step-1 & b<sfinalmatrix-step-1 hs=round(step/2); resultx(b-hs:b+hs,a-hs:a+hs)=0*result(b-hs:b+hs,a-hs:a+hs)+result(b,a); end end end else resultx=result; end
%display overlap axis square; figure(3);subplot(1,2,1);imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],real(resultx));title('real part of overalp');xlabel('um')
axis square; figure(3);subplot(1,2,2);imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],imag(resultx));title('imaginary part of overlap');xlabel('um') axis square;
% contourf(CC); % colorbar; % shading flat; % axis image; % axis square; % xlabel('x(\mum)', 'fontsize', 12); % ylabel('y(\mum)', 'fontsize', 12); %
No, it doesn't. You did something wrong (not exactly like I described).
clear all;
close all;
clc;
%%%%inputs%%%%%%%%%%%
x1=-5:1e-3:5;
y1=-5:1e-3:5;
step=30; %step size 1=1nm;
randomscannb=100;
%%%%%%%%%%%%%%%%%%%%%
lambda0=1.31;
sfinalmatrix=size(x1);sfinalmatrix=sfinalmatrix(2);
% V=2*pi*a*NA/lambda0;
% rf=a*(0.65+1.619/V^(3/2)+2.879/V^6);
rf=((2.25)/2);
[X1,Y1]=meshgrid(x1,y1);
Ey2a4=exp((-X1.^2-Y1.^2)/rf^2);
Ey1a4=dlmread('K:\investigations for sweeping the position\New folder\ccccc_10t_10w_1nmstep.txt');
%248x;300y;
Ey1a4c=conj(Ey1a4);
%display fields
axis square;
figure(1);subplot(1,2,1);imagesc(real(Ey1a4));title('Ey1a4 real part')
axis square;
figure(2);subplot(1,2,1);imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],real(Ey2a4));title('Ey2a4 real part');xlabel('um')
axis square;
figure(1);subplot(1,2,2);imagesc(imag(Ey1a4));title('Ey1a4 imag part')
axis square;
figure(2);subplot(1,2,2);imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],imag(Ey2a4));title('Ey2a4 imag part');xlabel('um')
fiberscan=Ey2a4+1;
selectedscan=round(rand(1,randomscannb)*(sfinalmatrix*sfinalmatrix)/(step^2));
match=0;
%calculate overlap
C=zeros(sfinalmatrix,sfinalmatrix);
Norma = sum(sum(Ey2a4.*conj(Ey2a4)))*sum(sum(Ey1a4.*conj(Ey1a4)));
tic
c=0; %counter
for b=1:step:sfinalmatrix-300+1
for a=1:step:sfinalmatrix-248+1
c=c+1;
display(strcat('fractionexecuted=',num2str(c*(step^2)/(sfinalmatrix*sfinalmatrix))))
fib=Ey2a4(b:b+300-1,a:a+248-1);
C(b+150,a+124)=(sum(sum(conj(fib).*Ey1a4)))./sqrt(Norma);
for k=1:randomscannb
if c==selectedscan(k)
match=1;
end
end
if match==1
fiberscan(b:b+300,a:a+5)=0;
fiberscan(b:b+300,a+243:a+248)=0;
fiberscan(b:b+5,a:a+248)=0;
fiberscan(b+295:b+300,a:a+248)=0;
match=0;
end
end
end
toc
pack
result=abs(C);
%display fiberscan
figure(100);;imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],real(fiberscan));title('Ey2a4 with 100 random scan positions indicated');xlabel('um')
%fill in the blanks:
if step>1
resultx=real(result)*0;
for a=1:sfinalmatrix
for b=1:sfinalmatrix
if result(b,a)==0
elseif a>step+1 & b>step+1 & a<sfinalmatrix-step-1 & b<sfinalmatrix-step-1
hs=round(step/2);
resultx(b-hs:b+hs,a-hs:a+hs)=0*result(b-hs:b+hs,a-hs:a+hs)+result(b,a);
end
end
end
else
resultx=result;
end
%display overlap
axis square;
figure(3);subplot(1,2,1);imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],real(resultx));title('real part of overalp');xlabel('um')
axis square;
figure(3);subplot(1,2,2);imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],imag(resultx));title('imaginary part of overlap');xlabel('um')
axis square;
% contourf(CC);
% colorbar;
% shading flat;
% axis image;
% axis square;
% xlabel('x(\mum)', 'fontsize', 12);
% ylabel('y(\mum)', 'fontsize', 12);
%
src=http://i40.tinypic.com/zsn8m8.jpg here is the overlap result I got after cancelling the dlmread and putting yours, the overlap is shifted in x and y now being more shifted in x and it is not a circle.

Sign in to comment.

hi Naema,
I tried the code, but i can not see the result because the data is missing , we do not have the folder : K:\investigations for sweeping the position\New folder\ccccc_10t_10w_1nmstep.txt
Therefore i propose that you post some numerical data from the text file,if it contains less than 100 elements, then copy and past them here, or past just part of them, or just post the size of the matrix Ey1a4 to simulate with other values (rand,randn, or from other ressources) .

15 Comments

But I told you how to find sites to upload your file in my Answer. Did you see it?
I want to upload all my txt file data so that you can see the result clearly. Can I upload all my txt file data?
ok, but do not accept the answer until it is solved.
Hi: I am sorry. I am not used to the forum. I know now. thanks!
tell me, the Ey2a4 has a structure as 2d Gaussian peak? as exp(-x²+y²)?
exactly, it is a fiber ( a Gaussian peak) and my txt file (Ey1a4)which I just uploaded is a complex field.
ok, Random complex field ~N(0,variance)? or the same as Ey2a4 but with complex part?
In the mean while try this way and give me your viewpoint :
Ey1a4=randn(248,300)+j*randn(248,300);
% instead of lmread
Ey1a4 is a surface plasmon field which is a complex field, Ey2a4 is a fiber field which is pure real. I need Ey1a4(the surface plasmon field to go over the fiber domain and scan going from the corner and scanning the whole box that contain the fiber. this is an overlap integral problem and the overlap result sould look exactly like the fiber because the surface plasmon field is tiny compared to the fiber field .
hi, do not accept the answer for other contributors, I tried to download the file, there are some errors in reading it, it only read 300x1 elements which gives a Peak for Ey2a4 at (0,0)um.
Thats the best i could do .
please let me know how to upload my txt file. I am stuck
hi, no the upload was correct, i have the problem of reading the file ok? so delete the accepted answer, and wait for other contributors
I could not delete the accepted answer. Please let me know how to do it.
where you accepted it , click on it again to undo the process or delete this question and post new one

Sign in to comment.

When I try to run it, it fails because I don't have the file:
The file 'K:\investigations for sweeping the position\New folder\ccccc_10t_10w_1nmstep.txt' could not be opened because: No such file or directory
clear all;
close all;
clc;
%%%%inputs%%%%%%%%%%%
x1=-5:1e-3:5;
y1=-5:1e-3:5;
step=30; %step size 1=1nm;
randomscannb=100;
%%%%%%%%%%%%%%%%%%%%%
lambda0=1.31;
sfinalmatrix=size(x1);sfinalmatrix=sfinalmatrix(2);
% V=2*pi*a*NA/lambda0;
% rf=a*(0.65+1.619/V^(3/2)+2.879/V^6);
rf=((2.25)/2);
[X1,Y1]=meshgrid(x1,y1);
Ey2a4=exp((-X1.^2-Y1.^2)/rf^2);
Ey1a4=dlmread('K:\investigations for sweeping the position\New folder\ccccc_10t_10w_1nmstep.txt');
%248x;300y;
Ey1a4c=conj(Ey1a4);
%display fields
axis square;
figure(1);subplot(1,2,1);imagesc(real(Ey1a4));title('Ey1a4 real part')
axis square;
figure(2);subplot(1,2,1);imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],real(Ey2a4));title('Ey2a4 real part');xlabel('um')
axis square;
figure(1);subplot(1,2,2);imagesc(imag(Ey1a4));title('Ey1a4 imag part')
axis square;
figure(2);subplot(1,2,2);imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],imag(Ey2a4));title('Ey2a4 imag part');xlabel('um')
fiberscan=Ey2a4+1;
selectedscan=round(rand(1,randomscannb)*(sfinalmatrix*sfinalmatrix)/(step^2));
match=0;
%calculate overlap
C=zeros(sfinalmatrix,sfinalmatrix);
Norma = sum(sum(Ey2a4.*conj(Ey2a4)))*sum(sum(Ey1a4.*conj(Ey1a4)));
tic
c=0; %counter
for b=1:step:sfinalmatrix-300+1
for a=1:step:sfinalmatrix-248+1
c=c+1;
display(strcat('fractionexecuted=',num2str(c*(step^2)/(sfinalmatrix*sfinalmatrix))))
fib=Ey2a4(b:b+300-1,a:a+248-1);
C(b+150,a+124)=(sum(sum(conj(fib).*Ey1a4)))./sqrt(Norma);
for k=1:randomscannb
if c==selectedscan(k)
match=1;
end
end
if match==1
fiberscan(b:b+300,a:a+5)=0;
fiberscan(b:b+300,a+243:a+248)=0;
fiberscan(b:b+5,a:a+248)=0;
fiberscan(b+295:b+300,a:a+248)=0;
match=0;
end
end
end
toc
pack
result=abs(C);
%display fiberscan
figure(100);;imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],real(fiberscan));title('Ey2a4 with 100 random scan positions indicated');xlabel('um')
%fill in the blanks:
if step>1
resultx=real(result)*0;
for a=1:sfinalmatrix
for b=1:sfinalmatrix
if result(b,a)==0
elseif a>step+1 & b>step+1 & a<sfinalmatrix-step-1 & b<sfinalmatrix-step-1
hs=round(step/2);
resultx(b-hs:b+hs,a-hs:a+hs)=0*result(b-hs:b+hs,a-hs:a+hs)+result(b,a);
end
end
end
else
resultx=result;
end
%display overlap
axis square;
figure(3);subplot(1,2,1);imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],real(resultx));title('real part of overalp');xlabel('um')
axis square;
figure(3);subplot(1,2,2);imagesc([x1(1) x1(sfinalmatrix)],[y1(1) y1(sfinalmatrix)],imag(resultx));title('imaginary part of overlap');xlabel('um')
axis square;
% contourf(CC);
% colorbar;
% shading flat;
% axis image;
% axis square;
% xlabel('x(\mum)', 'fontsize', 12);
% ylabel('y(\mum)', 'fontsize', 12);
%

Categories

Asked:

on 27 May 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!