Signal segmentation error: how to select a specific number of points before and after the ECG signal?
1 view (last 30 days)
Show older comments
I want to segment an ECG signal in heartbeats by taking a number of sample points before and after each R-peak. I did the following loop:
before=100;
after=140;
for i=1:length(qrs_i_raw)
beat(i,:)=ECG(qrs_i_raw(i+1)-before:qrs_i_raw(i+1)+after);
end
%qrs_i_raw has the index location of the peak
it gives me this error
Index exceeds the number of array elements (650000).
I understand why I get this error, but how can I modify the loop so for the first and last beat it will take just the existing points before the first beat and the remaining points after the last beat?
0 Comments
Accepted Answer
Star Strider
on 9 Feb 2021
See How do I find and plot the average of action potentials from a trace? for an appropriate approach. Substitute your EKG vector and time vector for the signals in that code, and adjust the ‘ofst’ value to be the one you want (typically about 450 ms for an EKG, so that value would depend on the sampling frequency of your EKG and the heart rate, so multiply the sampling frequency in Hz by 0.45 to get the number of samples to use for ‘ofst’). It may be necessary to adjust that for the heart rate, so typically that interval should be slightly less than ½ of the previous — or mean — R-R interval.
0 Comments
More Answers (1)
Mathieu NOE
on 9 Feb 2021
hello Ioana
I modified a bit your code , hope it works
before=100;
after=140;
nn = length(qrs_i_raw);
% first and last buffer - specific cases
beat(1,:)=ECG(1:qrs_i_raw(1)+after);
beat(nn,:)=ECG(qrs_i_raw(nn)-before:end);
% general cases
for i=2:nn-1
beat(i,:)=ECG(qrs_i_raw(i)-before:qrs_i_raw(i)+after); % pls note index i is same on both sides of the equation
end
%qrs_i_raw has the index location of the peak
2 Comments
See Also
Categories
Find more on ECG / EKG in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!