%simple IMC loop model to double check calibrations

%2.4 V pp PDH signal measured at OUT2 with 2 Watts input power, after IN1 gain slider which had 15dB gain, 8812 Hz cavity pole

error_slope=(2.4/8812)*zpk([],2*pi*[8812],2*pi*8812); %volts per Hz

comp_filt=zpk(2*pi*[4e3],2*pi*[40],1);
boost_1=zpk(2*pi*[20e3],2*pi*[1e3],1);
high_pass=zpk(2*pi*[70e3], 2*pi*[140e3],2);
fast_option=zpk([],2*pi*[200e3], 2*pi*200e3);
fast_gain=0;

CMboard=comp_filt*boost_1*boost_1*db2mag(fast_gain)*high_pass*fast_option; 
VCO=zpk(2*pi*[40], 2*pi*[1.6],536600*(1.6/40)); % Hz per Volt factor of 2 for double pass


IMC_OLG=error_slope.*CMboard*VCO;

P=bodeoptions;
P.FreqUnits;
P.Grid='on';
P.MagUnits='abs';
P.MagScale='log';
P.FreqUnits='Hz';
P.XLim=([0.1, 1e6]);
P.XLimMode='manual';
figure(1)
bodeplot(IMC_OLG,P)


%when we do analog CARM, we loose 6dB of fast gain, move to in1 gain so
%calibration of AO input into Hz get a factor of 2
Hz_per_volt_in1=(8812)/(2*2.4)  
AO_gain=db2mag(-24);
