Master Thesis Code
by Simon Moser
Loading...
Searching...
No Matches
jumpNoiseAnalysis.m
Go to the documentation of this file.
1% =========================================================================== %
2%> @brief performs a noise analysis of data of a JUMP sensor.
3%>
4%> this function performs an Allan Deviation analysis of the data of a JUMP
5%> sensor. The data is expected to be in the format of the JUMP sensor data
6%> structure defined in @ref jumpReadData.m. The function an interface between
7%> the data and the @ref allanDeviationAnalysis.m function.
8%>
9%> @param data (struct): the data of a JUMP sensor in the format of the JUMP
10%> sensor data structure defined in @ref jumpReadData.m.
11%> @param options (struct): options for the analysis
12%> - toAnalyze (string): the fields of the data to analyze (default: ["acc","gyr","hig","mag","prs","tmp"])
13%> - plot (logical): if true, the function will plot the Allan Deviation of the data (default: false)
14%>
15%> @retval analysis (struct): a struct with the results of the analysis. The
16%> struct has the same fields as the input data, and each field has the
17%> following subfields:
18%> - tau (double): the tau values of the Allan Deviation
19%> - adev (double): the Allan Deviation values
20%> - N (double): the Power Spectral Density
21%> - K (double): the K value of the Allan Deviation
22%> - B (double): the B value of the Allan Deviation
23%> - tau_B (double): the tau value of the B value
24%> - note (string): a note about the units of the results
25%>
26%> @file jumpNoiseAnalysis.m
27%>
28%> @copyright see the file @ref LICENSE in the root directory of the repository
29% =========================================================================== %
30function analysis = jumpNoiseAnalysis(data, options)
31
32% input validation
33arguments
34 data (1,1) struct
35 options.toAnalyze (1,:) string = ["acc","gyr","hig","mag","prs","tmp"];
36 options.plot (1,:) logical = false;
37end
38
39% check data
40assert(jumpCheckData(data), "Data structure is not valid.");
41
42% define struct
43analysis = struct();
44
45if options.plot
46 figure("Name", sprintf("Allan Deviation Analysis of Sensor %s", char(data.name)), "NumberTitle", "off");
47end
48
49% loop over toAnalyze
50for i = 1:length(options.toAnalyze)
51 % get data
52 dataToAnalyze = data.tt.(options.toAnalyze(i));
53
54 % get fs
55 if strcmp(options.toAnalyze(i), "acc") || strcmp(options.toAnalyze(i), "gyr")
56 fs = data.mpu_rate;
57 elseif strcmp(options.toAnalyze(i), "mag")
58
59 this_idx = all(~isnan(data.tt.mag),2);
60 % get fs
61 this_times = data.tt.t(this_idx);
62 fs = round(1 / seconds(median(diff(this_times))));
63
64 if fs >= 20
65 % no timing correction was applied, therefore use 10 Hz
66 fs = 10;
67 end
68
69 % downsampe because the data is stored at mpu_rate, but the actual rate is 10 Hz
70 dataToAnalyze = resample(dataToAnalyze(this_idx,:), this_times, fs, "pchip");
71
72 elseif strcmp(options.toAnalyze(i), "hig")
73 fs = data.adxl_rate;
74 elseif strcmp(options.toAnalyze(i), "prs") || strcmp(options.toAnalyze(i), "tmp")
75
76 this_idx = all(~isnan(data.tt.(options.toAnalyze(i))),2);
77 % get fs
78 this_times = data.tt.t(this_idx);
79 fs = round(1 / seconds(median(diff(this_times))));
80
81 if fs >= data.pres_rate * 2
82 % no timing correction was applied, therefore use 1 Hz
83 fs = data.pres_rate;
84 end
85
86 % downsampe because the data is stored at mpu_rate, but the actual rate is pres_rate
87 dataToAnalyze = resample(dataToAnalyze(this_idx,:), this_times, fs, "pchip");
88 end
89
90 [tau, adev, N, K, B, tau_B] = allanDeviationAnalysis(dataToAnalyze, fs);
91
92 % store in analysis
93 analysis.(options.toAnalyze(i)).tau = tau;
94 analysis.(options.toAnalyze(i)).adev = adev;
95 analysis.(options.toAnalyze(i)).N = N;
96 analysis.(options.toAnalyze(i)).K = K;
97 analysis.(options.toAnalyze(i)).B = B;
98 analysis.(options.toAnalyze(i)).tau_B = tau_B;
99 analysis.(options.toAnalyze(i)).note = "The units are related to the input data. Check units before applying them to a model. Also, the Power Spectral Density (N) is outputtet according to single sided spectrum.";
100
101
102 % plot
103 if options.plot
104 subplot(2,ceil(length(options.toAnalyze)/2),i);
105
106 loglog(tau, adev, '-r', 1, N, 'o', 3, K, 'x', tau_B, 0.664*B, '+');
107 title(options.toAnalyze(i));
108 xlabel('tau [s]');
109 ylabel('Allan Deviation');
110 grid on;
111
112 end
113end
114
115
116
117end
function allanDeviationAnalysis(in meas, in fs)
function jumpCheckData(in data)
function jumpNoiseAnalysis(in data, in options)
function jumpReadData(in filePath, in options)