Master Thesis Code
by Simon Moser
Loading...
Searching...
No Matches
jumpZeroVelocityDetection.m
Go to the documentation of this file.
1%> @brief this function performs a zero velocity detection on the provided data.
2%>
3%> @param data - data structured as defined in @ref jumpReadData
4%> @param options.plot - boolean to enable plotting (default: false)
5%> @param options.method - method to use for zero velocity detection (default: "movstd_acc_gyr")
6%> @param options.windowSize - window size for the moving standard deviation (default: 100)
7%> @param options.threshold_acc - threshold for the acceleration (default: 0.15 m/s^2)
8%> @param options.threshold_gyr - threshold for the angular velocity (default: 0.15 deg/s)
9%>
10%> @retval zv - logical vector indicating zero velocity (1) and movement (0)
11%>
12%> @details The methods works as follows:
13%> - movstd_acc_gyr: calculates the moving standard deviation of the acceleration
14%> and angular velocity. If the standard deviation is below the threshold for both
15%> acceleration and angular velocity, the data is considered zero velocity.
16%>
18%>
19%> @copyright see the file @ref LICENSE in the root directory of the repository
20
21function zv = jumpZeroVelocityDetection(data, options)
22% input validation
23arguments
24 data (1,1) struct;
25 options.plot (1,1) logical = false;
26 options.method (1,1) string = "movstd_acc_gyr";
27 options.windowSize (1,1) double = 100;
28 options.threshold_acc (1,1) double = 0.15;
29 options.threshold_gyr (1,1) double = 0.15;
30end
31
32% check data structure
33assert(jumpCheckData(data), "Data structure is not valid.");
34
35switch options.method
36 case "movstd_acc_gyr"
37 try
38 std_acc = max(abs(movstd(data.tt.acc, options.windowSize)),[],2);
39 std_gyr = max(abs(movstd(data.tt.gyr, options.windowSize)),[],2);
40
41 zv = std_acc < options.threshold_acc & std_gyr < options.threshold_gyr;
42 catch e
43 error("Zero velocity detection failed. Check if the data is correctly structured and the parameters are set correctly.");
44 end
45 otherwise
46 error("Unknown method: %s", method);
47end
48
49if options.plot
50 figure;
51 plt1 = subplot(2,1,1);
52 yyaxis left;
53 plot(data.tt.t, data.tt.acc, "DisplayName", "acceleration");
54 ylabel("acc [m/s^2]");
55 yyaxis right;
56 plot(data.tt.t, zv, '.', "DisplayName", "zv");
57 ylim([-0.1, 1.1]);
58 yticks([0, 1]);
59 yticklabels(["movement", "zero velocity"]);
60 ylabel("zv");
61 title("Zero velocity detection");
62 legend("Location", "best");
63
64 plt2 = subplot(2,1,2);
65 yyaxis left;
66 plot(data.tt.t, data.tt.gyr, "DisplayName", "angular velocity");
67 ylabel("gyr [deg/s]");
68 yyaxis right;
69 plot(data.tt.t, zv, '.', "DisplayName", "zv");
70 ylim([-0.1, 1.1]);
71 yticks([0, 1]);
72 yticklabels(["movement", "zero velocity"]);
73 ylabel("zv");
74 xlabel("time [s]");
75 legend("Location", "best");
76
77 linkaxes([plt1, plt2], "x");
78
79end
function jumpCheckData(in data)
function jumpReadData(in filePath, in options)
function jumpZeroVelocityDetection(in data, in options)