Report Signal Petrai
Report Signal Petrai
University of Patras
Associate Professor E. Dermatas
Student: Petrai Elissaios
[email protected]
Patras 2018
Project 1: Two channels ECG - Remove artifacts and Noise
Theory
ECG Signal
Electrocardiogram (ECG) is the graphical representation of heart functionality. The ECG finds its
importance in the detection of cardiac abnormalities [1].
Electrical activity which is caused due to the muscle contraction gets reflected in the ECG signal
which is typically analyzed in the time domain. One normal sinus cycle of the ECG corresponds to
a single heartbeat. An ECG signal is typically labeled with the letters P, Q, R, S and T which
signifies its critical points as illustrated in Figure 1.
The frequency ranges from 0.67 to 120 Hz, and 0.67 Hz is the frequency (minimum) which is
observed when the pulse rate is 40 beats/min. Low frequency components consist of the P and T
waves (5–9 Hz) while the QRS complex resides at higher frequency.
Figure 1: ECG
The origins of these waves are:
1. P wave: sequential activation (depolarization) of the right and left atria
2. QRS complex: right and left ventricular depolarization
3. T wave: ventricular repolarisation
4. U wave: repolarisation of the papillary muscles, rarely seen
Noise and artifacts in ECG signals
Table 1: Types of ECG artifacts
Biosignals are usually contaminated with artifacts from limb movements, muscular contraction or
electrical interference.
The identification of a representative ECG signal may be affected or even compromised by the
presence of noise and artifacts. Anything that doesn't belong to the electrical activity generated by
the heart is described as interfering signal.
The sources of these artifacts can be physiological, such as muscle activity or skin movements, or
non-physiological as a result of neighboring electrical devices or incorrect use of the equipment [2].
Kinds of noise which are common in ECG signal are presented in the below pictures in Figure 2.
Both Figure 2a and 1b are usually a result of movements of the subject.
Figure 2a represents motion artifact (MA), which appears to be more related with random limb
movement.
Figure 2b represents Wandering Baseline (WB) which is a systematic modulation that represents
periodic movements, such as respiratory activity.
Figure 2: Common Kinds of Noise in ECG Signal
Figure 2c represents Muscular Activation Interference (MI), that means that the ECG is
contaminated with muscular contraction artifacts.
Figure 2d represents AC Interference (ACI) and it shows the presence of the baseline noise,
possibly due to the electromagnetic noise induction of the equipment and surrounding electronic
devices [2].
Table 2: ECG Noise Frequencies
Muscle Tremor: High frequency (20-150 Hz) and/or medium frequency (3-5 Hz)
Wavelet Transform:
The time-frequency representation of DWT is performed by repeated filtering of the input signal
with a pair of filters namely, low pass filter (LPF) and high pass filter (HPF), and its cutoff
frequency is the middle of input signal frequency. The coefficient corresponding to the low pass
filter is called as Approximation Coefficients and similarly, high pass filtered coefficients are called
as Detailed Coefficients. The approximation coefficient is consequently divided into new
approximation and detailed coefficients. This decomposition process is carried out until the required
frequency response is achieved from the given input signal. This multi-resolution analysis enables
us to analyze the signal in different frequency bands; therefore, we could observe any transient in
time domain as well as in frequency domain. The choice of mother wavelet can be selected based
on correlation between the signal of interest and the wavelet-denoised signal. Discrete Wavelet
(DWT) based wavelet denoising have incorporated using Transform different thresholding
techniques to remove power line interference from ECG signal. Thresholding methods are used to
denoise the ECG signals. For example, a wavelet decomposition until level 3, is represented in
Figure 4.
~ D
{
Dj= j
0,
if |D j|> λ
if |D j|≤λ
2. Soft threshold
~
Dj=
{
sign(D j )( D j −λ) if |D j|> λ
0, if |D j|≤λ
Algorithm Implemented
1. In time domain, an IIR notch filter is used in order to remove powerline noise (result is
displayed in Figure 5).
2. Decomposing of the noisy signal using wavelet transform. Using the discrete wavelet
transform by selecting mother wavelet (sym5 or sym8, db4, db6 etc), the noisy signal is
decomposed, at the decomposition level of 10. As a result approximate coefficients and
detail coefficients are obtained.
Table 3: 10 level Coefficients for Fs=360Hz
Coefficients Fs=360Hz
cD1 180-360
cD2 90-180
cD3 45-90
cD4 22.5-45
cD5 11.25-22.5
cD6 5.6-11.25
cD7 2.8-5.6
cD8 1.4-2.8
cD9 0.7-1.4
cD10 0.35-0.7
cA10 0.17-0.35
3. Removing Basline Wander. Baseline wander is a low frequency component, so is removed
by setting to zero cD10 and cA10 coefficients (results are displayed in Figure 6).
4. Reduction of EMG noise. Cumulative density function is calculated in order to apply a
thresholding window for the cD3 and cD4 coefficient. ( results are displayed in Figure 7)
5. Apply soft thresholing to the coefficients cD8 and cD9 in order to reduce motion artifacts.
The result is displayed in the final signal.
6. Removing high frequencies. Frequencies higher than 100Hz in a ECG has no useful
information. So coefficients cD1 and cD2 are set to zero. The result here again is displayed
in the final signal.
7. Reconstruct the wavelet using modified coefficients and same mother wavelet and same
level. Final results of all the above steps are shown in final signal displayed in Figure 8.
The results received from this implementation are appeared following.
Figure 1 displays the signal of channel 1 before and after the IIR Notch filter. The IIR Notch filter
was applied in both channels, however for comfortable reasons of view only the channel 1 is
displayed, in a random period of time.
Figure 9: Initial and Final Filtered Signal For the New ECG Signal
As in “project 1”, we have again same satisfactory results. However it is observed that channel 2
probably has negative polarity. At step of heart peak and mean heart beat calculation, only the one
channel is used. For this reason, we avoided to inverse the second channel.
Before running the new function, an average filter was used to the final signal in order to remove
glitches and to increase in this way the performance of peak detection.
Algorithm for R peak detection and mean heart rate calculation
This algorithm is implemented in the function Rpeakfinder. It takes three parameters, one the signal,
one the minimum distance between R peaks and finally the minimun height is excpected the R peak
to be.
1. This function stores R peaks locations and time that were occurred.
2. The algorithm works inspecting every value of signal to be higher than the previous and the
next one.
3. Next, from the previous values that it found, it compares which values are higher than the
threshold (minpeakh→ minimum peak height).
4. Finally, the values that were smaller than threshold (minpeakh→ minimum peak height) are
removed.
5. From values that remained from the previous step, the differentiation between every value
which it’s next was extracted. If this value satisfies minimum peak distance then it consider
to be an R peak.
6. Finally the matrix with locations of R peaks and the amplitude of signal for that location (i.e.
R peak), are returned.
The mean heart rate per minute results from the formula:
60
RR internal( seconds)
In our task is requires mean heart rate for half minute, the above formula implies to be:
30∗fs∗Total Number of Peaks
Total Number of Samples
The final results from algorithm implemented is displayed in following figure
The mean heart rate was found to be 30.42 beats per 30 seconds, otherwise almost 61 beats per
minute. This number is normal rate for a normal person.
2. The second approach was to remove the DC in time domain. After that to find the FFT of
the new signal. So in the frequency domain to cut-off low frequencies and high frequencies.
Finilly calculating the IFFT and ploting the final signal. Or we could do the same in time
domain designing some low pass and high pass filters. In both cases however, again the
result was not so satisfactory.
3. However, we preferred this approach just for the simplicity of implementation and the
almost clear result. The approach here was to remove first the DC component and after that
designing an IIR notch filter for removing power line in time domain (we preferred
removing 30Hz instead of 50Hz). In the final step we used the MATLAB built-in wavelet
automatic 1-D denoising function:
xd = wden(ecg_notch,'sqtwolog','s','mln',100,'sym5');
In this way with an extremely short code implementation we had better results than the other
two approaches.
Instead of sym5, we had good results with other wavelet families as ‘sym8’, ‘db4’, ‘db6’,
but we preferred (almost randomly ‘sym5’) and “100” for level decomposition after some
experiments trying different levels. Following, we display the initial signal and the final
filtered signal Figure 12.
The result it is like we have an contaminated PRQRST with an other (second) ECG signal
(see the zoom in part at samples 570000 to 650000. It sensible the information to be on the
second signal. So possibly, it would be a good approach in some way to remove big PQRST
which is beyond 1 x 106 and 1.3 x 106
Figure 13: Initial Signal and Signal after IIR Notch filter