Need help calculating BPM from ECG

35 ビュー (過去 30 日間)
Usama Zia
Usama Zia 2021 年 7 月 25 日
回答済み: Pavan Guntha 2021 年 7 月 28 日
NEED HELP IMMEDIATELY please. THANK YOU!!!
I performed the Valsalva maneuver and I have to show the changes it causes in heart rate.
I have filtered the raw ECG signal and found the R peaks but Im having trouble calculating Heart Rate BPM. I have put my code at the bottom. Please help me identify what I did wrong and what changes must be made.
%% Finding heart rate
clear;clc;
load('Mydata.mat');
rawdata = b1;%loading data from Labscribe File
ecgraw = rawdata(:,4);%extracting Filtered ECG Data
timeraw = rawdata(:,1);%extracting time points
figure(1)
plot(timeraw,ecgraw)
xlim([5 84])
%Implementing Filters
%low-pass filter
Wn = 0.5; %Wn=cuttoff frequency, high cutoff frequency of 5 Hz
n=300; %order of filter
lowpass = fir1(n,Wn,'low'); %implementing a 300th order FIR low pass filter
filterlowpass = filtfilt(lowpass,1,ecgraw);
%high-pass filter
Wn = 0.0067; %Wn=cuttoff frequency, low cutoff frequency of 0.67 Hz
n=300;
highpass = fir1(n,Wn,'high'); %implementing a 300th order FIR high pass filter
filterhighpass = filtfilt(highpass,1,filterlowpass);
figure(2) %plotting filtered ECG signal
plot(timeraw,filterhighpass);
xlim([5 84]);
xlabel('Time (secs)');ylabel('ECG (mV)');
title('Filtered ECG Signal');
figure(3) %plotting filtered ECG signal
plot(timeraw,filterhighpass);
xlim([5 84]);
xlabel('Time (secs)');ylabel('ECG (mV)');
title('Filtered ECG Signal');
hold on
[ecgpeaks,time] = findpeaks(filterhighpass,timeraw,'MinPeakProminence',0.14,'MinPeakDistance',0.3);
%identifying the R wave peaks of the QRS complex, MinPeakHeight and
%MinPeakDistance can be changed to identify clear peaks
%plot heart rate as a function of time
plot(time,ecgpeaks,'r*');
xlabel('Time (secs)');ylabel('ECG (mV)');
title('Peaks of Filtered ECG Signal');
xlim([5 84])
hold off
%% ( This is where the probelm starts )
%
totalnumberofpeaks = numel(ecgpeaks) %count the total number of peaks found within the signal
peaknumber = [1:1:totalnumberofpeaks]'; %create a column vector of the peak numbers going from 1 to the total number of peaks. Create row vector then transpose
timeinsecs = time; %convert time into seconds
HeartrateBPM = (peaknumber./timeinsecs).*60; %calculate heart rate in bpm, where heart rate = (number of peaks at a given time/given time)x60
figure(4) %plot heart rate as a function of time
plot(timeinsecs,HeartrateBPM);
xlabel('Time (secs)');ylabel('HR (bpm)');
title('Heart Rate');
  2 件のコメント
Scott MacKenzie
Scott MacKenzie 2021 年 7 月 25 日
It might help if you also post Mydata.mat.
Usama Zia
Usama Zia 2021 年 7 月 25 日
sure this the Mydata.mat

サインインしてコメントする。

回答 (1 件)

Pavan Guntha
Pavan Guntha 2021 年 7 月 28 日
Hi Usama,
I understand that the issue is related to the Heart rate computation in BPM. As per the code attached, the 'HeartrateBPM' computes the heart rate by considering all the R-peaks occured until current time. So, the instantaneous effect of R-peaks on the heart rate isn't captured. For calculating instantaneous heart rate you could have a look at the following code snippet:
totalnumberofpeaks = numel(ecgpeaks) %count the total number of peaks found within the signal
peaknumber = [1:1:totalnumberofpeaks]'; %create a column vector of the peak numbers going from 1 to the total number of peaks. Create row vector then transpose
timeinsecs = [time(1); diff(time)]; %calculating time difference b/w consecutive peaks in seconds
HeartrateBPM = 60./time_new; %calculating instantaneous heart rate (in BPM)
You could look at the documentation of diff function for more details.
Hope this helps!

カテゴリ

Help Center および File ExchangeECG / EKG についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by