Anda di halaman 1dari 20

Selected Topics in Digital Signal Processing

DSP Applications in Biomedicine

Prof.Fatima
April 2015

Power Line Communication

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.

Power Line Communication

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

Proposed System Approach


Block Diagram and FIR Filter Design
Matlab Code and Explanation

Graphs
Understanding our Results

References

Power Line Communication

Electromagnetic Compatibility

List of Figures
Figure 1 ECG Heart Signal [1]
Figure 2 Patient Electrocardiography [2]

Figure 3 Understanding Our ECG Signal


Figure 4 Understanding Our Filter Designs to Retrieve Original Signal
Figure 5 Subplot of our ECG with noise
Figure 6 Subplot of our ECG with noise
Figure 7 Our Signal in the Scope

Power Line Communication

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.

P wave: represents the depolarization impulse across the atria


Q, R and Swaves: all these three waves represent the ventricular
depolarization (the downward stroke followed by and upward stroke is
called Q wave, the upward stroke is called R wave and any downward
sroke preceded by an upward stroke is called S wave)
T wave: represents the repolarization of the ventricles

Figure 8 ECG Heart Signal [1]

Power Line Communication

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.

Figure 9 Patient Electrocardiography [2]

An ECG signal shown above is ideal and its usually a reptitive signal.

Power Line Communication

1.2.

Electromagnetic Compatibility

How ECG is recorded?

Electrocardiography (ECG or EKG*) is the procedure of recording the


electrical action of the heart over a timeframe utilizing anodes put on a
patient's body. These terminals recognize the minor electrical changes on the
skin that emerge from the heart muscle depolarizing amid every pulse.

In a customary 12 lead ECG, ten terminals are set on the patient's


appendages and on the surface of the mid-section. The general extent of the
heart's electrical potential is then measured from twelve distinct points
("leads") and is recorded over a timeframe (as a rule 10 seconds). Along these
lines, the general extent and heading of the heart's electrical depolarization is
caught at every minute all through the cardiovascular cycle.[3] The diagram of
voltage versus time created by this noninvasive medicinal methodology is
alluded to as an electrocardiogram (abridged ECG or EKG).

Amid every pulse, a solid heart will have a deliberate movement of


depolarization that begins with pacemaker cells in the sinoatrial hub, spreads
out through the chamber, goes through the atrioventricular hub down into the
heap of His and into the Purkinje strands spreading down and to one side all
through the ventricles. This methodical example of depolarization offers
ascend to the trademark ECG following. To the prepared clinician, an ECG
passes on a lot of data about the structure of the heart and the capacity of its
electrical conduction system.[4] Among different things, an ECG can be
utilized to gauge the rate and beat of heartbeats, the size and position of the
heart chambers, the nearness of any harm to the heart's muscle cells or
conduction framework, the impacts of cardiovascular medications, and the
capacity of embedded pacemakers.[5]


Power Line Communication

Electromagnetic Compatibility

1.3.

Why the ECG is Important?

To help identify primary conduction abnormalities, cardiac arrhythmias,


cardiac hypertrophy, pericarditis, electrolyte imbalances, myocardial
ischemia, and the site and extent of myocardial infarction.

To monitor recovery from an MI.

To evaluate the effectiveness of cardiac medication.

To assess pacemaker performance

To determine effectiveness of thrombolytic therapy and the resolution of


ST-segment depression or elevation and T-wave changes.

1.4.

Physiological Background of the Heart

The heart is the pump in charge of keeping up sufficient flow of


oxygenated blood around the vascular system of the body. It is a four-load
pump, with the right side getting deoxygenated blood from the body at low
presure and pumping it to the lungs (the aspiratory course) and the left side
accepting oxygenated blood from the lungs and pumping it at high weight
around the body (the systemic dissemination).
The myocardium (heart muscle) is a specific type of muscle, comprising of
individual cells joined by electrical associations. The constriction of every
phone is delivered by an ascent in intracellular calcium fixation prompting
unconstrained depolarisation, and as every phone is electrically associated
with its neighbor, compression of one cell prompts an influx of
depolarisation and withdrawal over the myocardium.

Power Line Communication

Electromagnetic Compatibility

This depolarisation and compression of the heart is controlled by a specific


gathering of cells restricted in the sino-atrial hub in the right chamber the
pacemaker cells.
These cells produce a rhythmical depolarisation, which then spreads out
over the atria to the atrio-ventricular hub. The atria then contract, pushing
blood into the ventricles.
The electrical conduction passes by means of the Atrio-ventricular hub to
the heap of His, which partitions into right and left branches and after that
spreads out from the base of the ventricles over the myocardium. This
prompts a 'base up' compression of the ventricles, constraining blood up
and out into the pneumonic supply route (right) and aorta (left).
The "press" is called systole and regularly goes on for around 250ms. The
unwinding period, when the atria and ventricles re-fill, is called diastole;
the time given for diastole relies on upon the heart rate.

1.5.

Generation of Different Types of Noises

In sign handling, clamor is a general term for undesirable (and, by and


large, obscure) adjustments that a sign may endure amid catch,
stockpiling, transmission, preparing, or conversion.[6]
In some cases the word is likewise used to mean flags that are irregular
(erratic) and convey no helpful data; regardless of the possibility that
they are not meddling with different flags or may have been presented
deliberately, as in solace clamor.
Commotion lessening, the recuperation of the first flag from the clamor
adulterated one, is an exceptionally regular objective in the outline of
sign preparing frameworks, particularly channels. As far as possible for
commotion evacuation are set by data hypothesis, in particular the
NyquistShannon examining hypothesis.

Power Line Communication

Electromagnetic Compatibility

Additive noise, gets added to the intended signal

White noise

Additive white Gaussian noise


Pink noise
Black noise
Gaussian noise
Flicker noise, with 1/f power spectrum
Brown noise or Brownian noise, with 1/f2 power spectrum
Contaminated Gaussian noise, whose PDF is a linear
mixture of Gaussian PDFs
Power-law noise
Cauchy noise
Multiplicative noise, multiplies or modulates the intended signal
Quantization error, due to conversion from continuous to discrete
values
Poisson noise, typical of signals that are rates of discrete events
Shot noise, e.g. caused by static electricity discharge
Transient noise, a short pulse followed by decaying oscillations
Burst noise, powerful but only during short intervals
Phase noise, random time shifts in a signal

10

Power Line Communication

Electromagnetic Compatibility

(2) Procedure
2.1

Proposed System Approach:

Through careful studying we discovered that the most important signal


lies less than 35, and more than 265. Therefore a filter will be designed
to suppress every other signal between those ranges, to decrease the
degradation of our signal.
The other filter will surpass the 50 Hz power line interference, which is
a constant, and stable noise added. Therefore the power line interference
will be removed completely in our design.

2.2

Block Diagram and FIR Filter Design

Figure 10 Understanding Our ECG Signal


11

Power Line Communication

Electromagnetic Compatibility



Figure 11 Understanding Our Filter Designs to Retrieve Original Signal

2.3

Matlab Code and Explanation


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

Power Line Communication

Electromagnetic Compatibility

title('Powerline Intereference signal');


fft_of_Powerline_signal = fft(Powerline_signal);
subplot(3,3,5)
plot(frequency_vector,abs(fft_of_Powerline_signal(1:end/2)));
title('Powerline signal Intereference amplitude spectrum');
Random_noise = randn(1,2500);
subplot(3,3,7)
plot(time_vector,Random_noise);
title('Random noise signal');
fft_of_Random_noise = fft(Random_noise);
subplot(3,3,8)
plot(frequency_vector,abs(fft_of_Random_noise(1:end/2)));
title('Random noise signal amplitude spectrum');
ecg_and_powerline = y15 + Powerline_signal;
subplot(3,3,6)
plot(time_vector,ecg_and_powerline);
title('ECG with powerline noise signal');
ecg_and_powerline_and_random = Random_noise + ecg_and_powerline;
subplot(3,3,9)
plot(time_vector,ecg_and_powerline_and_random);
title('ECG with both random and powerline noise signals');
FIR_filter1 = ones(1,2500);
FIR_filter1(2500/5 - 1:2500/5 + 3) = zeros(1,5);
FIR_filter1(2500*4/5 - 1:2500*4/5 + 3) = zeros(1,5);
FIR_filter2 = zeros(1,2500);
FIR_filter2(1:350) = ones(1,350);
FIR_filter2(2151:end) = ones(1,350);
ECG_signal_power = sum(y15.^2)*(1/2500); % calculate signal power
SNR = 10^(SNRdb/10);
Noise_power = ECG_signal_power / SNR; % calculate noise power
Noise_power_db = 10 * log10(Noise_power/2);
Random_noise = wgn(1,2500,Noise_power_db);
Powerline_signal = sqrt(Noise_power) * sin(2*pi*time_vector*50);
signal_with_NOISE = Powerline_signal + Random_noise + y15;
figure;
subplot(3,3,1)
plot(time_vector,signal_with_NOISE);
title('ECG signal before filtering');
fft_of_signal_with_NOISE = fft(signal_with_NOISE);

13

Power Line Communication

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

Power Line Communication

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

Power Line Communication

Electromagnetic Compatibility

(3) Results
3.1

Graphs



Figure 13 Signal of ECG Before Filtering

Figure 12 Subplot of our ECG with noise

16

Power Line Communication

Electromagnetic Compatibility


Figure 14 Subplot after the ECG

17

Power Line Communication

Electromagnetic Compatibility

Figure 15 Our Signal in the Scope

18

Power Line Communication

Electromagnetic Compatibility

3.2

Understanding our Results

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

Power Line Communication

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.

3."ECG- simplified. Aswini Kumar M.D.". LifeHugger. Retrieved 11


February 2010.
4. Walraven, G. (2011). Basic arrhythmias (7th ed.), pp. 111
5. Braunwald E. (ed) (1997), Heart Disease: A Textbook of Cardiovascular
Medicine, Fifth Edition, p. 108, Philadelphia, W.B. Saunders Co.. ISBN 07216-5666-8.Jump up^


20

Anda mungkin juga menyukai