ECG Electrodes and electronics
Copyright (C) 2021 Miodrag Bolic
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details <https://www.gnu.org/licenses/>.
Dependencies: ecg.mat, AmplifyFilterDryElectrodes.slx, AmplifyFilterDryElectrodesCM.slx
% Changing the path from main_folder to a particular chapter
main_path=fileparts(which('Main_Content.mlx'));
%addpath(append(main_path,'/Chapter2'))
cd (append(main_path,'/Chapter7/ECGFrontEnd'))
addpath(append(main_path,'/Service'))
SAVE_FLAG=0; % saving the figures in a file
Introduction
In this notebook we will show different ECG circuits and introduce driven right leg circuit. Let us first import the ECG signal:
qrs(:,2)=(ecg/1000)/2; % * 2 is because we are adding two ECG signals in Simscape
qrs(:,2)=qrs(:,2)-mean(qrs(:,2));
qrs(:,1)=1/fs:1/fs:length(ecg)/fs;
plot(qrs(:,1), qrs(:,2)*1000*2) % * 2 is because we are adding two ECG signals in Simscape
xlabel('Time (s)', 'FontSize', 10)
ylabel('Voltage (mV)', 'FontSize', 10)
title('Original ECG signal')
annonation_save('a)',"Fig7.10a.jpg", SAVE_FLAG);
Dry electrodes, no common mode voltage, same electrode-skin interface
model_name = 'AmplifyFilterDryElectrodesNoElectModel';
plot(s.Vout.Time, s.Vout.Data)
xlabel('Time (s)', 'FontSize', 10)
ylabel('Voltage (V)', 'FontSize', 10)
title('Output ECG signal when dry electrodes are used')
annonation_save('b)',"Fig7.10b.jpg", SAVE_FLAG);
PowerRatio=spectrum_ratio(333, s.Vout.Data)
Dry electrodes, no common mode voltage, same electrode-skin interface, adding DC bias
model_name = 'AmplifyFilterDryElectrodes';
Bias of 100 mV.
plot(s.Vout.Time, s.Vout.Data)
xlabel('Time (s)', 'FontSize', 10)
ylabel('Voltage (V)', 'FontSize', 10)
title('Output ECG signal with dry electrodes and a DC ofset of 100 mV')
annonation_save('',"Fig7.12.jpg", SAVE_FLAG);
Bias of 200 mV.
plot(s.Vout.Time, s.Vout.Data)
xlabel('Time (s)', 'FontSize', 10)
ylabel('Voltage (V)', 'FontSize', 10)
title('Output ECG Signal')
Dry electrodes, no common mode voltage, different electrode-skin interface
model_name = 'AmplifyFilterDryElectrodes';
set_param('AmplifyFilterDryElectrodes/DryElectrodeSkinModelLA/Rep','R','300')
set_param('AmplifyFilterDryElectrodes/DryElectrodeSkinModelRA/Rep','R','300')
set_param('AmplifyFilterDryElectrodes/DryElectrodeSkinModelLA/Cep','C','0.02')
set_param('AmplifyFilterDryElectrodes/DryElectrodeSkinModelRA/Cep','C','0.02')
set_param('AmplifyFilterDryElectrodes/DryElectrodeSkinModelLA/Vh','v0','230')
set_param('AmplifyFilterDryElectrodes/Zero','Value','0')
plot(s.Vout.Time, s.Vout.Data)
xlabel('Time (s)', 'FontSize', 10)
ylabel('Voltage (V)', 'FontSize', 10)
title('Output ECG Signal')
Even though the skin impedance under the RA and LA electrodes changed and sweat component is included, the output did not change much.
PowerRatio=spectrum_ratio(333, s.Vout.Data)
Case 2: Vh of the electrodes are different
set_param('AmplifyFilterDryElectrodes/DryElectrodeSkinModelLA/Rep','R','1')
set_param('AmplifyFilterDryElectrodes/DryElectrodeSkinModelRA/Rep','R','1')
set_param('AmplifyFilterDryElectrodes/DryElectrodeSkinModelLA/Cep','C','5')
set_param('AmplifyFilterDryElectrodes/DryElectrodeSkinModelRA/Cep','C','5')
set_param('AmplifyFilterDryElectrodes/Zero','Value','0')
set_param('AmplifyFilterDryElectrodes/DryElectrodeSkinModelLA/Vh','v0','210')
plot(s.Vout.Time, s.Vout.Data)
xlabel('Time (s)', 'FontSize', 10)
ylabel('Voltage (V)', 'FontSize', 10)
title('Output ECG Signal')
Even though the skin impedance under the RA and LA electrodes changed and sweat component is included, the output did not change much.
set_param('AmplifyFilterDryElectrodes/DryElectrodeSkinModelLA/Vh','v0','230')
PowerRatio=spectrum_ratio(333, s.Vout.Data)
Dry electrodes, common model voltage no Driven Right Leg Circuit
In this case we consider a situation where dispacement current flows through the body. The current is modelled as 60 Hz sine wave signal with 0.2 uA DC value and 0.1 V amplitude. Body's resistance is set to 100 kOhms. This results in a signal shown in the second figure. No driven right leg circuit was used.
model_name = 'AmplifyFilterDryElectrodesCM';
Let us consider a circuit without the third electrode and DRL circuit
set_param('AmplifyFilterDryElectrodesCM/Rb','Commented','off')
set_param('AmplifyFilterDryElectrodesCM/DryElectrodeSkinModelRL','Commented','on')
set_param('AmplifyFilterDryElectrodesCM/DRL_Feedback','Commented','on')
set_param('AmplifyFilterDryElectrodesCM/GND4','Commented','on')
set_param('AmplifyFilterDryElectrodesCM/GND2','Commented','off')
plot(s.Vout.Time, s.Vout.Data)
xlabel('Time (s)', 'FontSize', 10)
ylabel('Voltage (V)', 'FontSize', 10)
title('Output ECG Signal')
plot(s.CM.Time, s.CM.Data)
xlabel('Time (s)', 'FontSize', 10)
ylabel('Voltage (V)', 'FontSize', 10)
title('Output Common mode signal')
Dry electrodes without Driven Right Leg Circuit
Let us consider a circuit with the third electrode and without DRL circuit.
In this case we consider a situation where dispacement current flows through the body. The current is modelled as 60 Hz sine wave signal with 0.2 uA DC value and 0.1 V amplitude. Third electrode is used and it is connected to the ground. This results in a signal shown in the second figure. No driven right leg circuit was used.
model_name = 'AmplifyFilterDryElectrodesCM';
set_param('AmplifyFilterDryElectrodesCM/Rb','Commented','on')
set_param('AmplifyFilterDryElectrodesCM/DryElectrodeSkinModelRL','Commented','off')
set_param('AmplifyFilterDryElectrodesCM/DRL_Feedback','Commented','on')
set_param('AmplifyFilterDryElectrodesCM/GND4','Commented','off')
set_param('AmplifyFilterDryElectrodesCM/GND2','Commented','on')
plot(s.Vout.Time, s.Vout.Data)
xlabel('Time (s)', 'FontSize', 10)
ylabel('Voltage (V)', 'FontSize', 10)
title('Output ECG signal without driven right leg circuit')
annonation_save('a)',"Fig7.14a.jpg", SAVE_FLAG);
plot(s.CM.Time, s.CM.Data)
xlabel('Time (s)', 'FontSize', 10)
ylabel('Voltage (V)', 'FontSize', 10)
title('Mixed common mode and ECG signal')
annonation_save('b)',"Fig7.14b.jpg", SAVE_FLAG);
PowerRatio=spectrum_ratio(333, s.Vout.Data)
Dry electrodes with Driven Right Leg Circuit
Let us consider a circuit with the third electrode and without DRL circuit
model_name = 'AmplifyFilterDryElectrodesCM';
set_param('AmplifyFilterDryElectrodesCM/Rb','Commented','on')
set_param('AmplifyFilterDryElectrodesCM/DryElectrodeSkinModelRL','Commented','off')
set_param('AmplifyFilterDryElectrodesCM/DRL_Feedback','Commented','off')
set_param('AmplifyFilterDryElectrodesCM/GND4','Commented','on')
set_param('AmplifyFilterDryElectrodesCM/GND2','Commented','on')
plot(s.Vout.Time, s.Vout.Data)
xlabel('Time (s)', 'FontSize', 10)
ylabel('Voltage (V)', 'FontSize', 10)
title('Output ECG signal with driven right leg circuit')
annonation_save('a)',"Fig7.16a.jpg", SAVE_FLAG);
plot(s.CM.Time, s.CM.Data)
xlabel('Time (s)', 'FontSize', 10)
ylabel('Voltage (V)', 'FontSize', 10)
title('Mixed common mode and ECG signal')
annonation_save('b)',"Fig7.16b.jpg", SAVE_FLAG);
It can be seen that the amplitude of the oscillations of the common mode voltage reduced from 0.1V to 0.0025V resulting in the reduction of common mode voltage by 40.
PowerRatio=spectrum_ratio(333, s.Vout.Data)
Exersizes
Excersize 1: repeat the analysis for all cases after replacing dry electrode models with wet electrode models. Observe the results.
Excersize 2: Analyze the effect of mismatch of the parameters of the electrodes (Rep, Cep, Vh) on the output ECG waveform as well as on the PowerRatio value in cases where there is no common mode voltage and in cases with common mode voltage.
Excersize 3: Consider textile electrodes that have very large impedance (assume 300 MOhms) and very low capacitance (assume 20 pF). How would behaviour of the system change is this case?
Excersize 4: Make ECG signal zero and consider only the reduction of common mode signal. How is common mode gain improved by changing the resistor Rf in the driven right leg circuit from 1 MOhm to 2 MOhm (5 MOhm)?
Excersize 5: Set tolerance of resistors R4-R7 to none. In this case, all the resistors will have the same values. Consider the cases where commom mode voltage exist and analyze if driven right leg circuit improves the result at the output. Comment your results.
function PowerRatio=spectrum_ratio(fs, ecg)
% Define frequency ranges of interest fot the signal
Nfft = (60*2*NyquistF)/FResBPM; %number of bins in power spectrum
[Pxx,F] = periodogram(ecg,hamming(length(ecg)),Nfft,fs);
% Compute power in the frequency band of the signal of interest
FMask1 = (F >= Fmask_low_sig)&(F <= Fmask_high_sig);
PowerSig = sum(Pxx(FMask1));
% Compute power in the total frequency band
FMask2 = (F >= Fmask_low_all)&(F <= Fmask_high_all);
PowerAll = sum(Pxx(FMask2));
% Compute signal quality indices = ratio of the power in the
PowerRatio=PowerSig/PowerAll;