This is a period of time to do a course design, do relatively simple, do not take into account too thin, but initially to achieve the desired effect. This design is mainly to pre-processing ECG signals, some of the interference contained in its signal is filtered out or suppressed.
First, ECG signal
(1) Characteristics of ECG signal
Human ECG is a very weak physiological low frequency electrical signal, usually the maximum amplitude of not more than 5mV, signal frequency at 0. Between the 05~100hz. ECG signals are picked up by electrodes installed on the surface of the human skin. Due to polarization between the electrodes and the skin tissue, there is a serious disturbance to the ECG signal. In addition, the human body is a complex life system, there are a variety of other physiological electrical signals to the ECG signal interference. At the same time, because we are in an electromagnetic environment, the human body is like a moving antenna, so that the ECG signal will produce about 50Hz interference signal. ECG signal has weak, low frequency, high impedance and other characteristics, very easy to be disturbed, so the analysis of the source of interference, for different interference to take the corresponding filtering measures, is a key consideration of data acquisition problem. There are several common disturbances:
② baseline drift ③ EMG disturbance of ① power frequency interference
ECG signal has the following characteristics:
• The signal is extremely faint, generally only 0.05~4mv, the typical value is 1mV;
• Low frequency range, frequency range of 0.1~35hz, mainly concentrated in 5~20hz;
• There is instability. The mutual influence of each organ in the human body and each person's heart position, breathing, age, whether often exercise and other factors, will make the ECG signal changes accordingly;
• Interference noise is strong. When the ECG signal is measured, it is necessary to communicate with the outside world, but because of its very faint signals, various interference noises are very easy to influence the measurement.
The noise may come from power frequency (50Hz) interference, electrode contact noise, motion artifacts, EMG noise, baseline drift caused by respiration, and changes in ECG amplitude, as well as machine noise in other electronic devices.
(2) Selection of ECG signal
The ECG signal used in this experiment is from the Mit-bih library (arrhythmia database , the introduction of this library can be consulted: Click to open the link), the library has 48 groups of abnormal ECG signals, The ECG signal (i.e., EMG interference, power frequency interference and baseline drift) that meets the requirements of the experiment is identified.
(3) Normal ECG waveform
Fig. 1 waveform of normal ECG signal
Figure 1 is the normal ECG signal in a period of waveform, by the P-Wave, QRS group and T-Wave composition.
P waves are produced by the depolarization of the atria, their waveforms are smaller, the shape is somewhat rounded, the amplitude is about 0.25mV, and the duration is 0.08~0.11s. The sinus junction depolarization occurs before the atrial myocytes are depolarization, so the time is preceded by P wave, but the sinus node is inside the heart and its electrical activity is difficult to collect on the surface.
The P-r period is the time between the beginning of the P wave and the beginning of the QRS cluster, the excitement of the Sinus knot, and the time it takes to reach the ventricles after the right atrium, the left atrium, the atrioventricular Junction area, the atrioventricular bundle, and the bundle branch. In the normal body surface electrocardiogram, the value of the P-r interval is 0.12~0.2s, most of which is the time required to excite the conduction in the Atrioventricular junction area. The P-r period is also known as atrioventricular conduction time.
The p-r segment refers to the time span between the P-wave endpoint and the beginning of the QRS wave group. In normal body surface electrocardiogram, the ECG potential value of P-r segment is very small point near the baseline level. During the P-r period, the left and right atria were simultaneously excited, so the combined electric field produced by the two had less effect on the surface electrocardiogram. In addition, the excitement at this time is also in the Atrioventricular Junction area and the atrioventricular bundle special conduction system, did not reach the ventricle, thus did not produce the large fluctuation of the surface electrocardiogram signal.
QRS Wave Group is the reaction of the external negative potential of the left and right ventricular myocytes to the surface of the membrane. The duration of the QRS wave group is 0.06~0.1s. Because the ventricular myocytes in the excitement process of the integrated electric field vector changes several times, thus forming the surface electrocardiogram in the size and direction of multiple changes in the ECG signal, wherein the QRS wave group, the first downward wave is the Q wave, the first upward wave is R wave, the R wave behind the S-wave.
The S-T segment refers to the time spanned between the end of the QRS cluster and the start of the T wave. During the period of s-t, the muscle cells of the left and right ventricle are in the excitement, so the contribution of the integrated electric field vectors formed in the surface electrocardiogram is very small, resulting in the s-t Duanxinzhi electrical signal at about the baseline level.
T-wave is produced by complex polarization of ventricular myocytes, the amplitude of which is 0.1~0.8mv and duration is 0.05~0.25s. Due to the existence of complex polarization, the direction of T-wave is consistent with the direction of the main wave of the QRS wave group. In the case of R-wave upward, the amplitude of T-wave is generally more than 1/10 of the amplitude of R-Wave. Q-t is the time period between the beginning of the QRS cluster and the end of T wave, which represents the time required for the ventricular myocytes to begin to depolarization to the end of the repolarization, negatively correlated with heart rate.
Second, the choice of filter
1. Interference filtering-low-pass filter
in general, the frequency of EMG signals is 20~5000hz, the main components of the frequency and the type of muscle, generally in the 30~300hz, and the frequency of ECG is mainly concentrated in the 5~20hz, so choose a low-pass filter to filter out the EMG interference.
The characteristic of the Butterworth filter is that the frequency response curve in the passband is the most flat, no ups and downs, and the band decreases gradually to zero. The amplitude diagonal frequency of the Butterworth filter is monotonically decreasing, and the higher the order of the filter is, the faster the attenuation rate of the amplitude of the band is, the higher the amplitudes of the other filters have different shapes of the diagonal frequency and the amplitude diagonal frequency of the lower order.
2. Suppression of power frequency interference-band notch filter
Due to the ubiquitous power supply network, 50HZ frequency interference is the most common and the main interference source of ECG signal. The software design method of 50HZ Notch is varied, the common methods are wavelet transform filter, Adaptive filter and template matching filter, but all of them need to be calculated by hand to obtain the parameters of the filter, and the operation is more complicated.
In the filter design, the use of IIR filter can reduce the order, reduce the computation, but destroy the phase characteristic; The FIR filter can not only get good filtering effect, but also the waveform distortion reaches the bottom, and the FIR filter can be made linear phase characteristic, which is exactly the need of ECG signal filtering.
The method of designing FIR filter with MATLAB is window function method, frequency sampling method and Chebyshev approximation method, and the 50HZ notch filter is designed by Window function method in this course. The basic idea of the window function method is to select an appropriate ideal low-pass filter according to the requirement, because its impulse response is non-causal and infinitely long, using the optimal Window structure window function to intercept its impulse response, thus obtaining the linear phase and the causal FIR filter. Kaiser window is close to the optimal window structure of the window function, it can be adjusted according to different parameters of the filter indicators, so the use of Kaiser window function Filter Design disturbance suppression-band notch filter
3. Correction of baseline drift-0 phase shift Filter
0 Phase Shift filter refers to a signal sequence after the filter filter phase does not change, that is, the filter system function phase response is zero. Obviously, it is impossible for a causal system to achieve zero phase shift, it is impossible to achieve zero phase shift without prior knowledge of the signal phase spectrum. The 0 phase shift is only for non-causal systems. Specifically, the 0 phase shift filter uses the information contained in the signal points in front and back of the current signal point, essentially using "future information" to eliminate phase distortion.
Iii. Procedures and Results
1. ECG Reading
because of the Mit-bih library is not very familiar with the official online after reading, still do not understand (all English, but also medical ...) )。 So, here the ECG reading program is from the online rddata.m, detailed can refer to click to open the link. If you want to use it, after selecting the ECG signal to be processed, change the path, and select the appropriate number of samples, it is OK. I chose the Mit-bih in the 109, the sample number is 1500, for the ECG signal after reading the graph:
Figure 2 Mit-bih Library 109 ECG diagram (dual channel)
From the figure 2 red curve can be seen, there are many "burrs" on the waveform, and its phase changes (in the case of peaks, the peaks are roughly not a horizontal line, that is, "baseline drift"), some waveforms received more serious interference, more in line with the signal processing requirements.
2. pretreatment of ECG Signal
(1) Removal of EMG signal
clc;%------------------------------Low-pass filter to remove EMG signal------------------------------fs=1500; % sampling frequency fp=80;fs=100; % pass band cutoff frequency, resistance band cutoff frequency rp=1.4;rs=1.6; % pass band, resistance band Attenuation Wp=2*pi*fp;ws=2*pi*fs; [N,wn]=buttord (Wp,ws,rp,rs, ' s '); % ' s ' is to determine the Butterworth analog filter order and 3dB cutoff analog frequency [Z,p,k]=buttap (n); % Design normalized Butterworth analog lowpass filter, z is Pole, p is 0 points and K is gain [BP,AP]=ZP2TF (z,p,k)% converted to Ha (p), BP is molecular coefficient, AP is denominator factor [BS,AS]=LP2LP (BP,AP,WP)%ha (p) Converted to low-pass ha (s) and normalized, BS for molecular coefficients, as for denominator coefficients [hs,ws]=freqs (Bs,as); The amplitude-frequency response of the% analog filter [Bz,az]=bilinear (BS,AS,FS); % to analog filter bilinear transform [H1,w1]=freqz (Bz,az); The amplitude-frequency response of the% Digital filter M=filter (bz,az,m (:, 1)); Figurefreqz (Bz,az); title (' Butterworth low-pass filter amplitude-frequency curve '); Figuresubplot (2,1,1);p lot (Time,m (:, 1)), Xlabel (' t (s) '), Ylabel (' mv '), title (' Primitive ECG waveform '), Grid;subplot (2,1,2);p lot ( TIME,M); Xlabel (' t (s) '); Ylabel (' mv '); title (' Low-pass filtered time domain graph '); grid; N=512n=0:n-1;mf=fft (M (:, 1), N); % for spectral transformation (Fourier transform) mag=abs (MF), f= (0:length (MF)-1) *fs/length (MF); % for frequency conversion figuresubplot (2,1,1) plot (F,MAG);Axis ([0,1500,1,50]); grid; % Draw Spectrum graph Xlabel (' frequency (HZ) '); Ylabel (' amplitude '); title (' ECG Spectrum map '); Mfa=fft (m,n); % for spectral transformation (Fourier transform) maga=abs (MFA), Fa= (0:length (MFA)-1) *fs/length (MFA); % for frequency conversion subplot (2,1,2) plot (Fa,maga); axis ([0,1500,1,50]); grid; % Draw Spectrum graph Xlabel (' frequency (HZ) '); Ylabel (' amplitude '); title (' Low-pass filtered ECG signal spectrum map '); Wn=m (:, 1); P=10*LOG10 (ABS (FFT (WN) ^2)/N), f= (0:length (p)-1)/length (p); Figureplot (f,p); Gridxlabel (' normalized frequency '); Ylabel (' Power (DB) ') Title (' Power spectrum of ECG ');The results of the above procedure are as follows:
Fig. 3 Fig. 4
Fig. 5 Fig. 6
Figure 3 is the design of the Butterworth digital low-pass filter of the amplitude-frequency response curve, Figure 3 is the time-domain filter before and after the ECG waveform diagram, Figure 5 is in the frequency domain before and after the ECG signal Spectrum diagram, Figure 6 is the ECG Power spectrum diagram
(2) Suppression of power frequency interference
%-----------------Notch filter suppresses power-frequency interference-------------------%50hz notch: A low-pass filter plus a high-pass filter composition% and a high-pass filter from a full-pass filter minus a low-pass filter to form the me=100; % of filter order L = 100; % window length beta=100; % attenuation coefficient fs=1500;wc1=49/fs*pi; The%WC1 is a high-pass filter cutoff frequency, corresponds to 51HZWC2=51/FS*PI,%WC2 is a low-pass filter cutoff frequency corresponding to 49HZH=IDEAL_LP (0.132*pi,me)-IDEAL_LP (wc1,me) +IDEAL_LP (WC2, ME); The%h is a notch response w=kaiser (L,beta); Y=h.*rot90 (w); The%y is a 50Hz notch shock response sequence M2=filter (y,1,m), Figuresubplot (2,1,1);p lot (ABS (h)), axis ([0 0 0.2]), Xlabel (' Frequency (Hz) '), Ylabel (' Amplitude (MV) '); title (' Notch amplitude spectrum '); grid; n=512; P=10*LOG10 (ABS (FFT (y). ^2)/N), f= (0:length (P)-1), subplot (2,1,2);p lot (f,p), Xlabel (' Frequency (Hz) '), Ylabel (' Power (DB) '); Title (' Notch Power spectrum '); grid; Figuresubplot (2,1,1); Plot (time,m); Xlabel (' t (s) '); Ylabel (' amplitude '); title (' Original signal '); Grid;subplot (2,1,2);p lot (time,m2); Xlabel (' t (s) '); Ylabel (' amplitude '); title (' Band-stop filter Post signal '); grid; Figuren=512subplot (2,1,1);p lot (ABS (FFT (m)) *2/n), axis ([0 0 1]); Xlabel (' t (s) '); Ylabel (' amplitude '); title (' Original Signal spectrum '); Grid;subpLot (2,1,2) is;p lot (abs (FFT (m2)) *2/n), axis ([0 0 1]), Xlabel (' t (s) '); Ylabel (' amplitude '); title (' Band-stop filtered signal spectrum '); grid; where the IDEAL_LP () function is in another m file, as follows:% Ideal low pass filter% cutoff frequency WC, order mefunction HD=IDEAL_LP (wc,me) alpha= (Me-1)/2;n=[0:me-1];p = N-alpha+eps; %eps for a very small number, avoid being 0 apart from Hd=sin (wc*p)./(Pi*p); % with sin function to generate impact responseThe results of the above procedure are as follows:
Fig. 7 Fig. 8
Figure 9
Figure 7 is a band-notch filter amplitude spectrum and power spectrum, you can see at 50Hz, the amplitude of the filter is very large, and the power under 150, indicating a better notch performance. Figure 8 is the time domain filter before and after the ECG diagram, it can be seen that the waveform has a slight improvement after filtering . Figure 19 is a spectrum of ECG signals before and after filtering in the frequency domain.
(3) Correction of baseline drift
%------------------IIR 0 Phase Shift Digital filter corrects baseline drift-------------------wp=1.4*2/fs; % pass band cutoff frequency ws=0.6*2/fs; % resistance band cutoff frequency devel=0.005; % pass Band Ripple Rp=20*log10 ((1+devel)/(1-devel)); % pass band Ripple coefficient rs=20; % resistive band attenuation [N Wn]=ellipord (Wp,ws,rp,rs, ' s '); The order of the ellipse filter is obtained [b a]=ellip (N,rp,rs,wn, ' High '); The coefficients of the elliptic filter are obtained [HW,W]=FREQZ (b,a,512); Result =filter (B,A,M2); FIGUREFREQZ (B,a); Figuresubplot (211); Plot (TIME,M2); Xlabel (' t (s) '); Ylabel (' amplitude '); title (' Original signal '); Gridsubplot (212); Plot (Time,result); Xlabel (' t (s) '), Ylabel (' amplitude '), title (' Linear filter post signal '), grid Figuren=512subplot (2,1,1);p lot (ABS (FFT (m2)) *2/n); Xlabel ( ' Frequency (Hz) '), Ylabel (' amplitude '), title (' Original Signal spectrum '), Grid;subplot (2,1,2);p lot (ABS (FFT (Result)) *2/n), Xlabel (' Frequency (Hz) '); Ylabel ( ' Amplitude '), title (' After linear filtering '), Grid;subplot (2,1,2);p lot (ABS (FFT (Result)) *2/n) Xlabel (' Linear filtered signal spectrum '); Ylabel (' amplitude '); grid;
Results of the above procedure:
Fig. 10 Fig. 11
Figure 10 is the time domain filter before and after the ECG diagram, it can be seen that the baseline drift has been improved , Figure 11 is in the frequency domain filter before and after the ECG spectrum map .
The preprocessing of ECG signal based on MATLAB