%1611 photodiode with 20dB amplifier at AS_REFL on ISCT6
%signal read into spectrum analyzer with michelwson locked to the bright fringe. 
%10kHz resolution bandwidth, 801 points
%measurement.  Noise floor at -70dBm.

%we measured with auxiliary laser offset on one side of the carrier, then
%moved to the other side. when measuring side 2 maybe michelson was not 
%aligned as well because all of the measured values were lower than for
%side_1.  We are planning to go back and repeat this side.

%auxiliary laser offset controlled on H1:LSC_EXTRA_AO_2 about 4V, amplified
%by SN560.  We needed roughly 4V to see a beat note, and moved around by
%0.05 V divisions
%beat note from ISCT2R table 1611PD rerouted to ISCT6 on rack feedthroughs
%(ISCR2 to ISCR4 or something, with something in the middle?)

freq_amp_side1=[ ...
    940.38 -54.18 %MHz, dBm
    940.56  -53.96
    940.75  -54.137
    954.6   -55
    983.125 -52.651
    941.875 -54.7
    886.475 -60.7
    872.31  -60.11
    844.81  -59.3
    845     -59
    845     -62.4
    824.75  -56
    803.6   -58.7
    803.625 -60
    776.25  -58
    757.7   -57.9
    736.6   -59.0
    709.18  -57.4
    709.18  -55.5
    689.125 -54.6
    666.6   -53.2
    668.3   -53.5
    ];

freq_amp_side2=[ ...
    701.625 -57.5
    701.4   -58.0
    729.6   -59.3
    729.75  -59.1
    771.9   -63.1
    771.9   -64.0
    %820.938 nan %-69     %beneath -69dBm noise floor
    771.3   -64.1
    %820.18  nan %-69     %beneath -69dBm noise floor
    %867     nan %-69     %beneath -69dBm noise floor
    910.7   -62.74
    951.38  -58.38
    952.5   -59.2
    1000.0   -57.2
    ];

offset=0;
%define some extra variables to use in cftool.
freq_side1=freq_amp_side1(:,1)-offset;
amp_side1=freq_amp_side1(:,2);
freq_side2=freq_amp_side2(:,1)-offset;
amp_side2=freq_amp_side2(:,2);

FIT1=fitlm(freq_side1,amp_side1,'purequadratic') %p1*x^2+p2*x+p3, least squares linear regression
FIT2=fitlm(freq_side2,amp_side2,'purequadratic')

minimum1= -FIT1.Coefficients{2,1}/2/FIT1.Coefficients{3,1} +offset %-p2/2/p1 + offset
sdtErr_min1=minimum1*sqrt((FIT1.Coefficients{2,2}/FIT1.Coefficients{2,1})^2+(FIT1.Coefficients{3,2}/FIT1.Coefficients{3,1})^2)

minimum2= -FIT2.Coefficients{2,1}/2/FIT2.Coefficients{3,1} +offset %-p2/2/p1 + offset
sdtErr_min2=minimum2*sqrt((FIT2.Coefficients{2,2}/FIT2.Coefficients{2,1})^2+(FIT2.Coefficients{3,2}/FIT2.Coefficients{3,1})^2)

ls1=acos(0)*3e8/2/pi/minimum1/1e6
d_ls1=acos(0)*3e8/2/pi/1e6*sdtErr_min1/1e6
ls2=acos(0)*3e8/2/pi/minimum2/1e6
d_ls2=acos(0)*3e8/2/pi/1e6*sdtErr_min2/1e6

schnupp_asy=ls1/2+ls2/2



figure(1301);
plot(freq_amp_side1(:,1),freq_amp_side1(:,2),'r+')
hold on
%plot(freq_amp_side2(:,1),freq_amp_side2(:,2),'bo')
plot(-freq_amp_side2(:,1),freq_amp_side2(:,2),'bo')
hold off
xlabel('frequency (MHz)')
ylabel('auiliary beam power on ISCT6 (dBm)')

    