Finding average heart rate of EKG data
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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)')
0 commentaires
Réponse acceptée
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')
[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
StDvRperiod = std(Rperiod) % Unit: Second
SEMRperiod = StDvRperiod/sqrt(numel(locs)) % Unit: Second
RangeRfreq = 1./([1 -1]*1.96*SEMRperiod+MeanRperiod) % Unit: 1/Second
Rfreq = 1/mean(Rperiod) % Rate, Unit = 1/Second
Rfreq*60 % Rate, Unit = 1/Minute
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
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.
.
Plus de réponses (1)
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
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!