Matlab Implementation of ECG Signal Processing: V.Viknesh & P. Ram Prashanth
Matlab Implementation of ECG Signal Processing: V.Viknesh & P. Ram Prashanth
Abstract: Signal processing today is performed in vast majority of systems for ECG analysis and
interpretation. The objective of ECG signal processing is manifold and comprises the improvement of
measurement accuracy and reproducibility and the extraction of information not readily available from the
signal through visual assessment. In many situations, the ECG is recorded during ambulatory or strenuous
conditions such that the signal is corrupted by different types of noise, sometimes originating from other
physiological process of the body. Hence noise reduction represents another important objective of ECG signal
processing. The paper mainly focuses on implementing the present day trends and procedures in the processing
of ECG signals using software (MATLAB). The implementation process helps us to understand the drawbacks
and difficulties of such methods and gives us an opportunity to work out towards finding a better solution. Such
a solution would satisfy the scope of improvement expected in the technologies, used at present.
Keywords: ECG, baseline wander, powerline interference, QRS detection
I. INTRODUCTION
Electrocardiographic signals may be recorded on a long timescale (i.e., several days) for
the purpose of identifying intermittently occurring disturbances in the heart rhythm. As a result,
the produced ECG recording amounts to huge data sizes that quickly fill up available storage
space. Transmission of signals across public telephone networks is another application in which
large amounts of data are involved. For both situations, data compression is an essential operation
and, consequently, represents yet another objective of ECG signal processing. It is a basic set of
algorithms that condition the signal with respect to different types of noise and artifacts, detect
heartbeats, extract basic ECG measurements of wave amplitudes and durations, and compress
the data for efficient storage or transmission; the block diagram in Fig. 1 presents this set of
signal processing algorithms. Although these algorithms are frequently implemented to operate in
sequential order, information on the occurrence time of a heartbeat, as produced by the QRS
detector, is sometimes incorporated into the other algorithms to im prove performance. The
complexity of each algorithm varies from application to application.
www.iosrjournals.org 40 | Page
Matlab implementation of ECG signal processing
The signal obtained doesn‟t exhibit any noise or baseline wander hence the processing of such a signal is
undesirable
Example: Here the variable used for proceeding with further processing is “ecg “.The properties of the variable
“ecg” is as follows:
Name Size Bytes class
ecg 4170*1 33360 Double array
The signal obtained exhibits noise and baseline wander hence the processing of such signal is explanatory at
each stage
www.iosrjournals.org 41 | Page
Matlab implementation of ECG signal processing
A. Baseline wander
Removal of baseline wander is required in order to minimize changes in beat morphology
that do not have cardiac origin, which is especially important wh en subtle changes in the „ „ low-
frequency‟ ‟ ST segment are analysed for the diagnosis of ischemia, which may be observed, for
example, during the course of a stress test. The frequency content of baseline wander is usually
in the range below 0.5 Hz; however, increased movement of the body during the latter stages of a
stress test further increases the frequency content of baseline wander.
Matlab coding to remove baseline wander:
%code for removal of baseline wander %
for i = 1 : 1 : length(ecg)
if i == 1
m(i)=ecg(i+1)-ecg(i);
end
if i > 1
m(i)= ecg(i)-ecg(i-1);
end
end
plot(m);
The waveform given by these values is as follows:
B. Powerline interference
Electromagnetic fields caused by a powerline represent a common noise source in the
ECG that is characterized by 50 or 60 Hz sinusoidal interference, possibly accompanied by a
number of harmonics. Such narrowband noise ren ders the analysis and interpretation of the
ECG more difficult, as the delineation of low-amplitude waveforms becomes unreliable and
spurious waveforms may be introduced. Although various precautions can be taken to reduce the
effect of powerline interference, for example, by selecting a recording location with few
surrounding electrical devices or by appropriately shielding and grounding the location, it may
still be necessary to perform signal processing to remove such interference. Several techni ques
have been presented for this purpose, ranging from straightforward linear, band stop filtering to
more advanced techniques that handle variations in powerline frequency and suppress the
influence of transients manifested by the occurrence of QRS complexes .A major concern when
filtering out powerline interfer ence is the degree to which the QRS complexes Influence the
output of the filter. The QRS complex acts, in fact, as an unwanted, large-amplitude impulse input
to the filter. As linear, time-invariant notch filters are generally more sensitive to the presence of
such impulses, powerline filters with a nonlinear structure may be preferable. In order to assure
that a filter does not introduce unacceptable distortion, its performance should be assessed by
means of simulated signals so that distortion can be exactl y quantified.
Matlab coding:
www.iosrjournals.org 42 | Page
Matlab implementation of ECG signal processing
Execution:
www.iosrjournals.org 43 | Page
Matlab implementation of ECG signal processing
else if (i-past_pos)>(10)
count=count+1;
pos(count)=i;
val(count)=denoisd(i);
past_pos=i;
end
end
end
stem(pos,val);
The graph obtained after the detection of QRS complexes is as follows:
www.iosrjournals.org 44 | Page
Matlab implementation of ECG signal processing
V. DATA COMPRESSION
The overall goal is to represent a signal as accurately as possible using the fewest number
of bits, by applying either lossless compression, in which the reconstructed signal is an exact
replica of the original signal, or lossy compression, in which the reconstructed signal is allowed to
differ from the original signal. With lossy compression, a certain amount of distortion has to be
accepted in the reconstructed signal, although the distortion must remain small enough not to
modify the diagnostic content of the ECG. For both types of compression, it may be necessary to
perform noise filtering of the ECG signal before it is subjected to data compression.
As a wide range of clinical examinations involve the recording of ECG signals, huge
amounts of data are produced not only for immediate scru tiny, but also for storage in a database
for future retrieval and review. It is well-known that the availability of one or several previous
ECG recordings improves diagnostic accuracy of various cardiac disorders, including myocardial
infarction. Today, such serial ECG comparison encompasses short -duration recordings acquired
during rest, but may in the future encompass long signals, for example, acquired during stress
testing or ambulatory monitoring. Although hard disk technology has undergone dramatic
improvements in recent years, increased disk size is paralleled by the ever -increasing wish of
physicians to store more information. In particular, the inclusion of additional ECG leads, the
use of higher sampling rates and finer amplitude resolu tion, the inclusion of other, non cardiac
signals such as blood pressure and respiration, and so on, lead to rapidly increasing demands on
disk size. It is evident that efficient methods of data compression will be required for a long time
to come.
An ECG signal exhibits a certain amount of redundancy, as manifested by correlation
bet ween adjacent samples, the recurrence of heartbeats with similar mor phology, and the
relative resemblance between different leads. Considerable savings can be achieved in terms of
storage capacity and transmission time by exploiting the different types of redundancy so that
each sample can be represented by fewer bits than in the original signal. Hence, the data
compression algorithm should account for the fact that the signal contains r ecurrent heartbeats,
often with similar morphology, and that the signal is, almost invariably, a multilead recording.
Equally important, it must account for the fact that both small - and large-amplitude waveforms
are present in the signal, carrying important diagnostic information, whereas the isoelectric line
contains negligible information.
The outcome of data compression is critically depen dent on the sampling rate and the
number of bits used to represent each sample of the original signal.
Matlab coding:
>> min_val=min(1000*denoisd);
>> approx_val=ceil(1000*denoisd);
>>approx_str=approx_val-min_val;
>> bin_val=dec2bin((approx_str));
>> dec_val=bin2dec(bin_val);
>> inter_val=dec_val+min_val;
>> final_res=(inter_val/1000);
>> plot(final_res);
>> hold all;
>> plot(denoisd);
Fig. 12 waveform indicating the input and output of a data compression and expansion scheme with a scaling factor of 1000
www.iosrjournals.org 45 | Page
Matlab implementation of ECG signal processing
Fig. 13 waveform indicating the input and output of a data compression and expansion scheme with a scaling factor of 100
This is most commonly emp loyed to estimate the distortion. However this method also imposes
some drawbacks .That is during the evaluation of PRD for large amplitude signals, this measure
always result in a low value
So we move on to a normalized parameter denoted by P r m s
Output:
Case 1:
(Scaling factor used is 100)
sum_sqr =
1.2655e-005
rms_err =0.0036
Case 2:
(Scaling factor used is 1000)
sum_sqr =
1.0094e-007
rms_err =
3.1771e-004
Thus the observations reveal the presence of greater noise and error in the usage of smaller scaling factor
VII. CONCLUSIONS
Thus such an implementation serves as an initiative towards the development of a computerized
diagnosis system. Further there are other provisions to convert the matlab programs to embedded c programs
www.iosrjournals.org 46 | Page
Matlab implementation of ECG signal processing
that tries to exhibit an increased performance over the hardware implementation of the same. To add these
systematic approaches are in the way of their progress in the fields of present day medicine like biotelemetry etc.
ACKNOWLEDGMENT
I would like to express my gratitude to all those who had been a support during the completion of this
paper. I would like to thank my college for proving a support and serving as a backbone during the paper
completion. I would like to thank all my friends to have provided useful and constructive criticisms during the
due course of completion.
REFERENCES
[1] Wiley Encyclopedia of Biomedical Engineering,2006 edition by John Wiley & Sons, Inc.
[2] The official website of matlab – www.mathworks.com( for the matlab documentation)
Design of ECG Signal Acquisition and Processing System (2012). Zeli Gao; Jie Wu; Jianli Zhou; Wei Jiang; Lihui Feng
[4] Implementation of ECG signal processing and analysis techniques in digital signal processor based system (2009). Balasubramaniam,
D.; Nedumaran, D.
[5] New aspects in ECG signal processing using adaptive filters (2011). Tudosa, I.; Adochiei, N.I.; Ciobotariu, R.
[6] Processing ECG signals using rational function systems (2012).Locsi, L.; Kovacs, P.
[7] Evaluation of novel ECG Signal Processing on Quantificatiojn of Transient Ischemia amd Baseline wander suppression (2007).
Kostic, M.N.; Fakhar, S.; Foxall, T.; Drakulic, B.S.; Krucoff, M.W.
[8] Image processing on ECG chart for ECG signal recovery (2009).Shen, T.W.; Laio, T.F.
[9] ECG signal acquisition and analysis for telemonitoring (2010).Plesnik, E.; Malgina, O.; Tasič, J.F.; Zajc, M.
[10] Power- line Interference Detection and Suppression in ECG Signal Processing (2008). Yue-Der Lin; Yu Hen Hu
www.iosrjournals.org 47 | Page