필터 지우기
필터 지우기

Need help calculating BPM from ECG

조회 수: 24 (최근 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 CenterFile Exchange에서 ECG / EKG에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by