How to work out BPM from ECG data

35 views (last 30 days)
Hi,
I have managed to find the beatsperminute of my data using the findpeaks function, however I want to confirm this using the fourier transform with spectral analysis however I am not sure how to do this.

Accepted Answer

Star Strider
Star Strider on 9 Jan 2020
Edited: Star Strider on 9 Jan 2020
The R-wave frequency peak should be the largest peak in the absolute value of the Fourier transform (after removing any d-c offset that may be present). Use the max function (with two outputs) to detect it and its index (into the frequency vector).
Use the second (index) output of max to get the associated frequency index of the R-wave peak.
The frequency vector of the Fourier transform will be in units of cycles/(time unit).
To convert this to (time units)/cycle, simply invert it.
That should produce the average heart rate, based on R-wave frequency.
EDIT — (9 Jan 2020 at 22:48)
Using the data you posted to your other Question:
EKG = readmatrix('Anonymous ECG.csv');
L = numel(EKG);
Fs = 350/2; % Units: Hz
Ts = 1/Fs; % Units: Sec
tv = linspace(0,L,L)*Ts; % Units: Sec
Fn = Fs/2;
FTEKG = fft(EKG)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(tv , EKG)
grid
[Pks,Locs] = findpeaks(EKG,tv, 'MinPeakHeight',200);
MeanHr1 = 60/mean(diff(Locs)); % Units: 1/Min
figure
plot(Fv, abs(FTEKG(Iv))*2)
grid
[MaxFTEKG,Idx] = max(abs(FTEKG(Iv))*2);
MeanHR2 = 60/Fv(Idx); % Units: 1/Min
Note that ‘MeanHR1’ and ‘MeanHr2’ are not the same because the broadband noise present in the Fourier-transformed data (that cannot be removed witha frequency-selective filter) may obscure the actual R-wave peak in the Fourier-transformed data. They are close, however, although I suspect that ‘Fs’ is wrong (probably should be 350), because the heart rates are about half of what they should be.
  2 Comments
Anon
Anon on 10 Jan 2020
Thank you but I have actually done this method with findpeaks. What I now want do is use the fft function to plot the ECG against BPM to confirm the BPM that I have found using the findpeaks method, which is where I am quite confused on.
Star Strider
Star Strider on 10 Jan 2020
Please describe what you intend by: ‘... plot the ECG against BPM ...’
It is not at all obvious what that means.

Sign in to comment.

More Answers (1)

Kashish Raheja
Kashish Raheja on 2 Jun 2021
how do i display bpm using my ecg data in matlab command window? what functions and code to write? pls helpp

Categories

Find more on Signal Generation and Preprocessing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!