noLight=-0.26; 
straitShot=46.06;
norm=700;
orig=0.8; %gues at original modulation depth
Car=[491.3, 620.34, 664];
Car1=[491.3, 620.34];
SB=[184, 81.67];
ratio=SB./Car1;
ModDepth=[1, 0.5, 0.25];
ModDepth2=[1, 0.5];
ModDepthScale=[1, 0.5];
Gamma=0:0.01:1;
CarrPredict=@(Gamma)((besselj(0,Gamma)).^2);
SBPredict=@(Gamma)(2*(besselj(1,Gamma)).^2);
ratioPredict=@(Gamma)SBPredict(Gamma)./CarrPredict(Gamma);


%cost function to solve for Gamma
ratioPredictScale=@(Gamma)((ratioPredict(Gamma)-ratio(1))^2+(ratioPredict(Gamma/2)-ratio(2))^2);

GammaSolve=fminsearch(@(Gamma)ratioPredictScale(Gamma), 0.8) 

%cost function for normalization
NormCost=@(norm)((besselj(0,GammaSolve)).^2-Car(1)/norm).^2+...
    ((besselj(0,GammaSolve/2)).^2-Car(2)/norm).^2+...
    ((besselj(0,GammaSolve/4)).^2-Car(3)/norm).^2;


norm=fminsearch(@(norm)NormCost(norm), 700); %fit for the trans power with original modulation depth

h1=figure(1);
subplot(2,1,1)
plot(Gamma, CarrPredict(Gamma), GammaSolve.*ModDepth, Car./norm, 'o')
ylabel('Normalized Carrier Power')
subplot(2,1,2)
plot(Gamma, SBPredict(Gamma), GammaSolve.*ModDepth2, SB./norm, 'o')
xlabel('Modulation Depth Gamma')
ylabel('Normalized Sideband Power')
print(h1, '-djpeg', 'ModDepthPow')


scale1=0.8;
h2=figure(2);
plot(Gamma, ratioPredict(Gamma), GammaSolve*ModDepth2, ratio, 'o')
xlabel('Modulation Dpeth Gamma')
ylabel('Ratio of SB power to Carrier Power')
print(h2, '-djpeg', 'ModDepthRatio')

% syms x
% solve(besselj(1, x)./besselj(1,x)==sqrt(ratio(1)/2), x)
% 
Gain=@(Gamma)besselj(0,Gamma).*besselj(1,Gamma);

figure(3)
plot(Gamma, Gain(Gamma))
xlabel('Modulation Depth')
ylabel('Proportional to PDH gain')

% we changed the modulation depth from 0.8 to 0.2, so we have changed the
% gain by:
GainChange=20*log10(Gain(0.8)/Gain(0.2))