clear;
% close all;
set(0,'defaulttextinterpreter','none')

addpath /ligo/svncommon/NbSVN/aligonoisebudget/trunk/Externals/SimulinkNb/Utils/
addpath /ligo/svncommon/SeiSVN/seismic/Common/MatlabTools/
%% configure nds
gwd = GWData();
gwd.make_kerberos_ready;
gwd.site_info(2).port = 8088;
gwd.site_info(2).server = 'h1nds1';
% startTime1 = 1162386017 ;
% startTime1 = 1173228343-9*3600 ; %march high wind
startTime1 = 1199750000-1.5*3600 ; %march low wind

duration1 =3600;
datarate=128;
%%
channelETMX = {'H1:ISI-ETMX_ST1_T240INF_Z1_IN1_DQ',...1
'H1:ISI-ETMX_ST1_T240INF_Z2_IN1_DQ',...2
'H1:ISI-ETMX_ST1_T240INF_Z3_IN1_DQ',...3
'H1:ISI-ETMX_ST1_T240INF_X1_IN1_DQ',...1
'H1:ISI-ETMX_ST1_T240INF_X2_IN1_DQ',...1
'H1:ISI-ETMX_ST1_T240INF_X3_IN1_DQ',...1
'H1:ISI-ETMX_ST1_BLND_X_T240_CUR_IN1_DQ',...
'H1:ISI-ETMX_ST1_BLND_Y_T240_CUR_IN1_DQ',...

};

[ETMX_T240inf_data, tIn, ~] =gwd.fetch(startTime1,duration1,channelETMX,datarate);

%%
% [gnd_T240_X_asd, gnd_T240_tiltcorrected_asd, freq, fit_vect] = ...
%             mccs2(gnd_T240_X, [gnd_BRS_RY], 1/512, 9, 1, @hann);

[Z1_asd Z1_Z2_sub_asd, freq, Z1_Z2_fit]=mccs2(ETMX_T240inf_data(:,1),ETMX_T240inf_data(:,2),1/datarate,9);

[Z2_asd Z2_Z3_sub_asd, freq, Z2_Z3_fit]=mccs2(ETMX_T240inf_data(:,2),ETMX_T240inf_data(:,3),1/datarate,9);

[Z3_asd Z3_Z1_sub_asd, freq, Z3_Z1_fit]=mccs2(ETMX_T240inf_data(:,3),ETMX_T240inf_data(:,1),1/datarate,9);


%%

figure(1)
subplot(211)
loglog(freq,[Z1_asd Z2_asd Z3_asd],'linewidth',3);
title('ETMX T240 Z1-2-3','fontsize',24)
ylabel('nm/s/rthz','fontsize',16)
xlabel('hz','fontsize',16)
grid on;
leg=legend('Z1','Z2','Z3')
set(leg,'fontsize',16)
xlim([.005 10])

subplot(212)

loglog(freq,[Z1_Z2_sub_asd Z2_Z3_sub_asd Z3_Z1_sub_asd],'linewidth',3);
title('MCCS2 coherent subtraction','fontsize',24)
ylabel('nm/s/rthz','fontsize',16)
xlabel('hz','fontsize',16)
xlim([.005 10])

grid on;
leg=legend('Z1-Z2','Z2-Z3','Z3-Z1')
set(leg,'fontsize',16)
