clc
clear
close all

%run necessary package
run /users/swinkels/deploy/MatlabVirgoTools/trunk/startup.m
%load gps time for the data we want
gps1 = 1336699120;
gps2 = 1337022340;
%the time length [s] we will use after the gps starting time
len1 = 20000;
len2 = 5000;

name = 'LFC_SC_PD_RF_11MHz_I_CAL_mean';

[data1, t1]= getChannel('trend', name, gps1, len1);
[data2, t2]= getChannel('trend', name, gps2, len2);

%%
fs1 = 1 / (t1(2) - t1(1));
nav = 10;
dur = 2000;
npoints = dur*fs1;
npt = 2^floor(log(2*npoints/nav)/log(2));
[p1, f1] = pwelch(data1, hann(npt), [], npt, fs1);
[p2, f2] = pwelch(data2, hann(npt), [], npt, fs1);
loglog(f1, p1, f2, p2)
xlabel('Frequency [Hz]')
ylabel('Magnitude [Hz/rt(Hz)]')
xlim([0.004 0.5])
legend('no filter (measured on 16th May)', 'using new filter (measured on 19th May)')
title('Error signal spectrum of the filter cavity SC lock')
grid()


