Finding average heart rate of EKG data

15 vues (au cours des 30 derniers jours)
Lu Engr
Lu Engr le 13 Nov 2022
Commenté : Star Strider le 14 Nov 2022
Hello, I have a .wav file consisting of EKG DATA. I would like to find the average heart rate (BPM), but I'm not entirely sure on how to do that. I have read the wav file into MATLAB using audioread and was able to plot it. How do I calculate the average heart rate?
y,Fs]=audioread('EKG.wav');
y=y(:,1); dt=1/Fs; t=0:dt:(length(y)*dt)-dt;
plot(t,y); xlabel('Time(s)') ylabel('Amplitude') title('EKG(Relaxed)')

Réponse acceptée

Star Strider
Star Strider le 13 Nov 2022
Modifié(e) : Star Strider le 14 Nov 2022
I woiuld use findpeaks with an appropriate value for 'MinPeakProminence' to select only the R-deflections.
Example —
[y,Fs]=audioread('EKG.wav');
y=y(:,1);
dt=1/Fs;
t=0:dt:(length(y)*dt)-dt;
pv = 1; % Minimum Peak Prominence Value
[pks, locs] = findpeaks(y, 'MinPeakProminence',pv);
Rtimes = t(locs);
Rperiod = diff(Rtimes);
Rfreq = 1/mean(Rperiod)
Make appropriate changes to get the desired results.
.
EDIT — (14 Nov 2022 at )
That is av very strange EKG. I have no idea what lead it is, however it appears to have a RSR' (read: R-S-R prime) pattern, and the R' deflection slightly complicates the findpeaks call.. If it was a right precordial lead, I would suspect an atrial septal defect, or otherwise some sort of significant conduction system abnormality. Not knowing the lead, and not having other leads to put it into context, I have no idea what it could mean.
Uz = unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1191893/Ludovic.zip')
Uz = 1×2 cell array
{'Ludovic.wav'} {'__MACOSX/._Ludovic.wav'}
[y,Fs]=audioread(Uz{1});
y=y(:,1);
dt=1/Fs;
t=0:dt:(length(y)*dt)-dt;
% L = numel(y);
% t = linspace(0, L-1, L)/Fs;
figure
plot(t, y)
grid
xlabel('Time')
ylabel('Amplitude')
figure
plot(t, y)
grid
xlabel('Time')
ylabel('Amplitude')
xlim([0 7])
pv = 0.45; % Minimum Peak Prominence Value
[pks, locs] = findpeaks(y, 'MinPeakProminence',pv);
Rtimes = t(locs);
Rperiod = diff(Rtimes);
MeanRperiod = mean(Rperiod) % Units: Second
MeanRperiod = 0.7256
StDvRperiod = std(Rperiod) % Unit: Second
StDvRperiod = 0.2738
SEMRperiod = StDvRperiod/sqrt(numel(locs)) % Unit: Second
SEMRperiod = 0.0172
RangeRfreq = 1./([1 -1]*1.96*SEMRperiod+MeanRperiod) % Unit: 1/Second
RangeRfreq = 1×2
1.3169 1.4453
Rfreq = 1/mean(Rperiod) % Rate, Unit = 1/Second
Rfreq = 1.3781
Rfreq*60 % Rate, Unit = 1/Minute
ans = 82.6849
figure
plot(t, y)
hold on
plot(t(locs), pks, '^r')
hold off
grid
xlabel('Time')
ylabel('Amplitude')
xlim([0 11])
The result is quite sensitive to the ‘pv’ value, so if there are more records, it may be necessary to experiment with it to get the appropriate result.
.
  2 commentaires
Lu Engr
Lu Engr le 14 Nov 2022
Not having any luck. It's reading "Nan" for Rfreq
Star Strider
Star Strider le 14 Nov 2022
It worked when I ran it with the posted file. If you used that same file and copied and pasted the code I posted, you should get the same result I got when you run it.
I cannot re-run it because the file no longer exists here. Please re-post it. (Eliminating previously posted data or code is not courteous.)
If you are running my code with a different file, it may be necessary to adjust the ‘pv’ value so that findpeaks returns the correct R-deflection locations and values. As I mentioned, my code may be very sensitive to the ‘pv’ value. I had to experiment with it to get the correct result.
.

Connectez-vous pour commenter.

Plus de réponses (1)

Cris LaPierre
Cris LaPierre le 13 Nov 2022
I would calculate the instantaneous heart rate for each heartbeat, and then take the average of those to find average heart rate. To do that, you need to identify a single feature in each heartbeat (likely the peak of the QRS complex), find the time between each one, and convert that to instantaneous heart rate.
You might find the first 20 minutes of this YouTube Livestream helpful. Just beware that the example used is missing the time data.
  3 commentaires
Lu Engr
Lu Engr le 14 Nov 2022
I’ve added the wav file
Cris LaPierre
Cris LaPierre le 14 Nov 2022
And then removed it

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by