R wave peak detection matlab simulation of electrocardiogram data

Table of contents

1. Theoretical basis

2. Core program

3. Simulation conclusion


1. Theoretical basis

      Electrocardiogram (ECG or EKG for short) is a physiological signal that records the electrical activity of the heart. The peak R wave is the most prominent feature on an ECG, signifying the heart's ventricular contraction and is commonly used to calculate heart rate and analyze heart rhythm. R-wave peak detection is an important step in ECG signal processing. This paper will introduce in detail the system principle and specific mathematical formula of the R-wave peak detection of ECG data.
       R-wave peak detection of ECG data is a signal processing process, which mainly includes three steps: preprocessing, feature extraction and peak detection.

       Preprocessing: First, preprocessing the ECG data, including filtering to remove noise, baseline drift and interference, etc. Common filtering methods include low-pass filtering, high-pass filtering, and notch filtering. The purpose of preprocessing is to reduce noise and interference, and retain the information of the R-wave peak.

      Feature extraction: The next step is to extract features from the preprocessed ECG data for better peak detection. Commonly used feature extraction methods include signal amplitude, slope, energy, etc.

      Peak detection: Finally, use a suitable peak detection algorithm to identify the R-wave peak. Commonly used peak detection algorithms include threshold method, moving average method, difference method, peak and valley method, etc.
The following is an example of a mathematical formula for R-wave peak detection of ECG data:

Preprocessing:
low pass filtering:

Among them, $x[n]$ is the original signal, $y[n]$ is the filtered signal, and $N$ is the filter order.

High-pass filtering:

 

Notch filtering: 

Among them, $\omega$ is the cut-off frequency of the notch filter. 

Feature extraction:

Signal Amplitude:

Signal energy: 

Peak detection:
threshold method:
set a threshold $T$, when the signal amplitude exceeds the threshold, it is judged as a peak value.

Moving average method:
Use a moving window to calculate the mean value of the signal, and when the signal amplitude exceeds the mean value, it is judged as the peak value.

Difference method:
Calculate the difference of the signal amplitude, when the difference value exceeds the set threshold, it is judged as the peak value.

Peak and valley method:
detect the first-order derivative of the signal amplitude, and judge it as the peak value when the first-order derivative changes sign.

The difficulty in realizing the R-wave peak detection of ECG data lies in the selection of appropriate filters and feature extraction methods, as well as the determination of the parameters and thresholds of the peak detection algorithm. Different ECG signals may have different noise and characteristics, which need to be adjusted and optimized for specific situations.

    In summary, the R-wave peak detection of ECG data is a signal processing process. Through the three steps of preprocessing, feature extraction and peak detection, the R-wave peak can be accurately detected, which provides strong support for the analysis and diagnosis of ECG signals.

2. Core program

En=[];
for i=1:15
    En(i)=0;
end
DL=length(Sign);
for l=16:DL-16
    EnergyN1=0.0000;
    for ll=l-15:l+16
        EnergyN1=EnergyN1+Sign(ll)^2;
    end
    En=[En,EnergyN1];
end
for j=DL-15:DL
    En(j)=0;
end
Elen=length(En);  
Emean=mean(En);
maxE=max(En);     
Thresh1=0.5*Emean;   % set threshold 此处阈值的设定需要尝试~~~~~~~~~~
for j=1:Elen
    if En(j)<Thresh1
        En(j)=0.0000;
    end
end
En1Peak=[];   %初步得到的能量峰点
Eavr=[];     %能量峰平均间隔
Epeak=[];  %改进后的能量峰点
Mpeak=[];  %中间数组
Mavr=[];  %中间数组
PM=0.0000;
InterR=0;
%-------初步得到能量峰值点----------------
for ii=2:Elen
    if En(ii)>=PM
        PM=En(ii);
        Epoint=ii;
        InterR=0;
    else
        InterR=InterR+1;
        if InterR>108             % *********参数可改
            En1Peak=[En1Peak,Epoint];
            InterR=0;
            PM=0.0000;
        end
    end
end    
%-----计算平均峰值点间隔---------.
for avr=2:length(En1Peak)
    Eavr=[Eavr,(En1Peak(avr)-En1Peak(avr-1))];
end
AEavr=mean(Eavr);   %平均间隔
%-----改进峰值点-------------
for jj=2:length(En1Peak)
    if En1Peak(jj)-En1Peak(jj-1)<=0.6*AEavr 
       if En(En1Peak(jj-1))>=En(En1Peak(jj))
          Epeak=[Epeak,En1Peak(jj-1)];
       end    
    elseif En1Peak(jj)-En1Peak(jj-1)>=1.6*AEavr
        [Evalue,Epo]=max(abs(En(En1Peak(jj-1):En1Peak(jj))));
        Epeak=[Epeak,En1Peak(jj-1)];   
        Epeak=[Epeak,En1Peak(jj-1)+Epo-1];
        %更新阈值
       Mpeak=[Epeak,En1Peak(jj:length(En1Peak))];
        for jjj=2:length(Mpeak)
            Mavr=[Mavr,(Mpeak(jjj)-Mpeak(jjj-1))];
        end
         AEavr=mean(Mavr);
    else Epeak=[Epeak,En1Peak(jj-1)];
    end
end
up2169

3. Simulation conclusion

 

Guess you like

Origin blog.csdn.net/ccsss22/article/details/131838533