% === Script Initialization and Setup ===
clear all;
close all;
% Define indices for data plotting.
plot_reps = [1,2]; % Specify which repetitions to plot [1-2].
plot_gestures = [1,13,30]; % Specify which movement types to plot [1-30].
channelsToPlot = [1,5,6,7,9,10]; % Specify which data channels to display in subplots [1-12].
% === Frequency and segment lengths ===
freq = 2048;
S1 = 4 * freq;
S2 = 2 * freq;
S3 = S1 + S2;
% === File Loading ===
fileName = uigetfile('', 'Select File');
if fileName == 0
error('No File selected.');
end
[~, baseName, ~] = fileparts(fileName);
fileParts = split(baseName,'_');
if length(fileParts) < 2
error('File name does not match expected format: [sessionID]_[subjectID]');
end
sessionParts = split(fileParts{1},'session');
sessionIdx = str2double(sessionParts{2});
subjectParts = split(fileParts{2},'participant');
subjectIdx = str2double(subjectParts{2});
Edata = load(fileName, 'DATA_WRIST');
DATA_WRIST = Edata.DATA_WRIST;
% === Plotting Loop ===
for j = 1:length(plot_reps)
repIdx = plot_reps(j);
for k = 1:length(plot_gestures)
moveIdx = plot_gestures(k);
if all(cellfun(@isempty, DATA_WRIST(repIdx,moveIdx)))
continue;
end
allChannelData = DATA_WRIST{repIdx, moveIdx}(:,channelsToPlot);
globalMaxAbs = max(max(abs(allChannelData)));
yLimit = globalMaxAbs * 1.05;
figure('WindowState', 'maximized');
for i = 1:length(channelsToPlot)
ch = channelsToPlot(i);
subplot(length(channelsToPlot), 1, i);
currentData = DATA_WRIST{repIdx, moveIdx}(:,ch);
N = length(currentData);
% --- GREEN (0–4s) ---
idx1 = 1 : min(S1, N);
plot(idx1, currentData(idx1), 'Color', [0 0.8 0], 'LineWidth', 1);
hold on;
% --- RED (4–6s) ---
if N > S1
idx2 = (S1+1) : min(S3, N);
plot(idx2, currentData(idx2), 'r', 'LineWidth', 1);
end
% --- GREEN again (6s–end) ---
if N > S3
idx3 = (S3+1) : N;
plot(idx3, currentData(idx3), 'Color', [0 0.8 0], 'LineWidth', 1);
end
ylim([-yLimit, yLimit]);
xlim([0,N]);
ylabel(sprintf('Ch %d', ch));
grid on;
if i == length(channelsToPlot)
xlabel('Samples');
else
set(gca, 'XTickLabel', []);
end
end
sgtitle(sprintf('Participant %d - Session %d - Gesture %d - Repetition %d', ...
subjectIdx, sessionIdx, moveIdx, repIdx));
end
end