ECG = csvread('ECG.csv');
f_s = 350;
frame_duration = 0.5;
frame_len = frame_duration*f_s;
N = length(ECG);
num_frames = floor(N/frame_len);
Time = (0:length(ECG)-1)/f_s;
Amp = ECG(:,1);
plot(Time, Amp, 'b-', 'LineWidth', 2);
xlabel('Time', 'FontSize', 20);
ylabel('ECG', 'FontSize', 20);
hold on
threshold = 100;
line(xlim, [threshold, threshold], 'Color', 'r', 'LineWidth', 2);
grid on;
for m = 1:num_frames
index1 = (m-1)*frame_len + 1;
index2 = frame_len*m;
frame = Amp(index1 : index2);
fprintf('Extracted frame #%d, from index %d to %d.\n', ...
m, index1, index2);
[max_val, indexAtMax] = max(frame);
originalIndex = indexAtMax + index1 - 1;
fprintf(' Max of %f occurs at index %d of cropped signal, or %d of original signal.\n', ...
max_val, indexAtMax, originalIndex);
if (max_val > threshold)
plot(Time(originalIndex),Amp(originalIndex),'r*')
hold on
line(xlim, [threshold, threshold], 'Color', 'r', 'LineWidth', 2);
xlabel('Time', 'FontSize', 20);
ylabel('ECG', 'FontSize', 20);
grid on;
hFig.WindowState = 'maximized';
hold on
end
end
Best Answer