How to find Q and S point in QRS complex of ECG signal?

조회 수: 55 (최근 30일)
Explorer
Explorer 2016년 2월 9일
댓글: anas khan 2022년 3월 12일
How to find Q and R points of ECG signal shown below?
Code:
load 16265m.mat;
plot(val(1,:))
  댓글 수: 3
Explorer
Explorer 2016년 2월 9일
My attempt to code:
D=load('16265m.mat');
t=1:1280;
ECG_data=D.val(1,:);
% plot(t,ECG_data)
% grid on,
[~,locs_Rwave] = findpeaks(ECG_data,'MinPeakHeight',0.5,...
'MinPeakDistance',200);
ECG_inverted = -ECG_data;
[~,locs_Swave] = findpeaks(ECG_inverted,'MinPeakHeight',0.5,...
'MinPeakDistance',200);
figure
hold on
plot(t,ECG_data);
plot(locs_Rwave,ECG_data(locs_Rwave),'rv','MarkerFaceColor','r');
plot(locs_Swave,ECG_data(locs_Swave),'rs','MarkerFaceColor','b');
%axis([0 1850 -1.1 1.1]);
grid on;
legend('ECG Signal','R-waves','S-waves');
xlabel('Samples'); ylabel('Voltage(mV)')
title('R-wave and S-wave in Noisy ECG Signal')
smoothECG = sgolayfilt(ECG_data,7,21);
figure
plot(t,ECG_data,'b',t,smoothECG,'r'); grid on
axis tight;
xlabel('Samples'); ylabel('Voltage(mV)');
legend('Noisy ECG Signal','Filtered Signal')
title('Filtering Noisy ECG Signal')
[~,min_locs] = findpeaks(-smoothECG,'MinPeakDistance',40);
% Peaks between -0.2mV and -0.5mV
locs_Qwave = min_locs(smoothECG(min_locs)>-0.5 & smoothECG(min_locs)<-0.2);
figure
hold on
plot(t,smoothECG);
plot(locs_Qwave,smoothECG(locs_Qwave),'rs','MarkerFaceColor','g');
plot(locs_Rwave,smoothECG(locs_Rwave),'rv','MarkerFaceColor','r');
plot(locs_Swave,smoothECG(locs_Swave),'rs','MarkerFaceColor','b');
grid on
title('Thresholding Peaks in Signal')
xlabel('Samples'); ylabel('Voltage(mV)')
ax = axis;
%axis([0 1850 -1.1 1.1])
legend('Smooth ECG signal','Q-wave','R-wave','S-wave');
Still points are not detected correctly. Please help me in improving this code.
anas khan
anas khan 2022년 3월 12일
D.val error show why sir plz guid me

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2016년 2월 9일
The first trace doesn’t have any S-waves, so don’t look for them. The EKG morphology is dependent on the lead placement and heart health. The second one is a very sick heart, with a left bundle-branch block pattern. It also has an RSR' pattern, so you have to be careful to not detect the first R-deflection.
My code:
q = load('Explorer 16265m');
EKG1 = q.val(1,:);
EKG2 = q.val(2,:);
Fs = 128;
t = [0:size(EKG1,2)-1]/Fs;
[R1,TR1] = findpeaks( EKG1, t, 'MinPeakHeight',200);
[Q1,TQ1] = findpeaks(-EKG1, t, 'MinPeakHeight',100); % NOTE: No ‘S’ Waves In EKG1
[R2,TR2] = findpeaks( EKG2, t, 'MinPeakHeight', 50);
[QS2,TQS2] = findpeaks(-EKG2, t, 'MinPeakHeight', 75);
figure(1)
subplot(2,1,1)
plot(t, EKG1)
hold on
plot(TR1, R1, '^r')
plot(TQ1, -Q1, 'vg')
hold off
grid
axis([0 2 ylim])
legend('EKG', 'R', 'Q')
subplot(2,1,2)
plot(t, EKG2)
hold on
plot(TR2, R2, '^r')
plot(TQS2(1:2:end), -QS2(1:2:end), 'vg')
plot(TQS2(2:2:end), -QS2(2:2:end), 'vb')
hold off
grid
axis([0 2 ylim])
legend('EKG', 'R', 'Q', 'S')
My plot:
  댓글 수: 12
Explorer
Explorer 2016년 2월 18일
편집: Explorer 2016년 2월 18일
Okay, thank you for detailed answer.
I was finding Q R and S points to find slope of QR wave and RS wave.
In trace 1, there are Q and R points. So slope of QR can be found using slope formula i.e. (y2-y1)/(x2-x1)
But the problem here I am encountering is number of Q points and R points are not equal. What should I do now?
Probably this is because false Q points are detected especially after 300 (x-axis).
axis([300 330 ylim])
Star Strider
Star Strider 2016년 2월 18일
My pleasure. Electrocardiography and the principles behind it are not trivial to learn.
I didn’t look at that signal in detail, but the number of Q-waves and R-waves should not differ by more than 1, if the EKG trace was cut off in the middle of a QRS complex. Otherwise, experiment with different values of 'MINPEAKDISTANCE' in your findpeaks call to be sure the peaks it returns aren’t too close to each other. Do that for both the Q-wave and R-wave findpeak calls. You can use the same value for 'MINPEAKDISTANCE' for both once you detetermine the best value for it.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Shatha Jazar
Shatha Jazar 2017년 2월 13일
please can you predict the R wave in my signal ?

tursun wali
tursun wali 2017년 3월 20일
Dear @Star Strider, ----------------------------------- Answer by Star Strider on 9 Feb 2016 Accepted answer ----------------------------------- Your result is impressive and what I want. I want to find height of Q, R and S peaks ; so far find R and S not Q peak I have tested you code (I've changed one line:q = load('16265m.mat'); ) It shows this error message: ----------------------------------- Error using uddpvparse (line 122) Invalid Parameter/Value pairs.
Error in findpeaks>parse_inputs (line 84) hopts = uddpvparse('dspopts.findpeaks',varargin{:});
Error in findpeaks (line 59) [X,Ph,Pd,Th,Np,Str,infIdx] = parse_inputs(X,varargin{:});
Error in QRS_detect_tursun6 (line 6) [R1,TR1] = findpeaks( EKG1, t, 'MinPeakHeight',200); -----------------------------------
I would be very happy if you tell me how to fix it? Well actually My signal contains only one EKG (attachment: person6.mat): I want to find height of Q, R and S peaks ; so far find R and S not Q peak
  댓글 수: 3
sania urooj
sania urooj 2021년 3월 8일
@Star Strider I have used your above code for detecting QRS peaks. It's working but my task is to detect peaks of multiple ECG signal that are already stored in one mat file. How can I do it as each signal may have different peaks ? Please help me.
Christopher McCausland
Christopher McCausland 2021년 3월 10일
@sania urooj I would suggest creating a new question. However to run any code on diffrent arrays a simple 'for' loop of the lenght/width (depending on the orentation of the ecg leads) of the data should surfice. Remeber to include an array within the loop to store loop data in and a second array outside the loop to write the loop data too once the loop completes.
Hope this helps!
For 1:width(ecgchanneldata)
% do this code
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Signal Generation and Preprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by