-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtt_roll_vs_time.m
More file actions
119 lines (96 loc) · 3.08 KB
/
Copy pathAtt_roll_vs_time.m
File metadata and controls
119 lines (96 loc) · 3.08 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
clear; clc; close all;
%% Load and parse the CSV file
filename = 'output_att.csv';
fid = fopen(filename, 'r');
if fid == -1
error('Cannot open file: %s', filename);
end
time_sec = [];
att_roll = [];
lineCount = 0;
while ~feof(fid)
line = fgetl(fid);
if ~ischar(line) || isempty(strtrim(line))
continue;
end
% Split by comma
parts = strsplit(strtrim(line), ',');
if length(parts) < 10
continue;
end
% Column 2: datetime string
dt_str = strtrim(parts{2});
% Column 5: Att.Roll in degrees
val = str2double(parts{5});
if isnan(val)
continue;
end
% Parse datetime
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
% Convert datetime to seconds
t_num = datenum(dt);
time_sec(end+1) = t_num; %#ok<SAGROW>
att_roll(end+1) = val; %#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;
%% Re-zero time so that 420s becomes t=0
t_offset = 420;
time_plot = time_sec - t_offset;
%% Column vectors
time_plot = time_plot(:);
att_roll = att_roll(:);
fprintf('Time range : %.1f seconds (after offset)\n', max(time_plot));
fprintf('Att.Roll : %.2f deg to %.2f deg\n', min(att_roll), max(att_roll));
%% Visible window
x_min = 0;
x_max = max(time_plot) + 5;
vis_mask = time_plot >= x_min & time_plot <= x_max;
y_min = min(att_roll(vis_mask)) - 3;
y_max = max(att_roll(vis_mask)) + 3;
%% Plot
figure('Name', 'Att.Roll vs Time', 'NumberTitle', 'off', ...
'Position', [100, 100, 1100, 550]);
% Raw data
plot(time_plot, att_roll, 'b-', 'LineWidth', 1.0);
hold on;
% Smoothed overlay
window = 20;
roll_smooth = movmean(att_roll, window);
plot(time_plot, roll_smooth, 'r-', 'LineWidth', 2);
% Takeoff vertical line
takeoff_t = 424.8 - t_offset; % shifted to new reference
xline(takeoff_t, '--k', 'LineWidth', 1.2);
text(takeoff_t + 0.5, y_min + 0.5, 'Take Off', ...
'FontSize', 12, 'FontWeight', 'bold', 'Color', 'k', ...
'HorizontalAlignment', 'left', 'VerticalAlignment', 'bottom');
% Land vertical line fixed at 53.9s
land_t = 53.9;
xline(land_t, '--k', 'LineWidth', 1.2);
text(land_t + 0.5, y_min + 0.5, 'Land', ...
'FontSize', 12, 'FontWeight', 'bold', 'Color', 'k', ...
'HorizontalAlignment', 'left', 'VerticalAlignment', 'bottom');
hold off;
%% Labels, legend, grid
xlabel('Time (secs)', 'FontSize', 13); % starts at zero now
ylabel('Att.Roll (deg)', 'FontSize', 13);
title('Att.Roll vs Time', 'FontSize', 15, 'FontWeight', 'bold');
legend('Raw Att.Roll data', 'Smoothed (20-pt moving avg)', 'Location', 'best');
grid on;
%% Apply axis limits
xlim([x_min, x_max]);
ylim([y_min, y_max]);