Home > reduc > fitNTPOffsetSouth.m

fitNTPOffsetSouth

PURPOSE ^

this function uses the recorded times of the 1PPS gps to get the correct UTC values

SYNOPSIS ^

function d = fitNTPOffsetSouth(d,servoPPSFlag)

DESCRIPTION ^

this function uses the recorded times of the 1PPS gps to get the correct UTC values

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function d = fitNTPOffsetSouth(d,servoPPSFlag)
0002 
0003 %this function uses the recorded times of the 1PPS gps to get the correct UTC values
0004 
0005 if(isfield(d.antenna0.roach1, 'ntpUSeconds'))
0006     roachOffset= d.antenna0.roach1.ntpUSeconds([1:100:length(d.antenna0.roach1.ntpUSeconds)]);
0007     servoOffset = d.antenna0.servo.ntpUSecond([1:5:length(d.antenna0.servo.ntpUSecond)]);
0008 else 
0009     d.antenna0.roach1.ntpUSeconds=zeros(length(d.antenna0.roach1.utc),1);
0010     d.antenna0.servo.ntpUSecond=zeros(length(d.antenna0.roach1.utc)./20,1);
0011     roachOffset= d.antenna0.roach1.ntpUSeconds([1:100:length(d.antenna0.roach1.ntpUSeconds)]);
0012     servoOffset = d.antenna0.servo.ntpUSecond([1:5:length(d.antenna0.servo.ntpUSecond)]);
0013 end
0014 t0Roach=d.antenna0.roach1.utc(1);% we start this from the roach time
0015 t0Servo=d.antenna0.roach1.utc(1); % we also use the roach time for this since the two are supposed to be taken on the edge of a second
0016 
0017 
0018 tendRoach=d.antenna0.roach1.utc(length(d.antenna0.roach1.ntpUSeconds));
0019 roachArray=[0:length(d.antenna0.roach1.ntpUSeconds)-1]./100; %create an array for the roachTimes
0020 servoArray=[0:length(d.antenna0.servo.ntpUSecond)-1]./5; %create an array for the servoTimes
0021 
0022 
0023 servoIndex=[1:5:5*(length(servoOffset))]';
0024 P=polyfit(servoIndex,servoOffset,2);
0025 
0026 servoIndex2=[1:length(servoArray)];
0027 %do we use PPS correction for the servo or not?
0028 if(servoPPSFlag==1)
0029     servoPPSCorrection=polyval(P,servoIndex2);
0030 else
0031     servoPPSCorrection=0;
0032 end
0033 
0034 tRoach=t0Roach+roachArray./(24*60*60);%roachOffset./1e6./24*60*60;
0035 tServo=t0Servo+servoArray./(24*60*60)+servoPPSCorrection./1e6/(24*60*60);
0036 
0037 d.antenna0.roach1.utc=tRoach';
0038 d.antenna0.roach2.utc=tRoach';
0039 d.antenna0.servo.utc=tServo';
0040 
0041 % For the roach the samples are taken using the 1PPS and the roach clock. So the roach data are synchronous with GPS
0042 % For the servo the samples are taken using NTP time. So we need to correct for any weird offsets in the servo NTP time. We actually record the servo NTP time
0043 % when the servo detects a 1PPS signal. This is in d.antenna0.servo.ntpUSecond([1:5:length(d.antenna0.servo.ntpUSecond)).
0044 % This can be used since when we think the time is say t0 it is actually t0+offset. So a sample recorded needs to have it's timestamp adjusted accordingly
0045 
0046 return

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005