Matlab Code

function [BA,BB]=fitwaveplate(vA,vB)
%fitwaveplate function fits the measured intensities at port A and B as a
%function of theta to find the phase retardance of a waveplate.
%vA, and vB are 2 by N matrices whose first colum is angular postion theta
%and second column is measured intensity.

%initialize first guess of fitting parameters
thetanot=-0;
A=25;
phiR= 90;
BA=[thetanot,A, phiR ];

%Find fitting paramters than minimize least squared difference
BA=nlinfit(vA(:,1),vA(:,2),@portA,BA);
BB=nlinfit(vB(:,1),vB(:,2),@portB,BA);

%plot results
plot(vA(:,1),vA(:,2),'s');
title('Waveplate Fit');
ylabel('Power [mW]');
hold on
Y=portA(BA,1:360);
plot(1:360,Y,'r');
hold on
plot(vB(:,1),vB(:,2),'d');
xlabel('Waveplate Angle \theta');
hold on
Y=portB(BB,1:360);
plot(1:360,Y,'g');

h = legend('Port A Data','Port A Fit','Port B Data','Port B Fit',4);
set(h,'Interpreter','none');

end
function y=portA(b,X)
%returns vector y (intensity at port A) given paramter set b and vector containing angular
%positions X

N=length(X);

for i = 1:N

y(i)=abs(b(2)*(sin(pi/180*(b(1)+X(i)))^2+cos(pi/180*(b(1)+X(i)))^2*exp(-j*pi/180*b(3))))^2;
end
y=y';
end
function y=portB(b,X)
%returns vector y (intensity at port B) given paramter set b and vector containing angular
%positions X

N=length(X);

for i = 1:N

y(i)=abs(b(2)*(cos(pi/180*(b(1)+X(i)))*sin(pi/180*(b(1)+X(i)))*(1-exp(-j*pi/180*b(3)))))^2;
end
y=y';
end

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License