%
% rephasing of the signal with the inverse filter
%
inverse_filter = load('inv_anti_aliasing_10Hz.txt');
transient_length = round((length(inverse_filter)-1)/2);
%
signal=load('inline_polar_37days_file1.dat');
system('nedit Hinline_polar_37days_file1.dat &');
border=30;
signal_rectified=zeros(size(signal,1)-2*border,size(signal,2));
for j=1:size(signal,1)-2*border
    signal_rectified(j,1)=signal(j+border,1); % no need to rephase the GPS Time
end
for i=2:3
    signal_temp=conv(signal(:,i),inverse_filter);
    for j=1:size(signal,1)-2*border
        signal_rectified(j,i)=signal_temp(j+transient_length+border);
    end
end
save -ascii -double 'inline_polar_37days_file1_rectified.dat' signal_rectified

% PLOTS

% SS_DistanceMeasurementError

figure
plot(signal(:,1),signal(:,2),'b')
hold on
plot(signal_rectified(:,1),signal_rectified(:,2),'c')
xlabel('time [s]')
ylabel('SS\_DistanceMeasurementError [m]')
legend('signal filtered','signal rephased')

% NonGravDiffAccelMeasErr

figure
plot(signal(:,1),signal(:,3),'b')
hold on
plot(signal_rectified(:,1),signal_rectified(:,3),'c')
xlabel('time [s]')
ylabel('NonGravDiffAccelMeasErr [m/s^2]')
legend('signal filtered','signal rephased')