csvfile="GOPR2164.CSV" % Start/end times for the plot X axis, in seconds. start_time = 0; end_time = 10; % Readin in CSV file jump_raw=csvread(csvfile); % Convert raw units to useful units (seconds, degrees C, Gs, etc jump=jump_raw.*[1/1000 1 1 0.1 1/2048 1/2048 1/2048 0]; % Pull out the timestamps ts=jump(:,1); % Index of starting and ending data point to plot % These are data point numbers, rather than time values plot_start=find(ts >= start_time, 1) % Clip end time to end of data end_time = min(max(ts), end_time); % Find data point index corresponding to end time plot_end=find(ts >= end_time, 1) % Snap range to data points start_time = ts(plot_start) end_time = ts(plot_end) % Pull out the X,Y,Z acceleration values accel=jump(:,[5,6,7]); % Compute acceleration magnitude from X,Y,Z values mag=((accel(:,1).^2)+(accel(:,2).^2)+(accel(:,3).^2)).^0.5; %mag = jump(:,3); % Compute min/max/range of the values we are plotting, to make the axes pretty min_mag = min(mag(plot_start:plot_end)); max_mag = max(mag(plot_start:plot_end)); range_mag = max_mag - min_mag; % Moving average parameters lead = 3; lag = 3; weight = 0; % raw_color=[120 160 255]./255; raw_color = [0.8 0.8 1]; % Show an initial plot of what things will look like smoothed_data = movavg(mag(plot_start:plot_end), lead, lag, weight); hold off plot(ts(plot_start:plot_end), mag(plot_start:plot_end), '.-', 'LineWidth', 2, 'MarkerSize', 8, 'Color', raw_color) hold on plot(ts(plot_start:plot_end), smoothed_data, '.-', 'LineWidth', 2, 'MarkerSize', 8) axis([start_time end_time min_mag-range_mag*0.03 max_mag+range_mag*0.03]) % Plot a reference 1-G line plot([start_time end_time], [1 1], 'r-') printf("Preview generated. Press Enter to begin frame-by-frame plotting, or Ctrl-C to cancel\n"); pause % Okay, now do the frame-by-frame plotting for i = plot_start:plot_end % Generate a new figure. % We don't want to keep plotting over the same figure over and over due to some % silly issue with spontaneous plot resizing figure hold on % Configure our axis layout, to keep things consistent across frames axis([start_time end_time min_mag-range_mag*0.03 max_mag+range_mag*0.03]) % Plot a reference 1-G line plot([start_time end_time], [1 1], 'r-') % Show only the Y-axis labels axis("tic", "labely") % Cosmetic things title ("G-Force", "fontsize", 20) grid on set(gca, 'FontSize', 20) % Configure plot layout to mimimize white margins / borders around plot area set(gcf, 'Units', 'normal') set(gca,'Position', [0.07 0.05 0.90 0.87]) set(gcf, 'Color', 'none') set(gca, 'Color', 'none') printf('Plotting frame %d of %d\n', i - plot_start, plot_end-plot_start); % Actually plot our data smoothed_data = movavg(mag(plot_start:i), lead, lag, weight); plot(ts(plot_start:i), mag(plot_start:i), '.-', 'LineWidth', 2, 'MarkerSize', 8, 'Color', raw_color) plot(ts(plot_start:i), smoothed_data, '.-', 'LineWidth', 2, 'MarkerSize', 8) % Save current frame to a PNG file filename=sprintf('frame%05d.png', i); print(filename, "-S600,450"); close endfor