%gpsSec=GWData.datenum_to_gps('Mar 03 2019 11:16:00');
gpsSec=1235814048;
duration=30;

[freqs, tt, chans, nicknames]=getOscFrequencies(gpsSec, duration);

%%
% first, just a two-frequency mixing
[N, M]=size(freqs);
mix2=zeros(N, M*(M-1)/2);
indice={};
cols=0;
for ii=1:(M-1)
    for jj=(ii+1):M
        column=(freqs(:,ii)-freqs(:, jj));
        if min(abs(column))<24e3
            cols=cols+1;
            mix2(:, cols)=column;
            indice{cols}=[ii, jj];
        end
    end
end

%% seems like the measurement is once per second.
% find when the value changes in the first interesting pair

for ii=2:N
    if (freqs(ii, indice{1}(1))-freqs(ii, indice{1}(2)))~=(freqs(ii-1, indice{1}(1))-freqs(ii-1, indice{1}(2)))
        boundary=ii;
        break;
    end
end
tt=tt(boundary:16:end);
mix2=mix2(boundary:16:end, :);

%%
for ii=1:length(indice)
    figure
    plot(tt, mix2(:, ii), '.');
    grid on
    xlabel(['sec starting ', num2str(gpsSec)])
    ylabel('Hz')
    title([nicknames{indice{ii}(1)}, ' - ', nicknames{indice{ii}(2)}])
end

%%
open('IMC_F_PRCL_arches.fig');
subplot 211
hold on
colors='rbgkyc';
for ii=1:length(indice)
    plot(tt-0.5, min([abs(mix2(:, ii)), abs(abs(mix2(:,ii))-2^14)], [], 2), ['o-', colors(ii)]);
end

%%
for ii=1:length(indice)
    open('IMC_F_PRCL_arches.fig');
    subplot 211
    hold on
    plot(tt-0.5, min([abs(mix2(:, ii)), abs(abs(mix2(:,ii))-2^14)], [], 2), ['o', colors(ii)]);
end
%%
for ii=1:length(indice)
    open('OMC_PI_arches.fig');
    hold on
    plot(tt-0.5, abs(mix2(:, ii)), ['o', colors(ii)]);
end