-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGyroY_vs_time.m
More file actions
165 lines (135 loc) · 4.45 KB
/
Copy pathGyroY_vs_time.m
File metadata and controls
165 lines (135 loc) · 4.45 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
clear; clc; close all;
%% Load and parse the CSV file
filename = 'output_IMU.csv';
fid = fopen(filename, 'r');
if fid == -1
error('Cannot open file: %s', filename);
end
time_sec = [];
gyroY = [];
lineCount = 0;
while ~feof(fid)
line = fgetl(fid);
if ~ischar(line) || isempty(strtrim(line))
continue;
end
parts = strsplit(strtrim(line), ',');
if length(parts) < 7
continue;
end
dt_str = strtrim(parts{2});
gY = str2double(parts{7});
if isnan(gY)
continue;
end
try
dt = datetime(dt_str, 'InputFormat', 'yyyy-MM-dd HH:mm:ss.SSS');
catch
try
dt = datetime(dt_str, 'InputFormat', 'yyyy-MM-dd HH:mm:ss.SS');
catch
continue;
end
end
t_num = datenum(dt);
time_sec(end+1) = t_num; %#ok<SAGROW>
gyroY(end+1) = gY; %#ok<SAGROW>
lineCount = lineCount + 1;
end
fclose(fid);
fprintf('Successfully parsed %d data points.\n', lineCount);
if lineCount == 0
error('No valid data points found.');
end
%% Convert time to seconds from start
time_sec = (time_sec - time_sec(1)) * 86400;
time_sec = time_sec(:);
gyroY = gyroY(:);
%% Re-zero time so that 420s becomes t=0
t_offset = 420;
time_plot = time_sec - t_offset;
% Event times in the new (shifted) reference frame
takeoff_t = 424.8 - t_offset; % 4.8 s
%% Compute axis limits
x_min = 0;
x_max = 70;
vis_mask = time_plot >= x_min & time_plot <= x_max;
y_min = min(gyroY(vis_mask)) - 0.05;
y_max = max(gyroY(vis_mask)) + 0.05;
%% Compute min/max of visible window
gY_visible = gyroY(vis_mask);
t_visible = time_plot(vis_mask);
[gY_max, idx_max] = max(gY_visible);
[gY_min, idx_min] = min(gY_visible);
t_at_max = t_visible(idx_max);
t_at_min = t_visible(idx_min);
fprintf('\n--- Gyro Y Stats (visible window: 0 to 70s) ---\n');
fprintf('Maximum GyroY : %.6f rad/s at t = %.2f secs\n', gY_max, t_at_max);
fprintf('Minimum GyroY : %.6f rad/s at t = %.2f secs\n', gY_min, t_at_min);
fprintf('------------------------------------------------\n');
% Align Land xline with minimum gyroY time
land_t = t_at_min;
%% Plot
figure('Name', 'Gyro Y vs Time', 'NumberTitle', 'off', ...
'Position', [100, 100, 1100, 580]);
% Raw data
plot(time_plot, gyroY, 'b-', 'LineWidth', 1.0);
hold on;
% Smoothed overlay
window = 20;
gY_smooth = movmean(gyroY, window);
plot(time_plot, gY_smooth, 'r-', 'LineWidth', 2);
% Take Off vertical line
hl1 = xline(takeoff_t, '--k', 'LineWidth', 1.2);
hl1.Annotation.LegendInformation.IconDisplayStyle = 'off';
% Land vertical line
hl2 = xline(land_t, '--k', 'LineWidth', 1.2);
hl2.Annotation.LegendInformation.IconDisplayStyle = 'off';
% Take Off annotation
text(takeoff_t + 0.5, y_min + 0.01, 'Take Off', ...
'FontSize', 12, 'FontWeight', 'bold', 'Color', 'k', ...
'HorizontalAlignment', 'left', 'VerticalAlignment', 'bottom');
% Land annotation
text(land_t + 0.5, y_min + 0.01, 'Land', ...
'FontSize', 12, 'FontWeight', 'bold', 'Color', 'k', ...
'HorizontalAlignment', 'left', 'VerticalAlignment', 'bottom');
% Mark MAX point
plot(t_at_max, gY_max, 'v', ...
'MarkerSize', 12, ...
'MarkerFaceColor', 'k', ...
'MarkerEdgeColor', 'k');
text(t_at_max + 0.5, gY_max - 0.01, ...
sprintf(' Max: %.6f rad/s @ %.2f s', gY_max, t_at_max), ...
'FontSize', 11, ...
'FontWeight', 'bold', ...
'Color', 'k', ...
'BackgroundColor', [1.00 1.00 1.00], ...
'EdgeColor', 'k', ...
'Margin', 4, ...
'VerticalAlignment', 'top', ...
'HorizontalAlignment', 'left');
% Mark MIN point
plot(t_at_min, gY_min, '^', ...
'MarkerSize', 12, ...
'MarkerFaceColor', 'k', ...
'MarkerEdgeColor', 'k');
text(t_at_min - 0.5, gY_min + 0.03, ...
sprintf('Min: %.6f rad/s @ %.2f s', gY_min, t_at_min), ...
'FontSize', 11, ...
'FontWeight', 'bold', ...
'Color', 'k', ...
'BackgroundColor', [1.00 1.00 1.00], ...
'EdgeColor', 'k', ...
'Margin', 4, ...
'VerticalAlignment', 'bottom', ...
'HorizontalAlignment', 'right');
hold off;
%% Labels, legend, grid
xlabel('Time (secs)', 'FontSize', 13);
ylabel('Gyro Y (rad/s)', 'FontSize', 13);
title('Gyro Y vs Time', 'FontSize', 15, 'FontWeight', 'bold');
legend('Raw GyroY data', 'Smoothed (20-pt moving avg)', 'Location', 'northeast');
grid on;
%% Apply axis limits
xlim([x_min, x_max]);
ylim([y_min, y_max]);