clear all
close all

%%
meas1= ...
    [172.5, 2.377; ... % deg, mW
    174, 2.366; ...
    167, 2.374;...
    168, 2.391;...
    169, 2.384;...
    170, 2.396;...
    171, 2.384;...
    172, 2.376;... % (was 2.377 originally, it seems very stable)
    174, 2.369; ...
    178, 2.344; ...
    185, 2.176; ...
    183, 2.271; ...
    170, 2.406; ...
    169-1/4, 2.404; ...
    168-12.5/60, 2.407; ...
    167-1/6, 2.383; ...
    165, 2.387; ...
    163, 2.351; ...
    161, 2.334; ...
    157+42.5/60, 2.304; ...
    155, 2.255; ...
    152, 2.151; ...
    170, 2.389; ...
    169-1/6, 2.391]; %last line is horizontally "retroreflecting" as good as I can eyeball using a card with a punched hole, but there was still pit misalignment of the sensor.
% There's no pit adjustment, and the reflection was down by ~5mm over 110mm.
poff1=180/pi*atan2(5, 110)/2;
center1=meas1(end,1);
angle1=sqrt((meas1(:,1)-center1).^2+poff1^2).*sign(meas1(:,1)-center1);
angle1(end,1)=poff1;

% manually Fine-adjusted pit
% eyeballing retroreflection: 168+25/60
meas2=[ ...
    168+25/60, 2.370;...
    168, 2.358;...
    167, 2.399; ...
    165+3/4, 2.398; ...
    165+5/60, 2.325; ...
    163.5 , 2.350;...
    161+3/4, 2.312;...
    168+5/6, 2.364;...
    170, 2.394;...
    171, 2.350;...
    172, 2.389;... %this is hugely misaligned in YAW
    168+25/60, 2.360]; %back to retro-reflection using a card with a hole. happened to be the same angle as before! within .5mm over 110mm.
    %background 1.89uW
angle2=meas2(:,1)-meas2(1,1);
    
maxmax=max([meas1(:,2);meas2(:,2)]);
figure
plot(meas1(:,1), meas1(:,2)/maxmax, 'ro');
hold on
plot(meas2(:,1), meas2(:,2)/maxmax, 'bx');
grid on
xlabel('Horizontal rotation (deg)')
title('Normalized sensitivity for vertically polarized light VS YAW angle, raw data')
legend(['Initial angle scan, pit offset= ', num2str(poff1), 'deg, horizontally "retroreflects" at ', num2str(center1), 'deg'], '2nd scan, retroreflects at 168.42 deg', 'location', 'south')



figure
plot(angle1, meas1(:,2)/maxmax, 'ro');
hold on
plot(angle2, meas2(:,2)/maxmax, 'bx');
grid on
title('Normalized sensitivity for vertically polarized light VS AOI')
xlabel('AOI (deg)')
legend('Initial scan, pit offset taken into account', '2nd scan, no pit offset', 'location', 'south')
%%
%position scan with nominally retro-reflection
meas3=[...
    10.15, 2.359;... % mm, mW, this is the same pos with the last line of meas 2.
    10.65, 2.372; ...
    11.15, 2.386;...
    11.65, 2.383;...
    12.15, 2.39;
    12.65, 2.387;
    13.15, 2.379;
    13.65, 2.378;
    14.15, 2.374;%almost clipping
    10.15, 2.350;%back to neutral
    9.65, 2.387;
    9.15, 2.382;
    8.65, 2.363;
    8.15, 2.361;
    7.65, 2.358;
    7.15, 2.355;
    6.65, 2.345]; %almost clipping]
    %background 1.93uW.

figure
plot(meas3(:,1), meas3(:,2)/max(meas3(:,2)), 'ro');
grid on
title('Normalized sensitivity VS spot position')
xlabel('mm')