How to find the QRS complex for this ECG signal?

Hi all,
Could somebody please tell me how I can find the QRS complexes of this ECG signal? The signal is attached.
Thanks in advance!

6 Comments

@Star Strider Based on what you taught me in another post, I was able to find most of the QRS complex, but still, there are some that I cannot detect them. Here is the script
L = numel(ECG);
t = linspace(0, L-1, L)/1024;
[pks,locs] = findpeaks(ECG,'MinPeakDistance',2, 'MinPeakHeight',max(ECG)*0.6846);
figure
plot(t, ECG, '.-')
hold on
plot(t(locs), pks, '^k')
idxrng = locs(2) + [-6:6];
plot(t(idxrng), ECG(idxrng), '-g', 'LineWidth', 2)
hold off
grid
xlim([0 6])
ylim([-0.2 0.8])
Then I find and eliminate all identified unwanted spikes
ECGnew = ECG;
for k = 2:3:numel(locs)
idxrng = locs(k) + [-6:6];
ECGnew(idxrng) = NaN;
ECGnew = fillmissing(ECGnew, 'makima');
end
figure;
plot(t, ECGnew, '.-')
hold on
plot(t(locs), pks, '^r')
hold off
grid
It works almost great, but miss 5 QRS complexes, shown by their data tips bellow
Any idea how I can improve the code to do that? Many thanks in advance.
The 10 Hz spikes are basically the same height a a normal R wave in the absence of spikes, so it is not surprising that you might fail to identify an occasional lower-than-average-amplitude R wave. Of course you will want to identify and eliminate the source of the 10 Hz spikes if at all possible, in future recordings. Maybe that it impossible, for example if it is an indwelling stimulator or some other therapeutic device. You may have to live with a compromise in which you have occasional false positives (i.e. calling something an R wave when it is not) and false negatives (i.e. failing to identify real R waves). This occurs in many clinical scenarios. Finding the right balance depends on the costs of the different types of errors. You will have no better guide that @Star Strider in such matters.
I sympathize with your situation. I once recorded a very low quality EKG because I had not turned up the amplifier gain as normal, and did not catch the error. As a result, the R waves were almost buried in noise. But the experimental data was valuable, so I made quite an effort to filter out the noise to extract the R waves. And I added a checklist item to make sure I did not make that mistake again.
@William Rose Thanks, William, for your response. It was very informative and exciting. Out of curiosity, do you know what these 10Hz spikes mean for cardiologists? How much is the chance that these 10Hz spikes cause a wrong interpretation of these signals? I mean the chance that these data to be interpreted as an illness that it's not. Do you have some experience with other low-quality EKG due to some 2Hz and 40Hz spikes? Just wondering what Hz/frequency making these spikes are widespread. I appreciate any help you can provide.
@Susan, I am not a cardiologist or a physician. But I am confident that the 10 Hz spikes would not be interpreted as a pathology. The physician would immediately recognize that there was a problem with the recording. Maybe the circuit used to amplify and record the ECG has a flaw in it that generates 10 Hz spikes. Maybe the spikes are due to crosstalk from another device in the room. Maybe the subject has some implantable device that generates pulses at 10 Hz. If that were true, the physician would know it, so the spikes would not be misinterpreted.
This ECG is not acceptable for clinical use. If the spikes were much narrower, they could be removed by signal processing, without too much risk of causing significant distortion of the true signal. But they are wide as well as tall.
I have not seen spikes like this at 2 or 10 or 40 Hz, but my experience is quite limited, with only a few hundred subjects. I have recorded ECGs with clinical-grade machines, with teaching machines, and with amplifiers I designed and built myself. I have recorded in the cardiac cath lab and in teaching labs and in research labs and in the field.
If you collected the data, then you probably have ideas about the possible source of the spikes.
@William Rose Thank you so much for your response. It's helpful. Appreciate it!
@Susan, you're welcome. Good luck with your work.

Sign in to comment.

 Accepted Answer

Perhaps the comments above constitute an answer to your question.
ECGs=load('ECG');
ECG=ECGs.ECG;
L = numel(ECG);
t = linspace(0, L-1, L)/1024;
[pks,locs] = findpeaks(ECG,'MinPeakDistance',2,'MinPeakHeight',max(ECG)*0.6846);
%[pks,locs] = findpeaks(ECG,'MinPeakDistance',2,'MinPeakHeight',.48);
figure
subplot(311), plot(t, ECG, '-r',t(locs), pks, '^r')
xlabel('Time (s)'); grid on
subplot(312), plot(t, ECG, 'r-',t(locs), pks, '^k')
xlim([0 5]); xlabel('Time (s)'); grid on
subplot(313), plot(t, ECG, '.r-',t(locs), pks, '^k')
xlim([4 5]); xlabel('Time (s)'); grid on
The 10 Hz spikes are a bit narrower than the QRS complexes, so it should be possible to identify the QRS complexes based on that, plus the peak height excedigng approximately 0.4. This should allow you to find all of the R waves.
Was the subject paced? The R-R intervals appear to be too even for unpaced beats.
Good luck.

3 Comments

@William Rose Thanks again for your feedback. Unfortunately, the peak height exceeding ~0.4 is not the case for all R waves, and I'm still unable to detect all of them, but your suggestion on finding QRS complexes based on their width is interesting. Any guidance on how I can calculate these widths?
And the subject wasn't paced. This data was for a normal heart beat.
@Susan, Let's continue the discussion offline. Please send me secure email by clicking the WR circle next to my name, then click on the envelope icon.

Sign in to comment.

More Answers (0)

Asked:

on 8 Dec 2022

Commented:

on 13 Dec 2022

Community Treasure Hunt

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

Start Hunting!