Master Thesis Code
by Simon Moser
Loading...
Searching...
No Matches
jumpCombineData.m
Go to the documentation of this file.
1% =========================================================================== %
2%> @brief combines multiple JUMP sensor data structures into one
3%>
4%> This function combines the data from multiple jumps into a single dataset.
5%> It takes in the data from each jump as input and returns a combined dataset.
6%>
7%> @param data : array of JUMP sensor data structures (see @ref jumpReadData)
8%> @param options.max_t_gap : maximum time gap between two data structures
9%> to be combined, if the time gap is larger, the data structures are not
10%> combined. must be given as duration or in seconds. (default: 10 seconds)
11%>
12%> @retval data_combined : combined JUMP sensor data structure
13%> @retval join_times : array of times when the data structures were combined
14%>
15%> @code{.m}
16%> % example usage:
17%> data(1) = jumpReadData("jump_1.BIN");
18%> data(2) = jumpReadData("jump_2.BIN");
19%> [data_combined, join_times] = jumpCombineData(data, max_t_gap=7);
20%> @endcode
21%>
22%> @note The data structures must have the same header information.
23%>
24%> see also @ref jumpReadData, @ref jumpCheckData
25%>
26%> @file jumpCombineData.m
27%>
28%> @copyright see the file @ref LICENSE in the root directory of the repository
29% =========================================================================== %
30
31function [data_combined, join_times] = jumpCombineData(data, options)
32
33arguments
34 data (1,:) struct;
35 options.max_t_gap (1,1) {mustBeA(options.max_t_gap, ["duration", "numeric"])} = seconds(10);
36end
37
38% check the data structure
39for i = 1:length(data)
40 [valid, ~, data(i)] = jumpCheckData(data(i));
41 assert(valid, "Data structure %d is not valid", i);
42end
43
44% check if the max time gap is a duration, otherwise convert
45if ~isa(options.max_t_gap, "duration")
46 options.max_t_gap = seconds(options.max_t_gap);
47end
48
49
50% check if the structures have the same header information, the header contains
51% ID, UID, name, sw_version, hw_version, acc_range, gyro_range, mpu_cal,
52% act_thrs, inact_dur, mpu_rate, adxl_rate, pres_rate, magn_en, sync,
53% ble_address. the t_start is not checked, as this must be different
54try
55 assert(length(unique([data.ID])) == 1, "ID");
56 assert(length(unique([data.UID])) == 1, "UID");
57 assert(length(unique([data.name])) == 1, "name");
58 assert(length(unique([data.sw_version])) == 1, "sw_version");
59 assert(length(unique([data.hw_version])) == 1, "hw_version");
60 assert(length(unique([data.acc_range])) == 1, "acc_range");
61 assert(length(unique([data.gyro_range])) == 1, "gyro_range");
62 assert(length(unique([data.mpu_cal])) == 1, "mpu_cal");
63 assert(length(unique([data.act_thrs])) == 1, "act_thrs");
64 assert(length(unique([data.inact_dur])) == 1, "inact_dur");
65 assert(length(unique([data.mpu_rate])) == 1, "mpu_rate");
66 assert(length(unique([data.adxl_rate])) == 1, "adxl_rate");
67 assert(length(unique([data.pres_rate])) == 1, "pres_rate");
68 assert(length(unique([data.magn_en])) == 1, "magn_en");
69 assert(length(unique([data.sync])) == 1, "sync");
70 assert(length(unique([data.ble_address])) == 1, "ble_address");
71catch ME
72 error("The data structures must have compatible headers. At least the field %s is not the same.", ME.message);
73end
74
75% sort the data structures by time
76[~, idx] = sort([data.t_start]);
77
78% check the time gaps between the data structures
79for i = numel(idx)-1
80
81 % check that the data is not overlapping
82 if data(idx(i)).tt.t(end) > data(idx(i+1)).tt.t(1)
83 error("Data structures %d and %d are overlapping", idx(i), idx(i+1));
84 end
85
86 % check the time gap
87 t_gap = data(idx(i+1)).tt.t(1) - data(idx(i)).tt.t(end);
88 if t_gap > options.max_t_gap
89 error("Time gap between data structures %d and %d is too large. It is %.1f s and is allowed to be %.1f s", idx(i), idx(i+1), seconds(t_gap), seconds(options.max_t_gap));
90 end
91end
92
93% combine the data structures
94data_combined = data(idx(1));
95join_times = NaT(numel(idx)-1, 1);
96for i = 2:numel(idx)
97 join_times(i-1) = data(idx(i)).t_start;
98 data_combined.tt = [data_combined.tt; data(idx(i)).tt];
99end
100
101% update the t_start
102data_combined.t_start = data_combined.tt.t(1);
103
104% fill gaps
105data_combined.tt = retime(data_combined.tt, 'regular', 'nearest', 'TimeStep', seconds(1/data_combined.mpu_rate));
function jumpCheckData(in data)
function jumpCombineData(in data, in options)
function jumpReadData(in filePath, in options)