Reputation: 145
I need help to find Heart rate in 2 ECGs signals that I'm analyzing. This is what I did since now:
Now, I'm basing my analysis on this paper but I'm stuck on Heart rate detection algorithms with Autocorrelation of energy signal / Thresholding of energy signal. I can't understand how to get the heart rate, can anyone tell me (with a code example please). Here is what I'm doing:
valvular_heart_disease = load('disease.mat');
figure;plot(valvular_heart_disease.val);
healthy_control = load('healthy.mat');
figure;plot(healthy_control.ecg);
fs = 1000; % Sampling frequency - Hz
n_dis = length(valvular_heart_disease.val); % length
n_heal = length(healthy_control.ecg);
timevec_dis = (0:n_dis-1)/fs; % time vector
timevec_heal = (0:n_heal-1)/fs; % time vector
% Detrend data vhd
detrend_data_vhd = detrend(valvular_heart_disease.val);
% Normalize data vhd
max_value_vhd = max(detrend_data_vhd);
normalized_vhd = detrend_data_vhd/max_value_vhd;
% Detrend data hc
detrend_data_hc = detrend(healthy_control.ecg);
% Normalize data hc
max_value_hc = max(detrend_data_hc);
normalized_hc = detrend_data_hc/max_value_hc;
%figure;plot(normalized_vhd);
%%%%%%%%%%% FILTERING %%%%%%%%%%%
% Notch def band stop
wo = 50/(fs/2);
bw = wo/35;
[b,a] = iirnotch(wo,bw);
% Butter High Pass
[z,p] = butter(2,0.5/(fs/2),'high');
% Butter low-high
%fcutlow=15; %low cut frequency in Hz
%fcuthigh=20; %high cut frequency in Hz
%[c,d]=butter(4,[fcutlow,fcuthigh]/(fs/2),'bandpass');
[c,d] =butter(2,15/(fs/2),'low');
[h,i] =butter(2,20/(fs/2),'high');
% Notch
ecg_vhd_notch = filter(b,a,normalized_vhd);
ecg_hc_notch = filter(b,a,normalized_hc);
% Butter
ecg_vhd_btr = filter(z,p,ecg_vhd_notch);
ecg_hc_btr = filter(z,p,ecg_hc_notch);
% Butter low-high
%l
ecg_vhd_low = filter(c,d,ecg_vhd_btr);
ecg_hc_low = filter(c,d,ecg_hc_btr);
%h
ecg_vhd_high = filter(h,i,ecg_vhd_low);
ecg_hc_high = filter(h,i,ecg_hc_low);
% Plotting Notch
figure
subplot(2,1,1)
plot(timevec_dis, normalized_vhd, 'b', timevec_dis, ecg_vhd_notch, 'r');
title('Segnale VHD Notch')
xlabel('sec')
ylabel('amp')
figure
subplot(2,1,1)
plot(timevec_heal, normalized_hc, 'b', timevec_heal, ecg_hc_notch, 'r');
title('Segnale HC Notch')
% Plotting after butter
figure
subplot(2,1,1)
plot(timevec_dis, normalized_vhd, 'b', timevec_dis, ecg_vhd_btr, 'r');
title('Segnale VHD Butter')
figure
subplot(2,1,1)
plot(timevec_heal, normalized_hc, 'b', timevec_heal, ecg_hc_btr, 'r');
title('Segnale HC Butter')
xlabel('time')
ylabel('amplitude')
% filtering with high pass and low pass Butterworth filters
% with cut-off frequencies 15 Hz and 20 Hz
figure
subplot(2,1,1)
plot(timevec_dis, normalized_vhd, 'b', timevec_dis, ecg_vhd_high, 'r');
title('Segnale VHD Butter')
figure
subplot(2,1,1)
plot(timevec_heal, normalized_hc, 'b', timevec_heal, ecg_hc_high, 'r');
title('Segnale HC Butter')
% Heart rate detection
et = abs(ecg_hc_high).^2;
plot(timevec_heal, et)
ac = xcorr(et);
plot(ac)
th = 2*mean(et);
[pks, locs] = findpeaks(j);
% what now?
Rwave = pcks>th;
% what now?
Upvotes: 0
Views: 794
Reputation: 424
I suggest searching for wavelet-based methods. They are the most commonly used for this task
This paper might help. (The main author was a lecturer of mine at the Research Institute where I studied my Master's Degree)
Upvotes: 1