Prof.Fatima
April 2015
Electromagnetic Compatibility
Abstract
An ECG signal from a standard database sampled at 250 Hz is
corrupted with a sinusoidal powerline interference of 50 Hz and a random
noise. UsingMATLAB 7.0 we will generate these two types of noise and add
the noise to the ECG signal then calculate the SNR. An FIR filter will then be
design to remove the added types of noise and the SNR will be calculated.
Electromagnetic Compatibility
Table of contents
1.
1.1.
1.2.
1.3.
1.4.
1.5.
Introduction
2.
2.1.
2.2.
2.3.
Matlab Code
3.
3.1.
3.2.
Results
ECG
How ECG is Recorded?
Why the ECG is Important ?
Physiological Background of the Heart
Generation of the Different Types of Noise
Graphs
Understanding our Results
References
Electromagnetic Compatibility
List of Figures
Figure 1 ECG Heart Signal [1]
Figure 2 Patient Electrocardiography [2]
Electromagnetic Compatibility
(1) Introduction
1.1.
ECG
The ECG is recorded when the muscle contracts and expands , this
contraction and expansion causes a signal to be generated . ECG is also
the measurement of the heart Electrical activity.
Electromagnetic Compatibility
Figure 1 shows how the signal is created from the heart activity into a
signal. The ECG signal is measured by placing electrodes at specific points
on the body. Electrocardiography is a tool used to monitor electrical signals
generated by the heart. Below, in Figure 2.4, is a typical ECG waveform for
one heartbeat. An Electrocardiogram (ECG) is recorded using electrodes on
the skin surface. The electrodes are placed at various points on the torso
(see Figure 2.3). Many channels are used because some channels are able to
capture events which are not visible in others.
An ECG signal shown above is ideal and its usually a reptitive signal.
1.2.
Electromagnetic Compatibility
Electromagnetic Compatibility
1.3.
1.4.
Electromagnetic Compatibility
1.5.
Electromagnetic Compatibility
White noise
10
Electromagnetic Compatibility
(2) Procedure
2.1
2.2
11
Electromagnetic Compatibility
Figure 11 Understanding Our Filter Designs to Retrieve Original Signal
2.3
close all
clear all
clc
time_vector = 0:1/250:10-1/250; % t = 3600 (total samples) / 250
(sample per sec)
frequency_vector = linspace(0,125-125/1250,1250); % fs = 250 Hz
SNRdb = str2num(input('Enter SNR in dB','s'));
figure;
y15 = [];
for i = 1:10
x = ecg(250);
y15 = [y15 sgolayfilt(x,0,5)];
end
y15_f = fft(y15);
subplot(3,3,1)
plot(time_vector,y15);
title('ECG signal');
subplot(3,3,2)
plot(frequency_vector,abs(y15_f(1:end/2)));
title('ECG signal amplitude spectrum');
Powerline_signal = sin(2*pi*time_vector*50);
subplot(3,3,4)
plot(time_vector,Powerline_signal);
axis([0 1 -1.5 1.5])
12
Electromagnetic Compatibility
13
Electromagnetic Compatibility
subplot(3,3,2)
plot(frequency_vector,abs(fft_of_signal_with_NOISE(1:end/2)));
title('ECG signal before filtering amplitude spectrum');
fft_of_signal_without_NOISE = fft_of_signal_with_NOISE .* FIR_filter1;
signal_without_NOISE = ifft(fft_of_signal_without_NOISE);
subplot(3,3,4)
plot(time_vector,real(signal_without_NOISE));
title('ECG signal after first filtering (from power noise)');
subplot(3,3,5)
plot(frequency_vector,abs(fft_of_signal_without_NOISE(1:end/2)));
title('ECG signal after first filtering (from power noise) amplitude
spectrum');
fft_of_signal_without_NOISE = fft_of_signal_without_NOISE .*
FIR_filter2;
signal_without_NOISE = ifft(fft_of_signal_without_NOISE);
subplot(3,3,7)
plot(time_vector,real(signal_without_NOISE));
title('ECG signal after second filtering (from random noise)');
subplot(3,3,8)
plot(frequency_vector,abs(fft_of_signal_without_NOISE(1:end/2)));
title('ECG signal after second filtering (from random noise) amplitude
spectrum');
%% claclate SNR for the filtered signal
Noise_after_filter = signal_without_NOISE - y15;
Noise_power_after_filter = sum(abs(Noise_after_filter).^2) * (1/2500);
Output_SNR = ECG_signal_power / Noise_power_after_filter;
display(10 * log(Output_SNR))
display(Noise_power_after_filter)
display(ECG_signal_power)
%% plot the filters in frequency domain
subplot(3,3,6)
plot(frequency_vector,FIR_filter1(1:end/2));
title('Frequency response of filter for powerline signal');
subplot(3,3,9)
plot(frequency_vector,FIR_filter2(1:end/2));
title('Frequency response of filter for random noise');
% Create 10 period of ECG signal
sampled_ecg = ecg(250).'; %sample at 250, the ECH function in matlab
ourSignal = sgolayfilt(sampled_ecg,0,5); %expand and shrink signal to
see peaks
sampling_frequency = 250;
[M,N] = size(ourSignal);
% Initialize scopes
scope = dsp.TimeScope('SampleRate',sampling_frequency,...
'TimeSpan',10,...
'YLimits',[-1 1],...
'ShowGrid',true,...
'NumInputPorts',2,...
14
Electromagnetic Compatibility
'LayoutDimensions',[2 1],...
'Title','Noisy and Filtered Signals');
% Design lowpass filter
passband_frequency = 50;
stopband_frequency = 100;
passband_ripple = 0.05;
stopband_attenuation = 0.0001;
F
= [0 passband_frequency stopband_frequency
sampling_frequency/2]/(sampling_frequency/2);
magntiude_vector
= [1 1
0
0];
D
= [passband_ripple stopband_attenuation];
b = firgr('minorder', F, magntiude_vector, D);
Low_Pass_filter = dsp.FIRFilter('Numerator',b);
% Design Highpass Filter
stopband_frequency = 50;
passband_frequency = 100;
stopband_attenuation = 0.0001;
passband_ripple = 0.05;
F = [0 stopband_frequency passband_frequency
sampling_frequency/2]/(sampling_frequency/2); % Frequency vector
magntiude_vector = [0 0
1
1]; % Amplitude vector
D = [stopband_attenuation
passband_ripple];
% Deviation (ripple)
vector
b = firgr('minord', F, magntiude_vector, D);
Highpass_filter = dsp.FIRFilter('Numerator', b);
% Stream
tic;
while toc < 30
sampled_ecg = .1 * randn(M,N);
highFreqNoise = step(Highpass_filter,sampled_ecg);
combined_signal_noise
= ourSignal + highFreqNoise;
pure_filteredSignal = step(Low_Pass_filter,combined_signal_noise);
step(scope,combined_signal_noise,pure_filteredSignal);
end
% Finalize
release(scope)
15
Electromagnetic Compatibility
(3) Results
3.1
Graphs
Figure 13 Signal of ECG Before Filtering
16
Electromagnetic Compatibility
Figure 14 Subplot after the ECG
17
Electromagnetic Compatibility
18
Electromagnetic Compatibility
3.2
In the first diagram, we represent 8 graphs. The first graph shows our pure
ECG signal before any kind of interference. And then in the graph next to it
we represent the amplitude spectrum. As we can see most of the signal power
that we need lies between 0 to 35, and 235 up to 250.
In the second set of graphs in the same subplots, we represent our powerline
interfering signal, and its amplitude spectrum. We can see the peaks are at 50
and 200. In the third graph we add the power line graph to the ECG powerline
noise to give us the new ECG corrupted signal. We further add a white
Gaussian noise filter, which is our random signal to give us our last graph with
ECG corrupted with both noise signal and power signal.
In the second set of graphs, our ECG signal is shown before filtering and its
amplitude spectrum. We design our first filter to surpress the 50 peak and 200
peak caused by the 50 Hz power interference.
In the random noise, we surpress the low frequency components between 35 to
235 to retrieve as much from the signal as possible from the orginal ECG.
In our program the user has the control to enter the SNR he or she admires to
produce a better or worse signal.
19
Electromagnetic Compatibility
Reference:
1. "ECG Machine-EKG Machine-ECG-EKG-ECG Manufacturer-ECG LeadsChannels". Meditech.cn. N.p., 2016. Web. 11 Apr. 2016.
2. MN, Daisy et al. "Electrocardiography (ECG)". Nursing Crib. N.p., 2010.
Web. 11 Apr. 2016.
20