How do separate each ECG beat from ECG data ?

I am trying to trace or to extract each single ECG beat from the entire ECG signal data. In entire data i am able to trace out the each R peak and I want to trace out now the each single beat. For that i want 108 samples before where R is occurring and 144 samples after R. i.e. window of [R-104:R+144]. So how do I do that?
Here is the code
clc clear all close all %% Denoise the ECG Signal
sig=load('100_b.txt'); load noisbump.mat; [sigDEN,wDEC] = func_denoise_sw1d(noisbump); subplot(2,1,1) plot(sig) title('Orignal ECG Signal'); % plot(sigDEN,'k'); axis tight; hold on; load denoisedbumps_100_b subplot(2,1,2) plot(denoisedbumps_100_b); title('Denoised ECG Signal'); % norm of the difference % norm(sigDEN,denoisedbumps_100_b,2)
%% BR Calculation % Plot Orignal Signal to calculate Heart-Beat Rate figure sig=load('100_b.txt'); plot(sig) xlabel('Samples'); ylabel('Electrical Activity (uV)'); title('Orignal ECG Signal Sampled at 360Hz') hold on plot(sig,'ro') beat_count=0; for k = 2 : length(sig)-1 if(sig(k)>sig(k-1) & sig(k)>sig(k+1) & sig(k)>1100) k disp('Prominant Peak found') beat_count = beat_count+1; end end fs = 360; N = length(sig); Duration_in_seconds = N/fs; Duration_in_minutes = Duration_in_seconds/60; BR = beat_count/Duration_in_minutes
In the code k is the value of sample at witch R peak of ECG sample is occurring. How to trace or to plot the window of (k-108:k+144) ?

Answers (2)

I have no idea what you’re doing. If you want to extract all the components of the P-QRS-T waves from a normal EKG with a rate of between 60-80 bpm, use a window beginning 150 ms prior to the R-wave, and 500 ms after it.
In sick hearts or higher rates, these limits may not be applicable. In rates lower than about 60 bpm (as seen in well-conditioned athletes), there is the possibility of ventricular ‘escape’ beats, known as bigeminy, that you would have to test and account for.

2 Comments

I do appreciate your answer. For normal ECG signal with beat rate (60-80 bpm), the suggested window of yours is in terms of time (that is totally correct) . Same thing I am trying to do with number of samples prior to R peak and after R peak.
Would you tell me how to extract all the components of the P-QRS-T waves?
My pleasure.
To translate time into samples, multiply the time (in seconds) by your sampling frequency (samples/second). So if:
Fs = 360; % Sampling Frequency (Hz)
StartIdx = 0.150 * Fs; % Samples Prior To ‘R’ Peak
EndIdx = 0.500 * Fs; % Samples After ‘R’ Peak
with a sampling frequency of 360 Hz (that I saw somewhere in your unformatted code), your sampling window would go from 54 samples before the R-wave peak to 180 samples after the R-wave peak.
‘Would you tell me how to extract all the components of the P-QRS-T waves?’
No, because this is an area of ongoing research. There are several published methods, and I refer you to PubMed to search for one appropriate to your application.

Sign in to comment.

Hi Kiran, you can use the following matlab code to get a certain portion of an ECG wave. Where locs_Rwave will give the location of R peaks in ECG. You can use any location. and then subtract a required number of beats from that location to go left and can add required number of beats to go right.
clear all; clc;
load ('p1');
val1 = val(1,:);
val2 = (val1-2*mean(val1));
plot(val2); grid on; title('ECG Signal of lead one')
hold on
[~, locs_Rwave] = findpeaks(val2, 'MinPeakHeight',900, 'MinPeakDistance',50);
plot(locs_Rwave, val2(locs_Rwave), 'rv' , 'MarkerFaceColor','r');
grid on;
legend ('R-waves');
x1 = val2(locs_Rwave(2)-29:locs_Rwave(2)+29);

Asked:

on 11 Feb 2016

Answered:

on 15 Aug 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!