You are on page 1of 21

Example: Automatic detection of pathological ECG-pattern:

depressed ST-segment: e. g. subendocardial ischemia


PATTERN: time domain 1250

1200
(feature extraction)
ECG Analysis 1150

1100 QRSD

1050

1000
STD
950

Pattern recognition basics I: 900

850
TA

0 50 100 150 200 250 300 350

time domain methods TD

pattern recognition

classification

normal beat infarction


normal template

PATTERN: time domain PATTERN: time domain


Pattern recognition: (1) Determination of the occurrence and position of a wave
Detection of characteristic points in time series
QRS detection
x xp pos
Preprocessing decision rule
detection of the start of P,Q,T

Generation of time filtering threshold


detection of the end of P,S,T
series of the intervals
between derivation
detection of max. pressure (systoly) characteristic points template correlation
detection of
characteristic non-linear function
points Detection of triangulation
detection of the pulse wave
characteristic
correlation
patterns
detection of the start of a pulse wave extrapolation
etc... time frequency transforms

detection of the start of a sound curve fitting


other transforms

detection of the start of inspiration ...


PATTERN: time domain
PATTERN: time domain (1.1) Detection by threshold
Detection of characteristic waves
Aim: detect the position of a wave which occurs repetitively in a biomedical signal. Decision rule: The wave is considered as detected if it
exceeds a certain threshold.
Preprocessing condition: all other waves, which are of no interest
must remain below the threshold

Determination of the position: The position must be assigned to a


characteristic point (fiducial point) among those which exceed the
threshold (maximum of the wave, maximum of an interpolation of
the wave, midpoint between the two threshold crossings, etc...)

possible fiducial points

PATTERN: time domain


PATTERN: time domain Example 1: Detection of the pulse wave

Step 1: Detrending, baseline removal


Thresholding methods usually require preprocessing:
raw data
Elimination of baseline-offset
slow,
elevated amplitude
lowpass filtering

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))

k=find(signal>threshold) %According MATLAB command

We need two series: The one with upstroke threshold crossings


and the one with downstroke threshold crossings. In this way we
can determine the wave location from those two characteristic
points.

PATTERN: time domain


PATTERN: time domain
Step 4: Assignment of the fiducial point
MATLAB implementation for the detection of a pulse wave
for i=1:length(kpp)
[m,n(i)]=max(wave(kpp(i):kpn(i)));
pos1(i)=kpp(i)+n(i)-1;
function [kpp,kpn]=prok(k,sep) end
%k: indices of the signal values above the threshold wave(kpp(i):kpn(i))
%sep: separation condition between waves

kpp(1)=k(1); %the first entry of k is the first point


kpn=[]; Possibility 1: maximum of the wave
for i=1:length(k)-1
if k(i+1)-k(i)>sep %two waves must be separated at least by sep
kpp=[kpp,k(i+1)]; %The point before sep is the last one of the pos2=(kpp+kpn)/2;
kpn=[kpn,k(i)]; %wave, the next one is the starting point of the next kpp(i) kpn(i)
wave
pos(i)?
end Possibility 2 is only valid
end for symmetric waves
kpn=[kpn,k(length(k))]; %The last point of k is the last one of the last wave (not true in the shown case)

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

Tiempo entre puls os (s )


1.05

1 pos=kpp+n-1; %Calculate position


0.95
if pos(length(pos))+madel>length(wave)
wave=wave(:); %Convert wave to column vector 0.9
pos=pos(1:length(pos)-1); %avoid errors
for i=1:length(pos1)-1 0.85

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

PATTERN: time domain


Example 2: QRS - detection PATTERN: time domain
Illustration of the QRS-detection original
function r=detqrs(y,fs,fac)
% detection of qrs
% r= position of R (samples)
% y: ECG
% fs: sampling frequency (Hz)
% fac: empirical factor (between 0,7 y 1,5)
%Use 0,7 if obtained RR has many false positives
[b,a]=butter(2, [10*2 30*2]/fs); %Bandpass filtering between 10 and 30 Hz
yf=(filtfilt(b,a,y)); %zero phase filtering
yfd=(diff(yf)); %Differentiation
[b,a]=butter(2,30/fs); %lowpass filtering at 15 Hz
yfd=filtfilt(b,a,yfd); %zero phase filtering bandpass filtered (yf)
yfds=(round(yfd/max(yfd)*fac)); %normalizing and thresholding signal
yfdds=diff(yfds); %nonzero if thresh. signal changes
k=find(yfdds); %find changes in the tresh signal
sep_time=0.6; %min. expect. interval [s]
sep=sep_time*fs; %convert to samples

[kpp,kpn]=prok(k,sep); %reference points for wavelets

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

PATTERN: time domain Heartrate:


sampling intervals are not equidistant
Possible application: analysis of the time series of RR-intervals
1.2

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

T-wave (comp. large) z. B. fS = 800 Hz T-wave (comp. large) z. B. cutoff ~ 100 Hz


R-peak R-peak
raw ECG with heavy 50 Hz interference
H(z) = 1 + z-8 1000
ECG after 50 Hz removal H(z) = 1 + 4z-1 + 6z-2 + 4z-3 + 1z-4
300
2

gain of lowpass filter


200
ECG amplitude [arb. units]

1.5 20

ECG amplitude [arb. units]


500

gain of lowpass filter


100 1 15

0.5 10
0
0 5
0 50 100 150 200 250 300 350 400 0
-100
0

phase of lowpass filter [rad]


2 0 50 100 150 200 250 300 350 400
-200
1

phase of lowpass filter [rad]


4
-500
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 2
time [s]
time [s]
-1
50 Hz interference 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]

This filter eliminates all harmonics of 50 Hz

PATTERN: time domain


PATTERN: time domain recognition of a valid QRS-complex
4
differentiated and low-pass filtered ECG after 50 Hz removal criterion a):
Differentiation for determination 1.5
x 10

filtered ECG signal no crossing of S2


of the maxima: search for zero-crossings S1 1 P3
within 160 ms after P1
0.5 P1
here violated

diff ECG amplitude [arb. units]


discrete differentiator 0
R-peak T-wave (comp. large)
y[n]= x[n] - x[n-1] -0.5
criterion b):
x 10
5
low-pass filtered ECG after 50 Hz removal
H(z) = 1 - z-1 -1
no crossing of S1
2.5

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:

rpos=detqrs(ecg_act,fs,factor1); %Detection of R-peak


Solution: Detection of the QRS and then search backwards for finding the P-
wave if rpos(1)-tw-trev<1
rpos=rpos(2:length(rpos)); %Exclusion of first QRS if period
QRS end;

%------------filtering and baseline elimination--------------


[b,a]=butter(12,30/fs); %15Hz lowpass filter
ecg_act2=filtfilt(b,a,ecg_act);

%ecg_act3=ecg_act2-medfilt1(ecg_act2,80); %baseline elimination with median


P filter
[b,a]=butter(2,6/fs,'high'); %baseline elimination with 3Hz
highpass filter
ecg_act3=filtfilt(b,a,ecg_act2);
search %----------------------------------------------
pos
window
for i=1:length(rpos) %set window and find maximum
x=ecg_act3(rpos(i)-tw-trev:rpos(i)-trev);
[m,n]=max(x);
ppos(i)=n+rpos(i)-tw-trev-1;
end

PATTERN: time domain


PATTERN: time domain
Illustration of the result: detected P-wave peaks
(1.2) Detection by template correlation

Selection of Search for the maximum


similarity function
a template of the similarity

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

The waves are aligned in such a


way that the similarity function
reaches a maximum
PATTERN: time domain
PATTERN: time domain
MATLAB implementation
Original wave

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

xc=xcorr(plan,x); %Cross correlation


Cross correlation function
xc=xc(1:length(xc)/2); %Elimination of the second half (zeroes)

k=find(xc>0.7*max(xc)); %Detect approximate locations of high similarity

Thresholding [kpp,kpn]=prok(k,300*fs/1000); %determine upstroke and downastroke crossings


for i=1:length(kpp)
[m,n(i)]=max(xc(kpp(i):kpn(i))); %Detect indices for maximum similarity
end
pp=kpp+n-1+fix(length(plan)/2); %refer detected positions to positions
in original signal

Maxima of Xcorr represent exact locations of R-waves

MATLAB-example: correlation with template from the signal itself


PATTERN: time domain
function rcor=cdet(r,c1,pref,lba,lfor)
%r: approximate wave location, c1: signal
%pref: index of the wave which should be taken as template,
%lba: samples backwards (window), lfor: samples forwards
The template method is more robust versus noise than a threshold method %rcor: corrected wave position index
but needs much more operations (computation time) ini=1;
while r(ini)-lba<1
rcor(ini)=r(ini);
ini=ini+1;
Previous detection select window which correct the position end
by threshold includes the wave by template fin=length(r);
while r(fin)+lfor>length(c1)
rcor(fin)=r(fin);
fin=fin-1;
Select template end
qref=c1(r(pref+ini)-lba:r(pref+ini)+lfor); %select template
for i=ini:fin
qi=c1(r(i)-lba:r(i)+lfor); %select window
The shorter the window the lower the computational cost but, on the other hand x=xcorr((detrend((qi))),detrend((qref)),'coeff'); %correlation
the worse the possible correction of the wave’s position [m,n]=max(x); %maximum similarity
rcor(i)=r(i)+length(qi)-n; %update position

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.

In practice the sampling interval itself introduces a minimum trigger


jitter which is uniformly distributed between 0 and 1/fs. Hence we Example: alignment of EPs with a certain scatter in the latency
obtain a ‚natural‘ cutoff frequency of times
fc = 0.45fs
0x
The latency time can vary between different
Example: Assume a sampling frequency of 1000 Hz we obtain a 1 recurrences (τ01, τ02, τ03).
τ01 In contrast to ECG (natural trigger, forms part of
cutoff frequency of 450 Hz which lies below the Nyquist frequency
of 500 Hz ! the signal, high signal energy of the QRS-
complex) a good template is not available
τ02
0x
2
Implications: If for the alignment of a wave (e. g. the P-wave) the because the individual realizations are too noisy
fiducial point of another, time-locked wave is used, the variability  iterative algorithm
of the delay between both waves enters into the trigger jitter.
Example: alignment of P-waves with the R-peak as fiducial point τ03 0x
3
 variability of the P_R interval affects P-wave averaging. Step 1: calculate a zeroth approximation of
the template 1 N 0
Hence the algorithm for the determinantion of the fiducial point must ∑ xi [n]
Sˆ 0 [n] =
...
N i =1
be chosen such as to minimize the trigger jitter. The best step 2: cross correlate each 0xi with Ŝ 0 and estimate the 0τ0i
performance is obtained with template correlation methods (matched iterate
step 3: shift each 0xi[n]  1xi[n]= 0xi[n-0τ0i/ts ]
filter) but this holds strictly only for Gaussian white noise. N
ˆ [ n] = 1
step 4: calculate new estimate Ŝ1 from the 1xi[n] S 1 ∑
N i =1
1
xi [n]
result after 800 iterations

single realization of an EP-recording

Increase of the SNR with the


number of iterations

result after 200 iterations

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.

Alternatively the alignment can also be achieved from the analysis


of the cross spectrum between template and signal. If the template
y and the signal x deviate only by an attenuation factor α then we

obtain:
∫ 2πf Gxy (f ) ϕ xy (f )df
2πjfτ 0 τˆ0 = o
Gxy (f ) = αGxx e ∞
∫ (2πf )
2
Gxy (f ) df
o
Hence the delay time τ0 (misalignment) of the signal with respect to
the template is visible as a phase shift and can be evaluated at The phase readings are weighted with the modulus of the cross
every frequency spectrum in order to minimize the effect of contributions from those
ϕ (f ) parts of the spectrum which contain low signal energy (and hence
τ 0 (f ) = essentially noise !)
2πf

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

CCG at low noise levels, but


(weighted averaging): Sˆ i-1 ∑ ρ k + x i ρ i
minor at high noise levels. each beat is weighted Sˆ i = k =0
i
Results are shown for 3 according to its correlation
with the template

k =0
ρk
different signal bandwidths
(25, 50 100 Hz). iterate for i = 1 to N, N number of beats
noise [mVeff] MATLAB-Example

Alignment in case of nonstationary noise


(2) Determination of the starting and end points of waves

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

wavelet analysis 0.2

0
derivative
-0.2

-0.4
time frequency analysis
-0.6
0 50 100 150 200 250 300

schematic of the processing flow


Procedure: start at the maximum of the wave and search for the maximum
derivative (in modulus) towards the start (end) of the wave. Then follow this direction
until the absolute derivative falls below a certain fraction of the maximum.
5 filtering of signal detection of maxima detection of start
windowing
in the wave and end
0
wave

-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

-0.2 -0.09 baseline drift


-0.4
elimination
-0.46 (highpass)
-0.6
0 50 100 150 200 250 300
MATLAB implementation, find start of wave PATTERN: time domain
MATLAB implementation, find end of wave
function pin=inic(x,pma,l,fs,pen,fac);
%x: input signal function pfi=final(x,pma,l,fs,pen,fac);
%pma: positions of the maxima %x: input signal
%l: window length in ms %pma: positions of the maxima
%fs: sampling frequency %l: window length in ms
%pen: 1 if wave is positive, -1 else %fs: sampling frequency
%fac: threshold factor %pen: 1 if wave is positive, -1 else
%pin: starting point positions of the waves %fac: threshold factor
%pfi: end point positions of the waves
l=l*fs/1000; %conversion ms  samples
for i=1:length(pma) %from first to last detected wave l=l*fs/1000; %conversion ms  samples
xmu=x(pma(i)-l:pma(i)); %select a window of the wave for i=1:length(pma) %from first to last detected wave
xmud=diff(xmu); %differentiate xmu=x(pma(i):pma(i)+l); %select a window of the wave
[m,n]=max(xmud*pen); %find maximum of derivative xmud=diff(xmu); %differentiate
xmud=xmud(1:n); %cut the window [m,n]=max(xmud*pen); %find maximum of derivative
k=find(pen*xmud<m/fac); %find points below threshold xmud=xmud(n:length(xmud)); %cut the window
k=k(length(k)); %the separation point lies at the crossing k=find(pen*xmud<m/fac); %find points below threshold
pin(i)=pma(i)-l+k-1; %calculate position k=k(1); %the separation point lies at the crossing
end pfi(i)=pma(i)+n+k-1; %calculate position
end

PATTERN: time domain PATTERN: time domain


Result thresholding (2.2) Detection by the intersection of tangents
Principle: the starting and end point is determined by the intersection of 2
pin=inic(signal,202,100,1000,1,5) straight lines. One of them is a tangent of the wave, the other one is a linear
» pin =143 approximation of the isoelectric segment.
pfi=final(signal,202,length(signal)-203,1000,-1,5)
20
» pfi =249
wave duration: 249-143=106 ms 15

0 50 100 150 200 250 300


10

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

MATLAB implementation, find end of wave PATTERN: time domain


PATTERN: time domain
function pfin=finalr(x,pos,l,fs,fac,pen,miso) Result intersection
%x: input signal
%pma: positions of the maxima
%l: window length in ms
%fs: sampling frequency
%pen: 1 if wave is positive, -1 else
%fac: threshold factor
%pfin: end point positions of the waves
l=l*fs/1000; %ms  samples
for i=1:length(pos) % from first to last detected wave
xm=x(pos(i):pos(i)+l); %signal window
xmd=pen*diff(xm); %calculate derivative
[m,n]=max(xmd); % maximum of the derivative
xmd=xmd(n:length(xmd)); %second window
k=find(xmd<m/fac); %locate threshold
k=k(1); %find tangent point
r1=xmd(k)*pen*((1:length(xm))-(k+n-1))+xm(k+n-1); %tangent
xiso=xm(length(xm)-miso:length(xm)); %isoelectric segment 0 50 100 150 200 250 300
xiso=xiso(:)';
p=polyfit(length(xm)-miso:length(xm),xiso,1); %estimate regression line pin=inicr(mu,187,186,1000,2,1,20)
r2=polyval(p,(1:length(xm))); %estimate regression line » pin =132
k=find(r2>r1); %Intersect pfin=finalr(mu,187,length(mu)-188,1000,2,-1,20)
k=k(1); %intersection point » pfin =240
pfin(i)=k+pos(i); %Calculate position wave duration: 108 ms
end
PATTERN: time domain PATTERN: time domain
(2.3) Detection by triangulation
Proceeding: Select an analysis window (which most probably contains the
Principle: The area which is determined by 3 points (one on the wave, third point) the ends of which are formed by one point of the isoelectric
the second in the isoelectric segment and the third in between) is segment (with constant distance to the maximum of the wave) and the
maximum if the third point is located at the beginning of the wave maximum of the slope of the wave.
10

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

l=l*fs/1000; %ms  samples


for i=1:length(pos) %from first to last
xm=x(pos(i):pos(i)+l); %windowing
xd=diff(xm)*pen; %differentiate
[m,n]=max(xd); %maximum slope
1340 1360 1380 1400 1420 1440 1460 1480 1500 1520 1540
xm=xm(n:length(xm)); %new window (from isoelectric point to max. slope)
for j=1:length(xm) pini=initr(onda,1450,150,1000,1)
are(j)=abs(0.5*(j*(-xm(length(xm))+xm(j))-(-j+length(xm))*(xm(1)-xm(j)))); >>pini =1403
end %calculate area pfin=fintr(ecgf,1450,90,1000,-1)
[m,nn]=max(are); %maximum area >>pfin = 1516
pfin(i)=nn+n-1+pos(i); %wave position
end wave duration: 113 ms
The triangulation algorithm is very robust
PATTERN: time domain
HRV ANA
Conclusions
Methodology of HRV-analysis
localization of the wave
(source: www.hrvcongress.org/courses)
knowledge of an appropriate analysis window
algorithms for the
detection of start
and end knowledge about the wave shape

previous lowpass filtering required


• Analysis in the time domain (Time domain methods)
• Analysis in the frequency domain (Spectral domain methods)
detection by threshold
the result depends on an
or
empirically chosen parameter
• non-linear methods
intersection
• mathematical modelling
the result depends only on the
Deteccion by
two (mostly uncritical) end
triangulation
points of the analysis window

(1) Analysis in the time domain HRV ANA


HRV ANA
(Time domain methods)
The following indices have been defined so far:
Basis of the analysis is either the HR in any time instant
(‚instantaneous HR‘) or the interval between two subsequent QRS • Mean heart rate (HR, int/min)
• Mean NN interval (mNN or mRR, ms)
complexes of normal heart actions (‚Normal-normal‘, abbrev. NN). • Standard deviation of the NN interval (sdNN or sdRR, ms) - the square root of
For this purpose a detection of the R-peaks must be carried out variance between the NN intervals. Since variance is mathematically equal to total power of
first. Then a series of inter-beat intervals is generated. spectral analysis, sdNN reflects all the cyclic components responsible for variability in the
period of recording.
• Standard deviation of the average NN interval calculated over 5-min periods within
the 24 - hours recording (SDANN, ms). This parameter is an estimate of the changes in
(1.1) Statistical methods heart rate due to cycles longer than 5 minutes
• Mean of the standard deviations of all NN intervals for all 5 min segments of entire
The measures obtained after analyses of a series of instantaneous recording (SDNN index, ms). This index reflects the variability due to cycles shorter than 5
heart rates or NN intervals can be divided into 2 classes: minutes
• The square root of the mean squared differences of successive NN intervals
(RMSSD, ms).
1. those derived from direct measurements of the instantaneous • The number of pairs of adjacent NN intervals differing by more than 50 ms in the
heart rate or NN intervals entire recording (NN50). NN50 count divided by the total number of all NN intervals
(pNN50, %)
2. those derived from the differences between NN intervals
The last three measurements reflect high frequency variations in the HRV and
thus are highly correlated.
Frequently applied index: RMSSD
HRV ANA
HRV ANA
(1.2) Geometrical Methods
RMSSD: Root Mean Square of Successive RR-
Conversion of the series of NN intervals into geometric patterns:
Differences
RR1 RR2 RR3 RR4 RR5 .......
(a) interval tachogram is a graph of the NN intervals complexes
D1 D2 D3 D4 D5 .......

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

subsequent NN interval. The decreased HRV is reflected in a


greater density and smaller size of the cloud. The type of the The important characteristics of the spectrum are the power
point distribution is determined by origin of QRS complexes. density of the spectrum (power spectral density, PSD) and
the powers of its separate zones.

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.

HF-band: respiratory modulation of the vagus nerve activity.


HRV ANA HRV ANA
PSD [n.u.]
(3) Non - Linear Methods 120
LF-band (0.04÷0.15 Hz):
100 power is influenced by the
The stochastic indexes of the regulatory systems functioning sympathetic efferent activity
may be obtained by chaos analyses of the heart rate 80
LF/HF = 2,53
variability. Such indexes are thought to reflect the stress 60
HF-band (0.15÷0.4 Hz):
resistance of regulatory systems. 40
power mainly determined by
20
the vagal efferent activity
(4) Mathematic Modeling Methods LF HF
0
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4

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

Solution: Interpolation and resampling of the heart rate at a


Beispiel: Herzrate frequency sufficiently higher than half of the maximum
frequency of interest.
Abtastung nicht äquidistant
(1) definition of a resampling frequency fr (recommended 4 Hz)
(2) Define a local window at each sampling time tk between
3 tk-1 and tk+1
2.5
(3) calculate a fractional R rk = fr nk/2 (see figure), e. g.
(b/I3+c/I4)/(fr/2) average beats per windowlength
2

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

You might also like