Finding the turning point on the left side of a peak

8 views (last 30 days)
I am writing a program that analyses the data from an ECG machine, and it needs to find the turning point on either side of the major peak. I have been able to find the turning point to the roght of each peak but cannot think of a way to find the turning point on the left side
%Load data
load('Sample_2.mat');
%Filter Data
[b, a] = butter(10,0.1,'low');
% fvtool(b,a);
Filtered = filtfilt(b,a,Orig_Sig);
%Dynamic Min Peak Height%
x = max(Filtered)
min_h = x*.8;
plot(Filtered);
hold on;
[peaks,locs] = findpeaks(Filtered,'MinPeakHeight',min_h, 'MinPeakDistance', 150);
plot(locs,peaks,'rv','MarkerSize',10)
hold on;
%find S points
A = 1:length(locs);
current = locs(A);
next = current + 1;
while Filtered(current) >= Filtered(next)
current = next;
next = next + 1;
end
plot(current,Filtered(current),'g*','MarkerSize',10)
hold on;

Accepted Answer

Star Strider
Star Strider on 24 Oct 2021
‘... the turning point on either side of the major peak
Those are referred to as the Q and S deflections (or waves).
The filter is not designed correctly. I would use:
[Filtered, df] = bandpass(Orig_Sig, [1 45], Fs, 'ImpulseResponse','iir');
in order to elimiinate the baselilne drift as well as any high-frequency noise that couold be present. (Here ‘Fs’ is the sampling frequency, and should be constant for the entire record. If it is not, there are ways to correct for that.)
The bandpass call will design an elliptic bandpass filter and the ‘Filtered’ result should make any subsequent analyses easier. It also returns the digital filter object in ‘df’ so that it is not necessary to create it again if the intent is to use it subsequently.
Those deflections appear to be relatively well-defined here, so use the islocalmin function to identify them. I have had success with that in the past, and it should work here as well. It will be necessary to use some of the name-value pair arguments to get it to produce the desired result.
Other than the motion artefact, it appears to be a normal EKG. What appear to be low P-waves and peaked T-waves with U-waves could be indicative of hyperkalemia (or drug effects).
.
  2 Comments
Harrison Miller
Harrison Miller on 26 Oct 2021
Thank you very much for your help, your suggestions worked perfectly!
As you seem knowledgable on the topic, i hope you dont mind me asking a follow up question.
Do you have a reliable way to find the peaks of the P and T waves, preferably using the 'findpeaks' Function to keep it coheasive with the rest of the program?
Star Strider
Star Strider on 26 Oct 2021
As always, my pleasure!
That tends to be a bit more difficult, since the objective is to find specific peaaks that do not include all peaks.
It just requres a bit of set arithmetic, and it’s easier to demonstrate it than describe it —
t = linspace(0, 100, 250);
EKG = sin(2*pi*t*0.075).*(sin(2*pi*t*0.075)>0.7)*0.25 + sin(2*pi*t*0.075+pi).*(sin(2*pi*t*0.075+pi)>0.7)*0.75;
[pks1,locs1] = findpeaks(EKG); % All Peak Indices
[pks2,locs2] = findpeaks(EKG, 'MinPeakHeight',0.5); % R-Wave Indices
locs3 = setdiff(locs1,locs2); % P- & T-Wave Indices
figure
plot(t, EKG)
hold on
plot(t(locs1), EKG(locs1),'xr', 'MarkerSize',15)
plot(t(locs2), EKG(locs2),'+g', 'MarkerSize',15)
hold off
grid
legend('EKG','All Peaks','R-Waves', 'Location','best')
ylim([0 1])
figure
plot(t, EKG)
hold on
plot(t(locs3), EKG(locs3),'^r', 'MarkerSize',15)
hold off
grid
legend('EKG','P- & T-Waves', 'Location','best')
ylim([0 1])
Since in this trace, the P-waves are reduced and the T-waves appear to be peaked, this approach can be extended to identify them separately. (That may not always be the situation, especially with EKG traces displaying broadband noise, so it is not generally robust.)
.

Sign in to comment.

More Answers (0)

Categories

Find more on ECG / EKG in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!