load('SCRN0003.TXT');
load('SCRN0004.TXT');
load('SCRN0005.TXT');
load('SCRN0006.TXT');
load('SCRN0007.TXT');
load('SCRN0008.TXT');
load('SCRN0009.TXT');
load('SCRN0010.TXT');
load('SCRN0011.TXT');
load('SCRN0012.TXT');
load('SCRN0013.TXT');
load('SCRN0014.TXT');
load('SCRN0015.TXT');
load('SCRN0016.TXT');
load('SCRN0017.TXT');
load('SCRN0018.TXT');

CommPLL_NoiseSpecRad_PLLBoost1Off_PDHBoost2Off(:,1) = vertcat(SCRN0006(:,1),SCRN0005(50:400,1),SCRN0004(50:400,1),SCRN0003(50:400,1)) .* 36 * pi/180;
CommPLL_NoiseSpecRad_PLLBoost1Off_PDHBoost2Off(:,2) = vertcat(SCRN0006(:,2),SCRN0005(50:400,2),SCRN0004(50:400,2),SCRN0003(50:400,2)) .* 36 * pi/180; 
CommPLL_NoiseSpecRad_PLLBoost1Off_PDHBoost2On(:,1) = vertcat(SCRN0010(:,1),SCRN0009(50:400,1),SCRN0008(50:400,1),SCRN0007(50:400,1))  .* 36 * pi/180;
CommPLL_NoiseSpecRad_PLLBoost1Off_PDHBoost2On(:,2) = vertcat(SCRN0010(:,2),SCRN0009(50:400,2),SCRN0008(50:400,2),SCRN0007(50:400,2))  .* 36 * pi/180; 
CommPLL_NoiseSpecRad_PLLBoost1On_PDHBoost2Off(:,1) = vertcat(SCRN0014(:,1),SCRN0013(50:400,1),SCRN0012(50:400,1),SCRN0011(50:400,1))  .* 36 * pi/180;
CommPLL_NoiseSpecRad_PLLBoost1On_PDHBoost2Off(:,2) = vertcat(SCRN0014(:,2),SCRN0013(50:400,2),SCRN0012(50:400,2),SCRN0011(50:400,2))  .* 36 * pi/180; 
CommPLL_NoiseSpecRad_PLLBoost1On_PDHBoost2On(:,1) = vertcat(SCRN0018(:,1),SCRN0017(50:400,1),SCRN0016(50:400,1),SCRN0015(50:400,1))   .* 36 * pi/180;
CommPLL_NoiseSpecRad_PLLBoost1On_PDHBoost2On(:,2) = vertcat(SCRN0018(:,2),SCRN0017(50:400,2),SCRN0016(50:400,2),SCRN0015(50:400,2))   .* 36 * pi/180; 

data(:,:,1)=CommPLL_NoiseSpecRad_PLLBoost1Off_PDHBoost2Off;
data(:,:,2)=CommPLL_NoiseSpecRad_PLLBoost1Off_PDHBoost2On;
data(:,:,3)=CommPLL_NoiseSpecRad_PLLBoost1On_PDHBoost2Off;
data(:,:,4)=CommPLL_NoiseSpecRad_PLLBoost1On_PDHBoost2On;
for i=1:4
    rms(:, i)=[(-1.*cumtrapz(flipud(data(:,1, i)), flipud(data(:, 2,i)).^2)).^(0.5)]';
end
rms=flipud(rms);
freq=data(:,1,1);

figure(2)
clf;
loglog(CommPLL_NoiseSpecRad_PLLBoost1Off_PDHBoost2Off(:,1), CommPLL_NoiseSpecRad_PLLBoost1Off_PDHBoost2Off(:,2),...
    CommPLL_NoiseSpecRad_PLLBoost1Off_PDHBoost2On(:,1),CommPLL_NoiseSpecRad_PLLBoost1Off_PDHBoost2On(:,2),...
    CommPLL_NoiseSpecRad_PLLBoost1On_PDHBoost2Off(:,1), CommPLL_NoiseSpecRad_PLLBoost1On_PDHBoost2Off(:,2),...
    CommPLL_NoiseSpecRad_PLLBoost1On_PDHBoost2On(:,1), CommPLL_NoiseSpecRad_PLLBoost1On_PDHBoost2On(:,2),...
    freq, rms(:,2))
grid on;
title('Comm PLL Error Signal');
xlabel('Frequency [Hz]');
ylabel('Amplitude Spectrum [rad/SqrtHz]');
legend('PLL Boost 1 Off, PDH Boost 2 Off',...
    'PLL Boost 1 Off, PDH Boost 2 On',...
    'PLL Boost 1 On, PDH Boost 2 Off',...
    'PLL Boost 1 On, PDH Boost 2 On',...
    'RMS PLL Boost 1 Off, PDH Boost 2 On', 'Location', 'SouthEast');
set(gcf, 'Color', 'w');

saveas(gcf, '/Users/alexastaley/Documents/Matlab/COMM PLL/Comm PLL Error Sig.pdf');

save('/Users/alexastaley/Documents/MATLAB/COMM PLL/CommPLL_NoiseSpecRad_PLLBoost1Off_PDHBoost2Off.txt','CommPLL_NoiseSpecRad_PLLBoost1Off_PDHBoost2Off', '-ascii');
save('/Users/alexastaley/Documents/MATLAB/COMM PLL/CommPLL_NoiseSpecRad_PLLBoost1Off_PDHBoost2On.txt','CommPLL_NoiseSpecRad_PLLBoost1Off_PDHBoost2On', '-ascii');
save('/Users/alexastaley/Documents/MATLAB/COMM PLL/CommPLL_NoiseSpecRad_PLLBoost1On_PDHBoost2Off.txt','CommPLL_NoiseSpecRad_PLLBoost1On_PDHBoost2Off', '-ascii');
save('/Users/alexastaley/Documents/MATLAB/COMM PLL/CommPLL_NoiseSpecRad_PLLBoost1On_PDHBoost2On.txt','CommPLL_NoiseSpecRad_PLLBoost1On_PDHBoost2On', '-ascii');