HEART RATE from heart sound

Hi, Please I need help to remove errors on peak detected, here is the code I used.

2 Comments

Try using the Find Local Extrema task in a live script. This will allow you to interactively adjust the inputs to findpeaks, which can make it easier to identify the correct settings.
Monday David
Monday David on 29 Feb 2024
Moved: Star Strider on 29 Feb 2024
Here is my audio file.
Kindly assist on it.
Thanks

Sign in to comment.

Answers (1)

@Monday David, If you attach the MP3 file, others can run your code. You will have to zip it first.
[Edit: The sounds which are labelled S1 in the plot below are really S2, and vice versa. This does not affect the accuracy of the estimate of heart rate.]
I would rectify the signal with abs() instead of setting negaitve values to zero. But it probably won't make a huge difference. I wonder what Fs is, because if I knew, I would undertand the plot in the image better. I cannot tell how many seconds of data I am looking at.
The plot in your image has peaks with irregular spaciong and amplitude. It certainly does not look like normal heart sounds.
Here is a 10 second recording of normal heart sounds, from the University of Michigan heart sounds library.
unzip('heartSoundsApexNormalBell10s.zip');
[x,Fs]=audioread('heartSoundsApexNormalBell10s.mp3');
t=(0:length(x)-1)'/Fs; % time vector
envDur=0.02; % envelope duration (s)
[xUpper,~]=envelope(abs(x),envDur*Fs,'rms');
[pks,locs]=findpeaks(xUpper,Fs,MinPeakDistance=0.3,MinPeakHeight=0.1);
s1pks=pks(pks>0.4); s1locs=locs(pks>0.4);
s2pks=pks(pks<=0.4); s2locs=locs(pks<=0.4);
plot(t,xUpper,'-b',s1locs,s1pks,'r*',s2locs,s2pks,'gx');
grid on; xlabel('Time (s)'); legend('amplitude','S1','S2','Location','southeast')
Estimate the HR from the S1 locations:
HR=(length(s1locs)-1)/(s1locs(end)-s1locs(1));
fprintf('Heart rate=%.1f bpm.\n',HR*60)
Heart rate=74.7 bpm.
OK

11 Comments

Here is my audio file.
Kindly assist on it.
Thanks
I hear 14 S1 sounds when I listen to the recording you uploaded. The attached script also identifies 14 peaks, and computes HR accordingly. It makes the figure below.
>> HRfromHeartSounds
Heart rate=62.8 bpm.
.
Thanks for your help, kindly share the code you used.
I think my script makes a few errors when applied to adultCASE1. In 12 out of 14 beats in this recording, the script identifies the second heart sound (S2). In the other two beats, it identifies the first heart sound (S1). In this subject, S2 is generally louder than S1. The reverse is true in the recording I uploaded ("normal" from Univ. of Michigan library). If you are just trying to estimate mean rate, and the script identifies one sound or the other, but not both, then it doesn't make much difference, but if you are trying to estimate HR variability (which I do not recommend with heart sounds), you'd get incorrect results, because you would conclude there some short beats and some long beats, even if that was not really true. The image below is an annortated version of the image inthe answer above. Most of the red asterisks are on the second sound (S2). The red circles show where the script identified S1 instead of S2; the green arrows shows the S2 that comes after the S1s that were identified.
Ideally, all the red asterisks would be on S1s (and they are, in the UMich recording), or they would all be on S2s.
I noticed the absence of an S1 before the third S2, when listening to adultCASE1. That missing S1 corresponds to the flat spot in the plot below, from 2.0 to 2.4 seconds. Maybe something was blocking the sound during this time.
@Monday David, here is the script. I have tried various values for envDur (s), mnPkHt, mnPkProm, etc. The values in the attached version of the script produced the plots above.
I said, in a comment above, that your plot did not look like normal heart sounds. When I listened to the file, it sounded more normal than I expected from the plot. That suggests a degree of mismatch between the visual representation and my aural perception. Maybe a plot which uses a larger value for envDur would agree more with my aural perception.
For example, the plot below uses envDur=0.08 s, mnPkHt=0.07. The visual representaiton below agrees better with my aural perception than the plot obtained with envDur=0.02 s.
Thanks.
What do you advise I can do?
Thanks for your help
You are welcome.
"What do you advise I can do?" You can use the script I uploaded to compute HR from heart sounds. That was your orignal request. Was there something else?
Thanks
The value I am getting is 62.8 bpm but the clinical value is 70 bpm.
When you say "The clinical value is 70 bpm", what do you mean? Did some other analysis of this same recording indic ate a HR of 70? If so, I'd like to see the analysis. 70 bpm is a textbook value for average HR, but actual HR varies greatly, across and within individuals.
Okay. Thanks I appreciate
@Monday David, you're welcome. Good luck with your HR analysis.

Sign in to comment.

Asked:

on 28 Feb 2024

Commented:

on 4 Mar 2024

Community Treasure Hunt

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

Start Hunting!