load('SCRN0410.TXT');
load('SCRN0411.TXT');
load('SCRN0412.TXT');
load('SCRN0413.TXT');
load('SCRN0414.TXT');
load('SCRN0415.TXT');
load('SCRN0416.TXT');
load('SCRN0417.TXT');
load('SCRN0418.TXT');
load('SCRN0419.TXT');

EX_PLL_NoiseSpecV_BoostOn(:,1) = vertcat(SCRN0417(:,1),SCRN0416(100:800,1),SCRN0415(100:800,1),SCRN0414(100:800,1));
EX_PLL_NoiseSpecV_BoostOn(:,2) = vertcat(SCRN0417(:,2),SCRN0416(100:800,2),SCRN0415(100:800,2),SCRN0414(100:800,2)); 
EX_PLL_NoiseSpecRad_BoostOn(:,1) = EX_PLL_NoiseSpecV_BoostOn(:,1);
EX_PLL_NoiseSpecRad_BoostOn(:,2) = EX_PLL_NoiseSpecV_BoostOn(:,2) .* 36 * pi/180;

EX_PLL_NoiseSpecV_BoostOff(:,1) = vertcat(SCRN0410(:,1),SCRN0411(100:800,1),SCRN0412(100:800,1),SCRN0413(100:800,1)); 
EX_PLL_NoiseSpecV_BoostOff(:,2) = vertcat(SCRN0410(:,2),SCRN0411(100:800,2),SCRN0412(100:800,2),SCRN0413(100:800,2)); 
EX_PLL_NoiseSpecRad_BoostOff(:,1) = EX_PLL_NoiseSpecV_BoostOff(:,1);
EX_PLL_NoiseSpecRad_BoostOff(:,2) = EX_PLL_NoiseSpecV_BoostOff(:,2) .* 36 * pi/180;

EX_PLL_NoiseSpecRad_BoostOn_GainM5(:,1) = SCRN0418(:,1);
EX_PLL_NoiseSpecRad_BoostOn_GainM5(:,2) = SCRN0418(:,2) .* 36 * pi/180;
EX_PLL_NoiseSpecRad_BoostOn_GainP3(:,1) = SCRN0419(:,1);
EX_PLL_NoiseSpecRad_BoostOn_GainP3(:,2) = SCRN0419(:,2) .* 36 * pi/180;

data(:,:,1)=EX_PLL_NoiseSpecRad_BoostOn;
data(:,:,2)=EX_PLL_NoiseSpecRad_BoostOff;
for i=1:2
    rms(:, i)=[(-1.*cumtrapz(flipud(data(:,1, i)), flipud(data(:, 2,i)).^2)).^(0.5)]';
end
rms=flipud(rms);
freq=data(:,1,1);

figure(1)
clf;
loglog(EX_PLL_NoiseSpecRad_BoostOff(:,1), EX_PLL_NoiseSpecRad_BoostOff(:,2),...
    EX_PLL_NoiseSpecRad_BoostOn(:,1),EX_PLL_NoiseSpecRad_BoostOn(:,2),...
    EX_PLL_NoiseSpecRad_BoostOn_GainM5(:,1), EX_PLL_NoiseSpecRad_BoostOn_GainM5(:,2),...
    EX_PLL_NoiseSpecRad_BoostOn_GainP3(:,1), EX_PLL_NoiseSpecRad_BoostOn_GainP3(:,2),...
    freq, rms(:,1),'g--',...
    freq, rms(:,2),'b--')
grid on;
title('PLL Error Signal');
xlabel('Frequency [Hz]');
ylabel('Amplitude Spectrum [rad/SqrtHz]');
legend('Boost 1 Off, Gain 0dB', 'Boost 1 On, Gain 0dB', 'Boost 1 On, Gain -5dB', 'Boost 1 On, Gain 3dB','RMS Boost 1 On', 'RMS Boost 1 Off','Location', 'SouthWest');
set(gcf, 'Color', 'w');

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


save('/Users/alexastaley/Documents/MATLAB/EX_PLL_DATA/EX_PLL_NoiseSpecRad_BoostOn.txt','EX_PLL_NoiseSpecRad_BoostOn', '-ascii');
save('/Users/alexastaley/Documents/MATLAB/EX_PLL_DATA/EX_PLL_NoiseSpecRad_BoostOff.txt','EX_PLL_NoiseSpecRad_BoostOff', '-ascii');
save('/Users/alexastaley/Documents/MATLAB/EX_PLL_DATA/EX_PLL_NoiseSpecRad_BoostOn_GainM5.txt','EX_PLL_NoiseSpecRad_BoostOn_GainM5', '-ascii');
save('/Users/alexastaley/Documents/MATLAB/EX_PLL_DATA/EX_PLL_NoiseSpecRad_BoostOn_GainP3.txt','EX_PLL_NoiseSpecRad_BoostOn_GainP3', '-ascii');