Master Thesis Code
by Simon Moser
Loading...
Searching...
No Matches
allanDeviationAnalysis.m
Go to the documentation of this file.
1% =========================================================================== %
2%> @brief allanDeviationAnalysis calculates the Allan deviation and estimates
3%> the noise parameters of a given measurement.
4%>
5%> @param meas - the measurement data (Mxu vector) [unit: any = X, e.g. m/s^2]
6%> @param fs - the sampling frequency of the measurement (scalar) [unit: Hz]
7%> @param plt - a flag to plot the Allan deviation (logical)
8%>
9%> @retval tau - the time intervals used for Allan deviation calculation (Mxu vector) [unit: s]
10%> @retval adev - the Allan deviation values corresponding to each tau (Mxu vector) [unit: X, e.g. m/s^2]
11%> @retval N - the noise density factor (1xu vector) [unit: X/sqrt(Hz), e.g. (m/s^2)/sqrt(Hz)]
12%> @retval K - the random walk coefficient (1xu vector) [unit: X * sqrt(Hz), e.g. (m/s^2) * sqrt(Hz)]
13%> @retval B - the bias instability coefficient (1xu vector) [unit: X, e.g. m/s^2]
14%> @retval tau_B - the time interval where the bias instability coefficient is estimated (1xu vector) [unit: s]
15%>
16%> The implementation is based on the following references:
17%> - https://ch.mathworks.com/help/nav/ug/inertial-sensor-noise-analysis-using-allan-variance.html
18%> - IEEE Standard Specification Format Guide and Test Procedure for Single-Axis Laser Gyros, IEEE Std 647-2006
19%>
21%>
22%> @copyright see the file @ref LICENSE in the root directory of the repository
23% =========================================================================== %
24function [tau, adev, N, K, B, tau_B] = allanDeviationAnalysis(meas, fs)
25
26arguments
27 meas (:,:) double {mustBeNumeric}
28 fs (1,1) double {mustBeNumeric}
29end
30
31% calculate Allan variance
32[avar, tau] = allanvar(meas, 'octave', fs);
33
34% remove last element of tau and avar (because we have very long measurements)
35tau = tau(1:end-1,:);
36avar = avar(1:end-1,:);
37
38% calculate Allan deviation
39adev = sqrt(avar);
40
41u = width(meas);
42N = nan(1,u);
43K = nan(1,u);
44B = nan(1,u);
45tau_B = nan(1,u);
46
47% find Noise Parameters
48logtau = log10(tau);
49logadev = log10(adev);
50dlogadev = diff(logadev) ./ diff(logtau);
51
52for i = 1:u
53
54 % first, find the global minimum of the Allan deviation
55 [~, idx_min] = min(adev(1:end-1,i));
56
57 % find Noise Density N (must be left of the minimum of the Allan deviation curve)
58 slope = -0.5;
59 [~, idxN] = min(abs(dlogadev(1:idx_min,i) - slope));
60 b = logadev(idxN,i) - slope * logtau(idxN); % find y-intercept
61 logN = slope * log10(1) + b;
62 N(i) = 10^logN; % Noise Density Factor N [unit: X/sqrt(Hz), e.g. (m/s^2)/sqrt(Hz)]
63
64 % find Random Walk Coefficient K (must be right of the minimum of the Allan deviation curve)
65 slope = 0.5;
66 [~, idxK] = min(abs(dlogadev(idx_min:end,i) - slope));
67 idxK = idxK + idx_min - 1; % correct index
68 b = logadev(idxK,i) - slope * logtau(idxK); % find y-intercept
69 logK = slope * log10(3) + b;
70 K(i) = 10^logK; % Random Walk Coefficient K [unit: X * sqrt(Hz), e.g. (m/s^2) * sqrt(Hz)]
71
72 % find bias instability Coefficient B (must be between idxN and idxK)
73 slope = 0;
74 [~, idxB] = min(abs(dlogadev(idxN:idxK,i) - slope));
75 idxB = idxB + idxN - 1; % correct index
76 b = logadev(idxB,i) - slope * logtau(idxB); % find y-intercept
77 scfB = sqrt(2*log(2)/pi);
78 logB = b - log10(scfB);
79 B(i) = 10^logB; % bias instability Coefficient B [unit: X, e.g. m/s^2]
80
81 % find tau_B
82 tau_B(i) = tau(idxB);
83
84end
85end
function allanDeviationAnalysis(in meas, in fs)