0001 function d=ntpTimeAdjustSouth(d)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 ppsIndex = find(d.antenna0.roach1.fpgaClockStamp==2499976);
0012 ppsOffset=d.antenna0.roach1.ntpUSeconds(ppsIndex)/1e6-0.01;
0013
0014
0015 ppsPoly = polyfit(ppsIndex,ppsOffset,1);
0016 ppsOffsetFit=polyval(ppsPoly,[1:length(d.antenna0.roach1.utc)]);
0017
0018
0019
0020
0021
0022
0023
0024 offsetCorrectedUTC = d.antenna0.roach1.utc - (ppsOffsetFit/86400)';
0025
0026 offsetCorrectedUTCPoly=polyfit([1:length(offsetCorrectedUTC)],offsetCorrectedUTC',1);
0027 offsetCorrectedUTCFit=polyval(offsetCorrectedUTCPoly,[1:length(offsetCorrectedUTC)]);
0028
0029
0030 data=offsetCorrectedUTC;
0031 dataFit=offsetCorrectedUTCFit;
0032 fittingAccuracy=0.1;
0033 diffDecrement=2;
0034 startDiff=10;
0035 fittedDiff=86400*(dataFit-data');
0036 diffCalc=fittedDiff;
0037
0038 counter=1;
0039 close all
0040 dataStart=data;
0041 dataStartIndex=[1:length(offsetCorrectedUTC)];
0042
0043
0044 while((mean(fittedDiff.^2)>fittingAccuracy) && counter<=10)
0045 indexNew=find(diffCalc<=startDiff);
0046 newPoly=polyfit(indexNew,data(indexNew)',1);
0047 dataFit=polyval(newPoly,[1:length(offsetCorrectedUTC)]);
0048 fittedDiff=86400*(dataFit(indexNew)-data(indexNew)');
0049 diffCalc=86400*(dataFit-data');
0050 startDiff=startDiff./diffDecrement;
0051 counter=counter+1;
0052
0053 end
0054
0055
0056
0057
0058
0059
0060 d.antenna0.roach1.utc=dataFit;
0061
0062
0063
0064 ppsIndex = find(d.antenna0.roach2.fpgaClockStamp==2499976);
0065 ppsOffset=d.antenna0.roach2.ntpUSeconds(ppsIndex)/1e6-0.01;
0066
0067
0068 ppsPoly = polyfit(ppsIndex,ppsOffset,1);
0069 ppsOffsetFit=polyval(ppsPoly,[1:length(d.antenna0.roach2.utc)]);
0070
0071
0072
0073
0074
0075
0076
0077 offsetCorrectedUTC = d.antenna0.roach2.utc - (ppsOffsetFit/86400)';
0078
0079 offsetCorrectedUTCPoly=polyfit([1:length(offsetCorrectedUTC)],offsetCorrectedUTC',1);
0080 offsetCorrectedUTCFit=polyval(offsetCorrectedUTCPoly,[1:length(offsetCorrectedUTC)]);
0081
0082
0083 data=offsetCorrectedUTC;
0084 dataFit=offsetCorrectedUTCFit;
0085 fittingAccuracy=0.1;
0086 diffDecrement=2;
0087 startDiff=10;
0088 fittedDiff=86400*(dataFit-data');
0089 diffCalc=fittedDiff;
0090
0091 counter=1;
0092 close all
0093 dataStart=data;
0094 dataStartIndex=[1:length(offsetCorrectedUTC)];
0095
0096
0097 while((mean(fittedDiff.^2)>fittingAccuracy) && counter<=10)
0098 indexNew=find(diffCalc<=startDiff);
0099 newPoly=polyfit(indexNew,data(indexNew)',1);
0100 dataFit=polyval(newPoly,[1:length(offsetCorrectedUTC)]);
0101 fittedDiff=86400*(dataFit(indexNew)-data(indexNew)');
0102 diffCalc=86400*(dataFit-data');
0103 startDiff=startDiff./diffDecrement;
0104 counter=counter+1;
0105
0106 end
0107
0108
0109
0110
0111
0112
0113 d.antenna0.roach2.utc=dataFit;
0114
0115
0116 UTC=d.antenna0.servo.utc;
0117 UTCPoly=polyfit([1:length(UTC)],UTC',1);
0118 UTCFit=polyval(UTCPoly,[1:length(UTC)]);
0119
0120
0121 data=UTC;
0122 dataFit=UTCFit;
0123 fittingAccuracy=0.1;
0124 diffDecrement=2;
0125 startDiff=10;
0126 fittedDiff=86400*(dataFit-data');
0127 diffCalc=fittedDiff;
0128
0129 counter=1;
0130 close all
0131 dataStart=data;
0132 dataStartIndex=[1:length(UTC)];
0133
0134
0135 while((mean(fittedDiff.^2)>fittingAccuracy) && counter<=10)
0136 indexNew=find(diffCalc<=startDiff);
0137 newPoly=polyfit(indexNew,data(indexNew)',1);
0138 dataFit=polyval(newPoly,[1:length(UTC)]);
0139 fittedDiff=86400*(dataFit(indexNew)-data(indexNew)');
0140 diffCalc=86400*(dataFit-data');
0141 startDiff=startDiff./diffDecrement;
0142 counter=counter+1;
0143
0144 end
0145
0146
0147
0148
0149
0150
0151 d.antenna0.servo.utc=dataFit;
0152
0153
0154