-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathAllanVariance.m
117 lines (97 loc) · 3.58 KB
/
AllanVariance.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
% ****************************************************************************
% AllanVariance.m :Compute Phase or Frequency Sequence's Allan Variance
%
% Copyright (C) 2019 by Jason DING , All rights reserved.
%
% version :$Revision: 1.0 $ $Date: 2019/04/04 $
% history : 2019/04/04 1.0 new
% 2019/04/05 1.1 add Modified Allan variance and Time variance.
% ****************************************************************************
function AllanVariance = AVAR_Phase(PhaseSequence,tau,m)
% Calculate the Allan variance of the time difference (phase) sequence.*****
% Given:
% PhaseSequence Phase sequence
% tau Sampling interval
% m Smoothing factor
% Returned:
% AllanVariance Allan variance
% *************************************************************************
M = length(PhaseSequence);
M_= fix(M/m)+1;
bias = zeros(M_,1);
for i = 1:M_-2
if ((i+1)*m+1 <= M)
bias(i,1) = PhaseSequence((i+1)*m+1)-2*PhaseSequence(i*m+1)+PhaseSequence((i-1)*m+1);
end
end
AllanVariance=(bias*bias')/(2*(N-2)*tau*tau);
end
function AllanVariance = AVAR_Freq(FrequencySequence,m)
% Calculate the Allan variance of the frequency sequence.*******************
% Given:
% FrequencySequence Frequency sequence(n*1)
% m Smoothing factor
% Returned:
% AllanVariance Allan variance
% *************************************************************************
M = length(FrequencySequence);
M_= fix(M/m)+1;
bias = zeros(M_-1,1);
for i = 1:M_-1
if i < M_-1
bias(i,1) = mean(FrequencySequence((i*m+1):(i+1)*m,1)) ...
- mean(FrequencySequence((i-1)*m+1:i*m,1));
else
bias(i,1) = mean(FrequencySequence((i*m+1):M,1)) ...
- mean(FrequencySequence((i-1)*m+1:i*m,1));
end
end
AllanVariance=(bias'*bias)/(2*(M_-1));
end
function Mod_AllanVariance = MAVAR_Phase(PhaseSequence,tau,m)
% Calculate the Modified Allan variance of the time difference (phase) sequence.
% Given:
% PhaseSequence Phase sequence
% tau Sampling interval
% m Smoothing factor
% Returned:
% Mod_AllanVariance Modified Allan variance
% *************************************************************************
N = length(PhaseSequence);
sum = 0;
for j=1:N-3*m+1
for i=j:j+m-1
sum = sum+(PhaseSequence(i+2*m)-2*PhaseSequence(i+m)+PhaseSequence(i))^2;
end
end
Mod_AllanVariance = sum/(2*m^2*tau^2*(N-3*m+1));
end
function Mod_AllanVariance = MAVAR_Freq(FrequencySequence,m)
% Calculate the Modified Allan variance of the frequency sequence.*********
% Given:
% FrequencySequence Frequency sequence
% m Smoothing factor
% Returned:
% Mod_AllanVariance Modified Allan variance
% *************************************************************************
M = length(FrequencySequence);
sum = 0;
for j=1:M-3*m+2
for i=j:j+m-1
for k=i:i+m-1
sum = sum+(FrequencySequence(k+m)-FrequencySequence(k))^2;
end
end
end
Mod_AllanVariance = sum/(2*m^4*(M-3*m+2));
end
function TimeVariance = TVAR(ModAVAR,tau)
% Calculate the Time Variance. ********************************************
% Given:
% ModAVAR Modified Allan variance
% tau Sampling interval
% Returned:
% TimeVariance Time Variance
% *************************************************************************
TimeVariance = ModAVAR*tau/sqrt(3);
end