% close all
clear all
clc

%%
printFigs = true;

dataDir = '/ligo/home/carl.blair/gpib/netgpibdata/';
dataFile = 'dataSPSR785_24-07-2016_212424.txt';
resultsDir = '/ligo/home/jeffrey.kissel/2016-08-19/';

%%
 [freq_Hz,asd] = textread([dataDir dataFile],'%f %f','headerlines',30);
 
 freq_kHz = freq_Hz/1000;
 
 [amp,ind] = max(asd);
 [pks,locs] = findpeaks(asd,'minpeakheight',2.7e-6,'minpeakdistance',10);
 
%%
adcNoise =  3.6621e-06; % V/rtHz (above ~1e3 Hz); derived from G1300997, pg 44&45 * 40/2^16 [V/ct].
 
%%
figure(1)
ll = semilogy(freq_kHz,asd,...
         freq_kHz,adcNoise*ones(size(freq_kHz)),'--',...
         freq_kHz(ind),amp,'*',...
         freq_kHz(locs),pks,'s');
set(ll(3),'MarkerSize',16)
legend('Raw SR785 Data',...
       'Gen. Standards ADC Noise (6.3e-6 [V/rtHz])',...
       ['(' num2str(freq_kHz(ind),5) ' [kHz],' num2str(amp,3) ' [V/rtHz])'],...
       'Other Transient PI Modes or Mode Groups')
 xlim([60 73])
 ylim([8e-7 1e-5])
 set(gca,'XTick',60:73,'YTick',10.^(-6:-5));
 xlabel('Frequency [kHz]')
 ylabel('Amplitude [V/rtHz]')
 tt = title({'H1 TMSY QPD ASD, 2016-07-24 21:24:53 UTC';...
             ['FileName: ' dataFile]});
set(tt,'Interpreter','none')         
 
%%
if printFigs
    figure(1)
    FillPage('w')
    IDfig(', J. Kissel')
    saveas(gcf,[resultsDir dataFile(1:(end-4)) '.pdf'])
end