Professional Documents
Culture Documents
ECG Analysis: Pattern Recognition Basics I: Time Domain Methods
ECG Analysis: Pattern Recognition Basics I: Time Domain Methods
1200
(feature extraction)
ECG Analysis 1150
1100 QRSD
1050
1000
STD
950
850
TA
pattern recognition
classification
wave fast,
bandpass filtering
elevated amplitude
Detection of event-correlated
low amplitude other characteristic waves,
elimination of this ‘trigger wave’
The elimination of the baseline-offset (maybe also detrending)
allows the utilization of a constant threshold
PATTERN: time domain
PATTERN: time domain
Step3: Thresholding
Step2: Noise elimination by lowpass filtering
threshold
lowpas filtering 10 Hz
Reduction of noise
Be k={k(1)....k(M)} the series of positions for which holds
x(k(i))>threshold (∀ i∈(1,M))
Now we have to assign a position to the wave. The alignment point for Possibility 2: midpoint in between kpp(i) and kpn(i)
wave i lies between kpp(i) and kpn(i)
Complete MATLAB-example for wave extraction PATTERN: time domain
PATTERN: time domain
function [pos,sal]=prondpul(wave,facd,fs,matr,madel)
Step 5: Further processing %wave: input signal
Examples: averaging and shape analysis, mean(wave) %facd: threshold factor(between 0 y 1)
%fs: sampling frequency
interval analysis
%matr: samples backwards for alignment of waves
%madel: samples forward for alignment of waves
%pos: vector with the positions (maxima) of the waves
%sal: wave matrix, the columns are detected individual waves
sal=[];
wavef=lbmed(wave,40*fs/1000,fs); %baseline offset elimination
[b,c]=butter(2,20/fs); %filter coefficients
averaging of the signal wavef2=filtfilt(b,c,wavef); %bidirectional filtering
k=find(wavef2>max(wavef2)*facd); %calculate positions above threshold
1.25 [kpp,kpn]=prok(k,200*fs/1000); %starting and end points of waves
1.2
diff(pos)/fs for i=1:length(kpp)
1.15
[m,n(i)]=max(wavef2(kpp(i):kpn(i)));
1.1
end
0.8
end
wavel=[wavel (wave(pos1(i)-matr:pos1(i)+matl))];
end
0.75
0 10 20 30 40 50 60 70 80 90 100
wavef2=wavef2(:);
Nú mero de puls o
for i=1:length(pos)
sal=[sal wavef2(pos(i)-matr:pos(i)+madel)]; %assemble wave matrix
intervals before and after fiducial point time series of intervals end DEMO ECG-P-extraction : synchronous averaging.m
for i=1:length(kpp)
[m,n(i)]=max(y(kpp(i):kpn(i))); %calc of position (maximum)
end
r=kpp+n-1;
PATTERN: time domain PATTERN: time domain
lowpass filtered (yf)
differentiation (yfdds)
thresholding (yfds)
detected R peaks
1.15 3
1.1 2.5
1.05
2
RR (s)
1
1.5
0.95
1
0.9
0.5
0.85
0
0.8
4456 4458 4460 4462 4464 4466 4468 4470 4472 4474
0.75
0 10 20 30 40 50 60 70 80 90 100
number of beat
PATTERN: time domain
classical R-peak-detector with integrated filters
raw ECG signal, contaminated with filtered ECG signal, contaminated with FIR-lowpass,
noise and interferences 50-Hz-filter noise linear phase
1.5 20
0.5 10
0
0 5
0 50 100 150 200 250 300 350 400 0
-100
0
-2
0 50 100 150 200
frequency f [Hz]
250 300 350 400 noise -2
-4
0 50 100 150 200 250 300 350 400
frequency f [Hz]
2
4
x 10 differentiated and low-pass filtered ECG after 50 Hz removal -1.5
within 160 ms after P2
1.5
S2 -2 P2
1.5 1 here fulfilled
ECG amplitude [arb. units]
1 0.5 -2.5
if neither a) nor b)
diff ECG amplitude [arb. units]
0.5 0
0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8
-0.5
0 time [s]
-0.5
-1 criterion c):
-1
-1.5
160 ms no crossing of S2
-2
0 0.2 0.4 0.6 0.8 1
time [s]
1.2 1.4 1.6 1.8 2
zero crossing -2.5 160 ms within 160 ms after P3
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
(time of 2nd crossing
time [s]
Determine first zero-crossing after P1 with S1)
PATTERN: time domain
MATLAB implementation: P-wave detection
PATTERN: time domain function [ppos,rpos]=searchp(ecg,fs,trev,tw, factor1)
Example 3: P-wave detection %ecg: input ecg
%fs: sampling frequency
%trev: time backwards from QRS which defines end of the search window
Problem: Frequency components of QRS and P-wave overlap (if the threshold %tw: duration of search window
is lowered to detect the P-wave, also the QRS complex is detected) %factor1:
Realization of a wave
e. g. cross correlation same as in
with position marker assigned
threshold detection
by the user (e. g. maximum)
ppos(1)
requires zero mean excessive computation
and lowpass time in case of large
noise reduction data records
function pp=pospl(x,plan,fs)
%x: input sequence
%plan: template
%fs: sampling frequency
%pp: location indices of the waves similar to the template
Template correlation (here with the R-wave-template)
x=x-mean(x); %Elimination of DC components
end
PATTERN: time domain PATTERN: time domain
Differences in the location by threshold
and by template correlation, refinement of the location
Illustration: improved P-wave location in ECG
Assignment of the position
Threshold detection by wave characteristics
(e. g. maximum)
t alignment
en by threshold
m
fi ne template and maximum
re
sample wave
Position determinantion
x QRS r Detection p Correction pc with a global template alignment
detection of P wave of P wave template by template
(threshold) (template)
searchp.m cdet.m Detection (correction)
sample wave
by template
MATLAB-Example
PATTERN: time domain
Application 1: time series of the P-R-interval Application 2: Synchronized averaging
P-R interval If we can assume that a biosignal contains repetitive patterns
122
which stem from the same generating process (mostly assumed as
120
a random process), The SNR can be improved by averaging of
subsequent patterns. Example: ECG, evoked responses
118
example: average P-wave
(ms) 116
for template generation
114
112
110
108
0 20 40 60 80 100 120 140 160 180 200
beat number
mean P-wave
Classical averaging requires the following conditions to be met: This means that the signal S(f) is filtered with a filter function
•accurate detection of a fiducial point (alignment)
•stationarity of the signal and of the noise
•no correlation between signal and noise
{ } ∞
H (f ) = E e 2πjfθ m = ∫ p(θ )e 2πjfθ dθ
−∞
p(θ) is the pdf of θ and consequently H(f) is the FT of p(θ), a function
Inaccuracies in the alignment (‚trigger jitter‘) cause additional and which is known as the ‚characteristic function‘ in random theory. For
usually unwanted low-pass filtering of the signal. Assume M signals a normal distribution of the jitter with mean 0 and STD σθ H(f) is:
xm, m = 1... M to be averaged whereby each realization xm is derived
H (f ) = e −2(πfθσ θ )
2
from a prototype signal s by delaying it by a random number θm.
1 M 1 M
x [k ] = ∑
M m =1
x m [k ] = ∑ s[k + θ m ]
M m =1 The 3 dB cutoff frequency is fc =
0.1325
σθ
Fourier transform of a single realization yields a spectrum
If the distribution is uniform between 0 and c we obtain
2πjfθ m
X m (f ) = S (f )e 0.45 0.13
fc = =
The average spectrum has the expectation: c σθ
{ } { }
E X (f ) = E S (f )e 2πjfθ m = S (f )E e 2πjfθ m { } The cutoff frequency does not depend much on the type of distribution,
the only important parameter is the STD of the jitter.
For a comparison of some alignment methods see: Jané, R. et al. (1991). Alignment
methods for averaging of highresolution cardiac signals: a comparative study of
performance. IEEE Trans Biomed Eng 38: 571-579.
Additionally a group delay can be calculated as the derivative of the A third estimator for the misalignment can be built with multichannel
phase with respect to the frequency. This method, however, is very AR-methods as estimators for the cross spectra. This method will
sensitive to noise, especially in those parts of the spectrum, where not be treated in this lecture.
the noise predominates over the signal. In order to reduce the
uncertainty of this estimator a weighted averaged delay can be
calulated:
Performance of correlation (Rxy), cross spectral estimator (CCG)
and AR method for the P-wave alignment in ECG signals Application 3: Detection of abnormal beats in ECG
This algorithm is a special case of template correlation. Here instead
Correlation versus of the correlation function the correlation coefficient ρ is applied as a
cross spectrum: no measure of similarity. [SOURCE: SCHREIER 1998]
pronounced difference. step 1: QRS-detection
The jitter increases
considerably above a step 2: chose one beat which is considered as normal and create a
certain noise level. template Ŝ 0 Sˆ [n] = 0 x [n] set iteration counter i = 1
0 i
noise [mVeff]
step 3: calculate the ρ between the template and the next xi of the series
of beats
AR-method: The jitter is
step 4: if ρ >= ρtresh then accept xi as normal beat and update the template
higher than that of Rxy and i −1
The noise reduction approaches only the 1/N rule if the noise is
stationary. In practical cases (e. g. ECG) this condition is not
necessarily met. The reasons can be physiological (respiration,
movements, electrode artifacts). Because of this the improvement in Pi Pf Qi Sf Ti Tf
SNR by averaging can be much worse than 1/N. A very prominent start of
method for considering non-stationarities is weighted averaging, the puls wave
weights depending inversely on the variance of the noise in the
respective signal segment:
e. g.: ECG:
1 M M
x [k ] = ∑ w m x m [k ] ,
M m =1
∑w
m =1
m =1 wave
isoelectric segment
1 1
with wm =
σ m2 M
1 start end t
∑σ
i =1
2
We need algorithms for the classification which samples form part of the isoelectric
i
segment and which ones belong to the wave. The start or end of the wave would
segments with higher error variance contribute less to the final result
then be the separation point for samples which enter into the classification and which
one not.Common problems: noise, interferences, baseline drifts
(2.1) Detection by thresholding the derivative
Principle: An isoelectric segment has (theoretically) a derivative zero (at least close to
threshold in the derivative zero). In contrast the wave contributes with a significant derivative, except around its
extrema
5
0
intersection of straight lines
-5 original signal
-10
Detection of require the
start and end triangulation previous detection -15
0 50 100 150 200 250 300
of the wave
0.4
0
derivative
-0.2
-0.4
time frequency analysis
-0.6
0 50 100 150 200 250 300
-5
reduction of noise by threshold or must include that the wave must be
-10
and interference template part of the wave monotonic for
-15 (lowpass) which lies between correct function
0 50 100 150 200 250 300
start end maximum and the lower the threshold
0.4 0.34 isoelectric segment the farther away
is the separation point
derivative
0.2 0.34/5=0.07
from the wave’s maximum
0
5
[m,n]=max(signal)
m =1219
0
n =265
» pin=inic(signal,n,100,1000,1,5)
pin =181 -5
» pfi=final(signal,530,length(signal)-531,1000,-1,5)
pfi =645 -10
50 100 150 200 250
wave duration: 645-181= 464 ms
0 100 200 300 400 500 600 700 800 900
reference point for calculating the end of the wave Result depends on the locatopn of the tangent
MATLAB implementation, find start of wave PATTERN: time domain
PATTERN: time domain
function pin=inicr(x,pos,l,fs,fac,pen,miso)
%x: input signal
%pma: positions of the maxima
%l: window length in ms
%fs: sampling frequency
Proceeding: Starting from the maximum slope of the wave a point of the %pen: 1 if wave is positive, -1 else
wave is selectet at which the slope is a certain fraction of the maximum %fac: threshold factor
slope. Then the tangent in this point is calculated. On the other hand %pin: starting point positions of the waves
another straight line is adjusted to the isoelectric segment from several l=l*fs/1000; %ms samples
for i=1:length(pos) % from first to last detected wave
recurrecnes (regression line with minimum quadratic error criterion). Then xm=x(pos(i)-l:pos(i)); %signal window
the intersection of both lines is carried out. xmd=pen*diff(xm); %calculate derivative
[m,n]=max(xmd); %maximum of the derivative
xmd=xmd(1:n); %second window
prerequisites:
k=find(xmd<m/fac); %find threshold of derivative
•Same preprocessing as for threshold detection of waves k=k(length(k));
•the respective wave segment must be monotone r1=xmd(k)*pen*((1:length(xm))-k)+xm(k); %tangent on the wave
xiso=xm(1:miso); %window for the isoelectric segment
problem: the position of the intersection point depends on the slope xiso=xiso(:)';
p=polyfit((1:miso),xiso,1); %estimate regression line
flatter waves yield higher uncertainty r2=polyval(p,(1:length(xm))); %estimate regression line
k=find(r2<r1); %find intersection
k=k(1);
pin(i)=pos(i)-l+k-1; %calculate position
end
0 maximum area
-2
A2
-4 A1 max !
-6
area for different locations
-8
0 50 100 150 200 250 300
A1 < A2
MATLAB implementation, find start of wave PATTERN: time domain PATTERN: time domain
Result triangulation
function [pfin,are]=fintr(x,pos,l,fs,pen)
%x: input signal
%pos: positions of the maxima
%l: window length between maximum and isoelectric segment in ms
%fs: sampling frequency
%pen: 1 if wave is positive, -1 else
%fac: threshold factor
%pfin: end position of wave
%are: triangulation area
HR
N 2 80
∑ Di
RMSSD = i =1 60
N „Tachogram“
0 3
„Task Force of the European Society of Cardiology and the North American time [min]
Society of Pacing and Electrophysiology“, Circulation 93, pp: 1043-1065,
1996
(b) scaterogram: Abscissa of the point is the length of the HRV ANA
previous NN interval. Ordinate of the point it the length of the (2) Spectral Domain Methods
PSD [n.u.]
HR 160
80
140
LF HF
120
100
60
80
60
„Tachogram“ 40
20
0
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45
0 3
time [min] frequency [Hz]
HRV ANA
4 spectral zones are distinguished: HRV ANA
• ULF, ultra low frequencies, <0,003 Hz
Indices derived from short-term recordings
• VLF, very low frequencies, 0,003 - 0,04 Hz
• LF, low frequencies, 0,04 - 0,15 Hz
(5 min)
• HF, high frequencies, 0,15 - 0,4 Hz
• Total Power [ms2] - Variance of all NN intervals
typical HRV-spectrum for short-term analysis
• VLF, [ms2] - power in the very low frequency range
• LF, [ms2] - power in the low frequency range
VLF
• LFnorm, n.u. - LF power in normalized units:
LF • LF/(Total Power - VLF)*100
• HF, [ms2] - power in the high frequency range
• HFnorm, n.u. - HF power in normalized units:
• HF/(Total Power - VLF)*100
HF
• LF/HF - ratio LF /HF
HRV ANA
HRV ANA Physiological interpretation of the different spectral
components
Indices derived from long-term recordings (24 h) ULF-band: origin is unknown, however the prognosis of a
sudden death according to its power is the most accurate.
• Total Power [ms2] - Variance of all NN intervals VLF-band: still a matter of investigation. Most probable corre-
• ULF, [ms2] - power in the ultra low frequency range lates: thermoregulation, renin-angiotensin system activation,
• VLF, [ms2] - power in the very low frequency range changes in physical activity.
• LF, [ms2] - power in the low frequency range
LF-band: to some extent generated by baroreceptor
• LFnorm, n.u. - LF power in normalized units:
modulations of sympathetic and vagus nervous tone. According
• LF/(Total Power - VLF)*100 to other references it is mostly dependent on the sympathetic
• HF, [ms2] - power in the high frequency range activation.
Frequency [Hz]
LF/HF - typical:
Mathematic modeling is a special tool that gives the possibility
Rest ≥1
to evaluate those properties of regulatory systems and
Orthostasis ÷ 20
processes that can't be obtained by direct measurements. LF-power
Sensitivity and specificity of the effective systems to humoral LF/HF =
HF-power Sleeping <1
sympathetic and parasympathetic influences can be obtained
with the help of these methods.
Index of „sympatho-vagal“ balance
1.5
0.5
HR, resampled
0
4456 4458 4460 4462 4464 4466 4468 4470 4472 4474
(4) Deconvolution with local window spectrum HRV ANA
HR [1/s]
T=2/fr
1/I1 1/I2 1/I3 1/I4
t
original HR-spectrum warped HR-spectrum
window spectrum W
fr/2 f
1/W restauration of original
spectrum by multiplication
with 1/W