What is an ECG?
ECG is an abbreviation for electrocardiography. A heart's electrical activity can be known by the ECG test. A set of electrodes are used to capture the biopotentials and convert them into electrical signals. The ECG is basically a 2D plot of time v/s voltage.
The measured ECG signal that is the output voltage of the set of electrodes is in the range of 1mv to 5mv approx. This needs to be amplified using a high gain amplifier. The ECG signal also contains noises.
There are mainly 3 types of noise.
1. 50Hz noise due to the powerline.
2. High-frequency noise (Electromyogram -EMG noise).
3. Additive white gaussian noise.
4. Low-frequency noise (Baseline wandering).
Noisy ECG signal with baseline wandering
1. Amplifier circuit design:
A high gain instrumentation amplifier is the best to amplify the ECG signal. An instrumentational amplifier has got high gain and high CMRR(common-mode rejection ratio). The amplifier has got two input legs(V1 and V2), electrodes are connected to the two input terminal of the amplifier. The noise which is common to both(V1 and V2) the terminals are going to get rejected, the instrumentation amplifier is not going to amplify the noise that is common to both the electrodes.
picture credit: circuits today
Instrumentational amplifier design:
The design aim is to get the value of the Rg resistor by considering some R1, R2, R3-value, and the gain. The gain is 100 and let's consider R1 =R2 =R3 = 10kohm.
The gain of an Instrumentation is given by - gain = (1+ 2 x R1/Rg) x R3/R2
Rg = 200ohm
Matlab simscape model:
2. Low pass filter design: An RC low pass filter can be used to remove the high-frequency noise in the ECG signal.
The output voltage is taken across the capacitor. The above filter is designed for 150Hz cut-off frequency.
The frequency response of a low filter.
The ideaL low pass filter which passes all the signals with frequencies below the cut-off frequency without any attenuation and does not pass the signals with frequencies above cut-off frequencies. But in practice, the low pass filter attenuates the signals which are above the cut-off frequency to an extent. The meaning of the term 'attenuation' is reducing the amplitude of the input signal. For the signal having a frequency equal to the cut-off frequency, the output signal amplitude will be 70.7% of the input signal amplitude.
The order of the filter plays an important role. The higher the order of the filter better the performance. That is in the case of low pass filter, as we increase the order of the filter, the filter attenuates high-frequency components of a signal more.
2nd order low pass filter
3rd order low pass filter
|
Transfer function model (low pass filter) |
The concept, 'order of a filter' is best understood by plotting a bode plot of the filter.
|
1st order low pass filter 2nd order low pass filter 3rd order low pass filter
|
In the above bode plot, we can observe the magnitude(dB) reduces with an increase in the order of the filter at the cut-off frequency.
Notch filter:
It is a type of bandstop filter. It is also called a narrow bandstop filter. It is used to remove a specific frequency component of a signal. In the case of the ECG signal, it is used to remove 50Hz power line interference.
|
Notch filter
|
Design:
Notch filter's transfer function:
|
Bode plot(Noth filter f = 50Hz) |
|
2nd order notch filter |
Simscape model
2nd order Notch filter's transfer function model.
2nd order notch filter: It is a cascade network of two notch filters, the output of the first notch filter is given as the input to the 2nd notch filter. The second-order filter is used to get more attenuation of the 50Hz component.
High pass filter:
It is a passive RC high pass filter. The output is taken across the resistor. It is designed for a cut-off frequency of 0.5Hz. The frequencies below the cut-off frequency are responsible for baseline wandering.
Transfer function and design:
Taking
c = 1uF , fc = 0.5Hz
R
= 1/(2*pi*C*f)
R = 318.47K ohms
-
The
performance of a single RC high pass filter is not satisfactory as there is a
very small attenuation of low-frequency signals. More attenuation can be achieved by using a higher-order high pass filter. A
3rd order high pass filter gives a satisfactory output.
\
Bode plot of 1st, 2nd, and 3rd order high pass filter.
ECG amplifier and filter Matlab-simscape model:
Transfer function model:
Each subsystem contains transfer functions.
Input ECG signal
Matlab program that loads the ECG signal and adds 50Hz, high frequency, and low-frequency noise to the input signal.clc
clear all
close all
fs = 125; % ECG data sampling rate
dt = 1/fs;
load('E:\7th sem\biomedinst\MLII\2 APB\100m (0).mat')
plot(val)
timeVector = dt*[0:length(val)-1]';
y1 = 30*sin(2*pi*50*timeVector)';
y2 = 15*sin(2*pi*500*timeVector)';
y3 = 10*sin(2*pi*0.2*timeVector)'+10*cos(2*pi*400*timeVector)'+5*cos(2*pi*1000*timeVector)';
m=[[20*ones(1,1000)] [100*ones(1,1000)] [200*ones(1,1000)] [50*ones(1,600)]];
%y4 = 5*sin(2*pi*1000*t);
%y5 = 10*sin(2*pi*0.1*timeVector);
%val=val+y1+y2+y3+y4+y5;
val=val+y1+y2+m;
%val = awgn(val,0);
val = val*10^-2;
val = awgn(val,50,'measured');
var.time =timeVector;
var.signals.values=[val'];
figure()
subplot(2,1,1);
plot(var.time,var.signals.values);
title("Noisy ECG signal")
subplot(2,1,2);
disp("Enter 1")
x=input('enter');
if(x==1)
plot(Y.Data)
title("Filtered ECG signal")
end
Noisy ECG signal is the input to the amplifier and filter model.
The output of the ECG amplifier and filter matlab-simulink-simscape model:
Note: The above circuit is designed for educational purposes if any pieces of information are wrongly conveyed, please comment below, it will be corrected as soon as possible.
Awesome!
ReplyDeleteNiiceee
ReplyDeleteGreat! Well written
ReplyDelete