필터 지우기
필터 지우기

How to calculate the heart rate from an ECG signal?

조회 수: 101 (최근 30일)
HelpAStudent
HelpAStudent 2023년 6월 15일
댓글: Cris LaPierre 2023년 6월 15일
Hi, I have for example this ecg signal from how I did the plot in time:
load 'sig.mat'
fs = 300;
t=linspace(0,length(sig)/fs,length(sig));
figure()
plot(t,sig/max(sig));
title('Signal in Time Domain');
xlabel('Time(s)');
ylabel('Amplitude');
And from the plot I roughly calculate in the x axis the time between one peak (R wave) to the other. That is circa 1.5 s. If the distance between two R peaks in an ECG is approximately 1.5 seconds, I calculate the heart rate based on that interval.
Converting 1.5 seconds to milliseconds:
1.5 seconds * 1000 = 1500 milliseconds
Now, we can calculate the heart rate:
Heart Rate = 60,000 / 1500 = 40 beats per minute
Therefore, with a distance between two R peaks of approximately 1.5 seconds, the heart rate would be around 40 beats per minute.
There is a more precice way to calculate the heart rate from an ECG signal?
Attention this signal is not filtered. Is better to filter first? And if so, how?
  댓글 수: 1
Cris LaPierre
Cris LaPierre 2023년 6월 15일
No need to convert to milliseconds
HeartRate = 60/1.5 % seconds/min * beats/sec = beats/min
HeartRate = 40

댓글을 달려면 로그인하십시오.

답변 (1개)

Cris LaPierre
Cris LaPierre 2023년 6월 15일
  댓글 수: 2
HelpAStudent
HelpAStudent 2023년 6월 15일
편집: Cris LaPierre 2023년 6월 15일
with findpeaks it not help me to find just the R peaks that I want. Since if I do the mean of the distance between this peaks I can't find a normal heart rate.
load sig.mat
% plotting
fs=300;
t = linspace(0,length(sig)/fs,length(sig));
f = linspace(- fs/2, fs/2, length(sig));
figure()
plot(t,sig)
title("signal")
xlabel("seconds")
ylabel("A.U.")
figure()
plot(f,fftshift(abs(fft(sig))))
title("signal spectrum")
xlabel("Hz")
ylabel("Amplitude")
% filtering
sig_noDC = sig - mean(sig);
freq1 = 49;
freq2 = 51;
w1 = freq1/(fs/2);
w2 = freq2/(fs/2);
w = [w1 w2];
[b,a] = butter(3, w, "stop");
filtered_sig = filtfilt(b,a,sig_noDC);
freqX = 0.5;
wX = freqX/(fs/2);
[b,a] = butter(3,wX,"high");
filtered_sig = filtfilt(b,a,filtered_sig);
figure()
plot(t,filtered_sig)
title("filtered signal")
xlabel("seconds")
ylabel("A.U.")
figure()
plot(f,fftshift(abs(fft(filtered_sig))))
title("filtered signal spectrum")
xlabel("Hz")
ylabel("Amplitude")
[pks,locs,w,p] = findpeaks(sig); %find R peak
meanw = mean(w) %w is the width of all the peaks
meanw = 4.7879
heartRate = mean(w)*60
heartRate = 287.2740
Cris LaPierre
Cris LaPierre 2023년 6월 15일
You will need to spend some time finding the appropriate settings for your findpeaks function call. It also wouldn't hurt to filter your signal, though with the prominence of the R peaks, that's proabably not necessary.
Consider doing this interactive in a live script using the Find Local Extrema live task.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by