Example: Automatic detection of pathological ECG-pattern...
Transcript of Example: Automatic detection of pathological ECG-pattern...
ECG Analysis
Pattern recognition basics I: time domain methods
PATTERN: time domain
Example: Automatic detection of pathological ECG-pattern: depressed ST-segment: e. g. subendocardial ischemia
classification
normal beat infarction
pattern recognition
normal template
(feature extraction)
STD
QRSD
TD
TA
0 50 100 150 200 250 300 350850
900
950
1000
1050
1100
1150
1200
1250
Pattern recognition: Detection of characteristic points in time series
detection of characteristic points
QRS detection
detection of the start of P,Q,T
detection of the end of P,S,T
detection of max. pressure (systoly)
detection of the pulse wave
detection of the start of a pulse wave
detection of the start of a sound
detection of the start of inspiration
Generation of timeseries of the intervals
betweencharacteristic points
Detection of characteristic
patterns
etc...
PATTERN: time domain
Preprocessingx
decision rulexp pos
filtering
derivation
non-linear function
correlation
time frequency transforms
other transforms
...
threshold
template correlation
triangulation
extrapolation
curve fitting
(1) Determination of the occurrence and position of a wave
PATTERN: time domain
Detection of characteristic waves
Aim: detect the position of a wave which occurs repetitively in a biomedical signal.
PATTERN: time domain (1.1) Detection by threshold
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
wave
slow, elevated amplitude
fast, elevated amplitude
low amplitude
Elimination of baseline-offset
lowpass filtering
bandpass filtering
Detection of event-correlated other characteristic waves,elimination of this ‘trigger wave’
Thresholding methods usually require preprocessing:
PATTERN: time domain Example 1: Detection of the pulse wave
The elimination of the baseline-offset (maybe also detrending)allows the utilization of a constant threshold
raw data
Step 1: Detrending, baseline removal
PATTERN: time domain
Reduction
ofnoiselow
pasfiltering
10 Hz
Step2: Noise elimination by lowpass filtering
PATTERN: time domain
Be k={k(1)....k(M)} the series of positions for which holds x(k(i))>threshold (∀ i∈(1,M))
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.
k=find(signal>threshold) %According MATLAB command
Step3: Thresholding
threshold
PATTERN: time domain
function [kpp,kpn]=prok(k,sep)%k: indices of the signal values above the threshold%sep: separation condition between waves
kpp(1)=k(1); %the first entry of k is the first pointkpn=[];for i=1:length(k)-1
if k(i+1)-k(i)>sep %two waves must be separated at least by sepkpp=[kpp,k(i+1)]; %The point before sep is the last one of thekpn=[kpn,k(i)]; %wave, the next one is the starting point of the next
waveend
endkpn=[kpn,k(length(k))]; %The last point of k is the last one of the last wave
Now we have to assign a position to the wave. The alignment point for wave i lies between kpp(i) and kpn(i)
MATLAB implementation for the detection of a pulse wave
PATTERN: time domain
kpn(i)
wave(kpp(i):kpn(i))
kpp(i)pos(i)?
for i=1:length(kpp)[m,n(i)]=max(wave(kpp(i):kpn(i)));pos1(i)=kpp(i)+n(i)-1;
end
Possibility 1: maximum of the wave
Possibility 2: midpoint in between kpp(i) and kpn(i)
pos2=(kpp+kpn)/2;
Possibility 2 is only valid for symmetric waves (not true in the shown case)
Step 4: Assignment of the fiducial point PATTERN: time domain
wave=wave(:); %Convert wave to column vectorfor i=1:length(pos1)-1
wavel=[wavel (wave(pos1(i)-matr:pos1(i)+matl))];end
mean(wave)
averaging of the signal
time series of intervals
0 10 20 30 40 50 60 70 80 90 1000.75
0.8
0.85
0.9
0.95
1
1.05
1.1
1.15
1.2
1.25
Nú mero de pulsoT
iem
po
en
tre
pu
lso
s (
s)
diff(pos)/fs
Step 5: Further processingExamples: averaging and shape analysis,interval analysis
intervals before and after fiducial point
PATTERN: time domainfunction [pos,sal]=prondpul(wave,facd,fs,matr,madel)%wave: input signal%facd: threshold factor(between 0 y 1)%fs: sampling frequency%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 wavessal=[];wavef=lbmed(wave,40*fs/1000,fs); %baseline offset elimination[b,c]=butter(2,20/fs); %filter coefficientswavef2=filtfilt(b,c,wavef); %bidirectional filteringk=find(wavef2>max(wavef2)*facd); %calculate positions above threshold[kpp,kpn]=prok(k,200*fs/1000); %starting and end points of wavesfor i=1:length(kpp)
[m,n(i)]=max(wavef2(kpp(i):kpn(i)));endpos=kpp+n-1; %Calculate positionif pos(length(pos))+madel>length(wave)
pos=pos(1:length(pos)-1); %avoid errors endwavef2=wavef2(:);for i=1:length(pos)
sal=[sal wavef2(pos(i)-matr:pos(i)+madel)]; %assemble wave matrixend DEMO ECG-P-extraction : synchronous averaging.m
Complete MATLAB-example for wave extraction PATTERN: time domain
Example 2: QRS - detectionfunction 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 Hzyf=(filtfilt(b,a,y)); %zero phase filteringyfd=(diff(yf)); %Differentiation[b,a]=butter(2,30/fs); %lowpass filtering at 15 Hzyfd=filtfilt(b,a,yfd); %zero phase filteringyfds=(round(yfd/max(yfd)*fac)); %normalizing and thresholding signalyfdds=diff(yfds); %nonzero if thresh. signal changesk=find(yfdds); %find changes in the tresh signalsep_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)
endr=kpp+n-1;
PATTERN: time domain
Illustration of the QRS-detection original
bandpass filtered (yf)
PATTERN: time domain
lowpass filtered (yf)
thresholding (yfds)
PATTERN: time domain
differentiation (yfdds)
detected R peaks
PATTERN: time domain
0 10 20 30 40 50 60 70 80 90 1000.75
0.8
0.85
0.9
0.95
1
1.05
1.1
1.15
1.2
number of beat
RR
(s)
Possible application: analysis of the time series of RR-intervals
PATTERN: time domain Heartrate: sampling intervals are not equidistant
4456 4458 4460 4462 4464 4466 4468 4470 4472 4474
0
0.5
1
1.5
2
2.5
3
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
-200
-100
0
100
200
300
time [s]
EC
G a
mpl
itude
[ar
b. u
nits
]
raw ECG with heavy 50 Hz interference
raw ECG signal, contaminated withnoise and interferences
classical R-peak-detector with integrated filters
R-peak
50 Hz interference
T-wave (comp. large)
50-Hz-filter
z. B. fS = 800 HzH(z) = 1 + z-8
0 50 100 150 200 250 300 350 4000
0.5
1
1.5
2
gain
of
low
pass
filt
er
0 50 100 150 200 250 300 350 400-2
-1
0
1
2
frequency f [Hz]
phas
e of
low
pass
filt
er [
rad]
This filter eliminates all harmonics of 50 Hz
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
-500
0
500
1000
time [s]
EC
G a
mpl
itude
[ar
b. u
nits
]
ECG after 50 Hz removal
filtered ECG signal, contaminated withnoise
R-peak
noise
T-wave (comp. large)
FIR-lowpass,linear phase
z. B. cutoff ~ 100 HzH(z) = 1 + 4z-1 + 6z-2 + 4z-3 + 1z-4
0 50 100 150 200 250 300 350 4000
5
10
15
20
gain
of
low
pass
filt
er
0 50 100 150 200 250 300 350 400-4
-2
0
2
4
frequency f [Hz]
phas
e of
low
pass
filt
er [
rad]
PATTERN: time domain
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
-2.5
-2
-1.5
-1
-0.5
0
0.5
1
1.5x 10
4
time [s]
diff
EC
G a
mpl
itude
[ar
b. u
nits
]
differentiated and low-pass filtered ECG after 50 Hz removal
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
-1
-0.5
0
0.5
1
1.5
2
2.5x 10
5
time [s]
EC
G a
mpl
itude
[ar
b. u
nits
]
low-pass filtered ECG after 50 Hz removal
filtered ECG signalDifferentiation for determinationof the maxima: search for zero-crossings
discrete differentiatory[n]= x[n] - x[n-1]
H(z) = 1 - z-1
T-wave (comp. large)R-peak
zero crossing
PATTERN: time domain
0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8
-2.5
-2
-1.5
-1
-0.5
0
0.5
1
1.5x 10
4
time [s]
diff
EC
G a
mpl
itude
[ar
b. u
nits
]
differentiated and low-pass filtered ECG after 50 Hz removal
if neither a) nor b)
criterion c):no crossing of S2within 160 ms after P3(time of 2nd crossingwith S1)
criterion a):no crossing of S2within 160 ms after P1here violated
160 ms
P1
criterion b):no crossing of S1within 160 ms after P2here fulfilled
P2
160 ms
S1
S2
recognition of a valid QRS-complex
Determine first zero-crossing after P 1
P3
PATTERN: time domain
Example 3: P-wave detection
Problem: Frequency components of QRS and P-wave overlap (if the threshold is lowered to detect the P-wave, also the QRS complex is detected)
Solution: Detection of the QRS and then search backwards for finding the P-wave
possearchwindow
QRS
P
PATTERN: time domain function [ppos,rpos]=searchp(ecg,fs,trev,tw, factor1)%ecg: input ecg%fs: sampling frequency%trev: time backwards from QRS which defines end of the search window%tw: duration of search window%factor1:
rpos=detqrs(ecg_act,fs,factor1); %Detection of R-peak
if rpos(1)-tw-trev<1rpos=rpos(2:length(rpos)); %Exclusion of first QRS if period
end;
%------------filtering and baseline elimination--------------[b,a]=butter(12,30/fs); %15Hz lowpass filterecg_act2=filtfilt(b,a,ecg_act);
%ecg_act3=ecg_act2-medfilt1(ecg_act2,80); %baseline elimination with median filter
[b,a]=butter(2,6/fs,'high'); %baseline elimination with 3Hz highpass filter
ecg_act3=filtfilt(b,a,ecg_act2);%----------------------------------------------
for i=1:length(rpos) %set window and find maximumx=ecg_act3(rpos(i)-tw-trev:rpos(i)-trev);[m,n]=max(x);ppos(i)=n+rpos(i)-tw-trev-1;
end
MATLAB implementation: P-wave detectionPATTERN: time domain
ppos(1)
Illustration of the result: detected P-wave peaksPATTERN: time domain
Selection of a template
similarity functionSearch for the maximumof the similarity
excessive computationtime in case of large
data records
requires zero meanand lowpass
noise reduction
The waves are aligned in such a way that the similarity function
reaches a maximum
Realization of a wave with position marker assigned by the user (e. g. maximum)
e. g. cross correlation same as in threshold detection
(1.2) Detection by template correlation
PATTERN: time domain
Original wave
Template correlation (here with the R-wave-template)
Cross correlation function
Thresholding
Maxima of Xcorr represent exact locations of R-waves
PATTERN: time domain
function pp=pospl(x,plan,fs)%x: input sequence%plan: template%fs: sampling frequency%pp: location indices of the waves similar to the template
x=x-mean(x); %Elimination of DC components
xc=xcorr(plan,x); %Cross correlation
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
[kpp,kpn]=prok(k,300*fs/1000); %determine upstroke and downastroke crossingsfor i=1:length(kpp)
[m,n(i)]=max(xc(kpp(i):kpn(i))); %Detect indices for maximum similarityendpp=kpp+n-1+fix(length(plan)/2); %refer detected positions to positions
in original signal
MATLAB implementation
PATTERN: time domain
The template method is more robust versus noise than a threshold method but needs much more operations (computation time)
Previous detection by threshold
correct the position by template
select window which includes the wave
Select template
The shorter the window the lower the computational cost but, on the other handthe worse the possible correction of the wave’s position
PATTERN: time domainMATLAB-example: correlation with template from the signal itself
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%rcor: corrected wave position indexini=1;while r(ini)-lba<1
rcor(ini)=r(ini);ini=ini+1;endfin=length(r);while r(fin)+lfor>length(c1)
rcor(fin)=r(fin);fin=fin-1;endqref=c1(r(pref+ini)-lba:r(pref+ini)+lfor); %select templatefor i=ini:fin
qi=c1(r(i)-lba:r(i)+lfor); %select windowx=xcorr((detrend((qi))),detrend((qref)),'coeff'); %correlation[m,n]=max(x); %maximum similarity
rcor(i)=r(i)+length(qi)-n; %update position
end
Illustration: improved P-wave location in ECG
QRS detection
cdet.m
x Detection of P wave(threshold)
searchp.m
r Correctionof P wave(template)
p pc
PATTERN: time domain
Differences in the location by threshold and by template correlation, refinement of the location
Assignment of the positionby wave characteristics(e. g. maximum)
refin
ement
Position determinantionwith a global template
Threshold detection
Detection (correction) by template
alignment by thresholdand maximumtemplate
sample wave
alignmentby templatetemplate
sample wave
PATTERN: time domain
0 20 40 60 80 100 120 140 160 180 200108
110
112
114
116
118
120
122
Application 1: time series of the P-R-interval
beat number
P-R interval
(ms)
PATTERN: time domainMATLAB-Example
Application 2: Synchronized averaging
If we can assume that a biosignal contains repetitive patternswhich stem from the same generating process (mostly assumed as a random process), The SNR can be improved by averaging of subsequent patterns. Example: ECG, evoked responses
example: average P-wavefor template generation
mean P-wave
Classical averaging requires the following conditions to be met:•accurate detection of a fiducial point (alignment)•stationarity of the signal and of the noise•no correlation between signal and noise
Inaccuracies in the alignment (‚trigger jitter‘) cause additional and usually unwanted low-pass filtering of the signal. Assume M signalsxm, m = 1... M to be averaged whereby each realization xm is derivedfrom a prototype signal s by delaying it by a random number θm.
∑∑==
+==M
mm
M
mm ks
Mkx
Mkx
11
][1
][1
][ θ
Fourier transform of a single realization yields a spectrum
mjfm efSfX θπ2)()( =
The average spectrum has the expectation:
{ } { } { }mm jfjf eEfSefSEfXE θπθπ 22 )()()( ==
This means that the signal S(f) is filtered with a filter function
{ } θθ θπθπ depeEfH jfjf m ∫∞
∞−== 22 )()(
p(θ) is the pdf of θ and consequently H(f) is the FT of p(θ), a functionwhich is known as the ‚characteristic function‘ in random theory. For a normal distribution of the jitter with mean 0 and STD σθ H(f) is:
2)(2)( θθσπfefH −=
The 3 dB cutoff frequency isθσ
1325.0=cf
If the distribution is uniform between 0 and c we obtain
θσ13.045.0 ==
cfc
The cutoff frequency does not depend much on the type of distribution, the only important parameter is the STD of the jitter.
Example: Assume a sampling frequency of 1000 Hz we obtain a cutoff frequency of 450 Hz which lies below the Nyquist frequencyof 500 Hz !
In practice the sampling interval itself introduces a minimum triggerjitter which is uniformly distributed between 0 and 1/fs. Hence weobtain a ‚natural‘ cutoff frequency of
sc ff 45.0=
Implications: If for the alignment of a wave (e. g. the P-wave) thefiducial point of another, time-locked wave is used, the variabilityof the delay between both waves enters into the trigger jitter. Example: alignment of P-waves with the R-peak as fiducial point � variability of the P_R interval affects P-wave averaging.
Hence the algorithm for the determinantion of the fiducial point mustbe chosen such as to minimize the trigger jitter. The best performance is obtained with template correlation methods (matchedfilter) but this holds strictly only for Gaussian white noise.
Example: alignment of EPs with a certain scatter in the latencytimes
The latency time can vary between different recurrences (τ01, τ02, τ03).In contrast to ECG (natural trigger, forms part of the signal, high signal energy of the QRS-complex) a good template is not availablebecause the individual realizations are too noisy� iterative algorithm
Step 1: calculate a zeroth approximation of the template
∑=
=N
ii nx
Nn
1
0 ][1
][ˆ0S
step 2: cross correlate each 0x i with and estimate the 0τ0i0Sstep 3: shift each 0xi[n] � 1xi[n]= 0xi[n-0τ0i/ts ]
τ01
0x1
τ020x2
...
τ030x3
step 4: calculate new estimate from the 1xi[n]1S ∑=
=N
ii nx
Nn
1
1 ][1
][ˆ1S
iterate
single realization of an EP-recording
result after 200 iterations
result after 800 iterations
Increase of the SNR with thenumber of iterations
For a comparison of some alignment methods see: Jané, R. et al. (1991). Alignmentmethods 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 analysisof the cross spectrum between template and signal. If the templatey and the signal x deviate only by an attenuation factor α then weobtain:
02)( τπα jfxxxy eGfG =
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 every frequency
ff
fπ
ϕτ2
)()(0 =
Additionally a group delay can be calculated as the derivative of thephase with respect to the frequency. This method, however, is verysensitive to noise, especially in those parts of the spectrum, wherethe noise predominates over the signal. In order to reduce theuncertainty of this estimator a weighted averaged delay can becalulated:
( )∫
∫∞
∞
=o xy
o xyxy
dffGf
dfffGf
)(2
)()(2ˆ
20
π
ϕπτ
The phase readings are weighted with the modulus of the cross spectrum in order to minimize the effect of contributions from thoseparts of the spectrum which contain low signal energy (and henceessentially noise !)
A third estimator for the misalignment can be built with multichannelAR-methods as estimators for the cross spectra. This method will not be treated in this lecture.
Performance of correlation (Rxy), cross spectral estimator (CCG) and AR method for the P-wave alignment in ECG signals
Correlation versuscross spectrum: no pronounced difference.The jitter increasesconsiderably above a certain noise level.
noise [mVeff]
noise [mVeff]
AR-method: The jitter ishigher than that of Rxy and CCG at low noise levels, butminor at high noise levels. Results are shown for 3 different signal bandwidths(25, 50 100 Hz).
Application 3: Detection of abnormal beats in ECG
This algorithm is a special case of template correlation. Here insteadof the correlation function the correlation coefficient ρ is applied as a measure of similarity. [SOURCE: SCHREIER 1998]
step 1: QRS-detection
step 3: calculate the ρ between the template and the next x i of the seriesof beats
][][ˆ 0 nxn i=0S
step 2: chose one beat which is considered as normal and create a template set iteration counter i = 10S
step 4: if ρ >= ρtresh then accept x i as normal beat and update the template(weighted averaging):
∑
∑
=
−
=
+= i
kk
ii
i
kk
0
1
0
ˆˆ
ρ
ρρ xSS
1i-
ieach beat is weightedaccording to its correlationwith the template
iterate for i = 1 to N, N number of beatsMATLAB-Example
Alignment in case of nonstationary noise
The noise reduction approaches only the 1/N rule if the noise isstationary. In practical cases (e. g. ECG) this condition is notnecessarily met. The reasons can be physiological (respiration, movements, electrode artifacts). Because of this the improvement in SNR by averaging can be much worse than 1/N. A very prominent method for considering non-stationarities is weighted averaging, theweights depending inversely on the variance of the noise in therespective signal segment:
∑ ∑= =
==M
m
M
mmmm wkxw
Mkx
1 1
1,][1
][
∑=
= M
i i
mmw
12
2 111
σσ
with
segments with higher error variance contribute less to the final result
(2) Determination of the starting and end points of waves
Pi Pf Qi Sf Ti Tf
start ofpuls wave
isoelectric segment
wave
tstart end
e. g.: ECG:
We need algorithms for the classification which samples form part of the isoelectricsegment and which ones belong to the wave. The start or end of the wave would then be the separation point for samples which enter into the classification and which one not.Common problems: noise, interferences, baseline drifts
Detection of start and end
threshold in the derivative
intersection of straight lines
triangulation
wavelet analysis
time frequency analysis
require theprevious detection
of the wave
(2.1) Detection by thresholding the derivative
Principle: An isoelectric segment has (theoretically) a derivative zero (at least close to zero). In contrast the wave contributes with a significant derivative, except around its extrema
0 50 100 150 200 250 300-15
-10
-5
0
5
0 50 100 150 200 250 300-0.6
-0.4
-0.2
0
0.2
0.4
original signal
derivative
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.
0 50 100 150 200 250 300-15
-10
-5
0
5
0 50 100 150 200 250 300-0.6
-0.4
-0.2
0
0.2
0.4
start0.34
-0.46
0.34/5=0.07
-0.09
end
wav
ede
rivat
ive
filtering of signal
reduction of noiseand interference
(lowpass)
baseline driftelimination(highpass)
detection of maximain the wave
by threshold or template
windowing
must include that part of the wave
which lies betweenmaximum and
isoelectric segment
detection of startand end
the wave must bemonotonic for correct functionthe lower the thresholdthe farther away is the separation pointfrom the wave’s maximum
schematic of the processing flow
function pin=inic(x,pma,l,fs,pen,fac);%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%pin: starting point positions of the waves
l=l*fs/1000; %conversion ms � samplesfor i=1:length(pma) %from first to last detected wavexmu=x(pma(i)-l:pma(i)); %select a window of the wavexmud=diff(xmu); %differentiate[m,n]=max(xmud*pen); %find maximum of derivativexmud=xmud(1:n); %cut the windowk=find(pen*xmud<m/fac); %find points below thresholdk=k(length(k)); %the separation point lies at the crossingpin(i)=pma(i)-l+k-1; %calculate positionend
MATLAB implementation, find start of wave
function pfi=final(x,pma,l,fs,pen,fac);%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%pfi: end point positions of the waves
l=l*fs/1000; %conversion ms � samplesfor i=1:length(pma) %from first to last detected wavexmu=x(pma(i):pma(i)+l); %select a window of the wavexmud=diff(xmu); %differentiate[m,n]=max(xmud*pen); %find maximum of derivativexmud=xmud(n:length(xmud)); %cut the windowk=find(pen*xmud<m/fac); %find points below thresholdk=k(1); %the separation point lies at the crossingpfi(i)=pma(i)+n+k-1; %calculate positionend
MATLAB implementation, find end of wavePATTERN: time domain
0 50 100 150 200 250 300
pin=inic(signal,202,100,1000,1,5)» pin =143pfi=final(signal,202,length(signal)-203,1000,-1,5)» pfi =249
wave duration: 249-143=106 ms
[m,n]=max(signal)m =1219n =265» pin=inic(signal,n,100,1000,1,5)pin =181» pfi=final(signal,530,length(signal)-531,1000,-1,5)pfi =645wave 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 thresholdingPATTERN: time domain
(2.2) Detection by the intersection of tangents
Principle: the starting and end point is determined by the intersection of 2 straight lines. One of them is a tangent of the wave, the other one is a linear approximation of the isoelectric segment.
50 100 150 200 250-10
-5
0
5
10
15
20
Result depends on the locatopn of the tangent
PATTERN: time domain
Proceeding: Starting from the maximum slope of the wave a point of the wave is selectet at which the slope is a certain fraction of the maximum slope. Then the tangent in this point is calculated. On the other hand another straight line is adjusted to the isoelectric segment from several recurrecnes (regression line with minimum quadratic error criterion). Then the intersection of both lines is carried out.
prerequisites: •Same preprocessing as for threshold detection of waves•the respective wave segment must be monotone
problem: the position of the intersection point depends on the slope� flatter waves yield higher uncertainty
PATTERN: time domainfunction 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%pen: 1 if wave is positive, -1 else%fac: threshold factor%pin: starting point positions of the wavesl=l*fs/1000; %ms � samplesfor i=1:length(pos) % from first to last detected wave
xm=x(pos(i)-l:pos(i)); %signal windowxmd=pen*diff(xm); %calculate derivative[m,n]=max(xmd); %maximum of the derivativexmd=xmd(1:n); %second windowk=find(xmd<m/fac); %find threshold of derivativek=k(length(k));r1=xmd(k)*pen*((1:length(xm))-k)+xm(k); %tangent on the wavexiso=xm(1:miso); %window for the isoelectric segmentxiso=xiso(:)';p=polyfit((1:miso),xiso,1); %estimate regression liner2=polyval(p,(1:length(xm))); %estimate regression linek=find(r2<r1); %find intersectionk=k(1);pin(i)=pos(i)-l+k-1; %calculate position
end
MATLAB implementation, find start of wave PATTERN: time domain
function pfin=finalr(x,pos,l,fs,fac,pen,miso)%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 wavesl=l*fs/1000; %ms � samplesfor i=1:length(pos) % from first to last detected wave
xm=x(pos(i):pos(i)+l); %signal windowxmd=pen*diff(xm); %calculate derivative[m,n]=max(xmd); % maximum of the derivativexmd=xmd(n:length(xmd)); %second windowk=find(xmd<m/fac); %locate thresholdk=k(1); %find tangent pointr1=xmd(k)*pen*((1:length(xm))-(k+n-1))+xm(k+n-1); %tangentxiso=xm(length(xm)-miso:length(xm)); %isoelectric segmentxiso=xiso(:)';p=polyfit(length(xm)-miso:length(xm),xiso,1); %estimate regression liner2=polyval(p,(1:length(xm))); %estimate regression linek=find(r2>r1); %Intersect
k=k(1); %intersection pointpfin(i)=k+pos(i); %Calculate position
end
MATLAB implementation, find end of wave PATTERN: time domain
0 50 100 150 200 250 300
pin=inicr(mu,187,186,1000,2,1,20)» pin =132pfin=finalr(mu,187,length(mu)-188,1000,2,-1,20)» pfin =240wave duration: 108 ms
Result intersectionPATTERN: time domain
(2.3) Detection by triangulation
Principle: The area which is determined by 3 points (one on the wave, the second in the isoelectric segment and the third in between) is maximum if the third point is located at the beginning of the wave
0 50 100 150 200 250 300-8
-6
-4
-2
0
2
4
6
8
10
A1A2
A1 < A2
PATTERN: time domain
Proceeding: Select an analysis window (which most probably contains the third point) the ends of which are formed by one point of the isoelectricsegment (with constant distance to the maximum of the wave) and the maximum of the slope of the wave.
maximum area
area for different locations
max !
PATTERN: time domain
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 � samplesfor i=1:length(pos) %from first to lastxm=x(pos(i):pos(i)+l); %windowingxd=diff(xm)*pen; %differentiate[m,n]=max(xd); %maximum slopexm=xm(n:length(xm)); %new window (from isoelectric point to max. slope)for j=1:length(xm)are(j)=abs(0.5*(j*(-xm(length(xm))+xm(j))-(-j+length(xm))*(xm(1)-xm(j))));end %calculate area[m,nn]=max(are); %maximum areapfin(i)=nn+n-1+pos(i); %wave positionend
MATLAB implementation, find start of wave PATTERN: time domain
1340 1360 1380 1400 1420 1440 1460 1480 1500 1520 1540
pini=initr(onda,1450,150,1000,1)>>pini =1403pfin=fintr(ecgf,1450,90,1000,-1)>>pfin = 1516
wave duration: 113 ms
Result triangulation
The triangulation algorithm is very robust
PATTERN: time domain
Conclusions
algorithms for thedetection of start
and end
localization of the wave
knowledge of an appropriate analysis window
knowledge about the wave shape
previous lowpass filtering required
detection by threshold or
intersection
the result depends on anempirically chosen parameter
Deteccion bytriangulation
the result depends only on thetwo (mostly uncritical) end
points of the analysis window
PATTERN: time domain
Methodology of HRV-analysis(source: www.hrvcongress.org/courses)
HRV ANA
• Analysis in the time domain (Time domain methods)
• Analysis in the frequency domain (Spectral domain methods)
• non-linear methods
• mathematical modelling
(1) Analysis in the time domain(Time domain methods)
Basis of the analysis is either the HR in any time instant(‚instantaneous HR‘) or the interval between two subsequent QRS complexes of normal heart actions (‚Normal-normal‘, abbrev. NN). For this purpose a detection of the R-peaks must be carried out first. Then a series of inter-beat intervals is generated.
(1.1) Statistical methods
The measures obtained after analyses of a series of instantaneous heart rates or NN intervals can be divided into 2 classes:
1. those derived from direct measurements of the instantaneousheart rate or NN intervals
2. those derived from the differences between NN intervals
HRV ANA
The following indices have been defined so far:
• Mean heart rate (HR, int/min)• Mean NN interval (mNN or mRR, ms)• Standard deviation of the NN interval (sdNN or sdRR, ms) - the square root of variance between the NN intervals. Since variance is mathematically equal to total power of spectral analysis, sdNN reflects all the cyclic components responsible for variability in theperiod of recording. • Standard deviation of the average NN interval calculated o ver 5-min periods withinthe 24 - hours recording (SDANN, ms). This parameter is an estimate of the changes in heart rate due to cycles longer than 5 minutes• Mean of the standard deviations of all NN intervals for all 5 min segments of entirerecording (SDNN index, ms) . This index reflects the variability due to cycles shorter than 5 minutes• The square root of the mean squared differences of success ive NN intervals(RMSSD, ms).• The number of pairs of adjacent NN intervals differing by more th an 50 ms in theentire recording (NN50) . NN50 count divided by the total number of all NN intervals(pNN50, %)
The last three measurements reflect high frequency variations in the HRV and thus are highly correlated.
HRV ANA
Frequently applied index: RMSSD
RMSSD: Root Mean Square of Successive RR-
DifferencesRR1 RR2 RR3 RR4 RR5 .......
D1 D2 D3 D4 D5 .......
N
DN
ii∑
= =1
2
RMSSD
„Task Force of the European Society of Cardiology and the North American Society of Pacing and Electrophysiology“, Circulation 93, pp: 1043-1065, 1996
HRV ANA
(1.2) Geometrical Methods
Conversion of the series of NN intervals into geometric patterns:
(a) interval tachogram is a graph of the NN intervals complexes
time [min]0 3
60
80
HR
„Tachogram“
HRV ANA
(b) scaterogram: Abscissa of the point is the length of theprevious NN interval. Ordinate of the point it the length of thesubsequent NN interval. The decreased HRV is reflected in a greater density and smaller size of the cloud. The type of thepoint distribution is determined by origin of QRS complexes.
(2) Spectral Domain Methods
The important characteristics of the spectrum are the power density of the spectrum (power spectral density, PSD) and the powers of its separate zones.
time [min]0 3
60
80
HR
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.450
20
40
60
80
100
120
140
160
PSD [n.u.]
LF HF
frequency [Hz]
„Tachogram“
HRV ANA
VLF
typical HRV-spectrum for short-term analysis
HF
LF
4 spectral zones are distinguished:• ULF, ultra low frequencies, <0,003 Hz• VLF, very low frequencies, 0,003 - 0,04 Hz• LF, low frequencies, 0,04 - 0,15 Hz• HF, high frequencies, 0,15 - 0,4 Hz
HRV ANA
Indices derived from short-term recordings (5 min)
• Total Power [ms2] - Variance of all NN intervals• VLF, [ms2] - power in the very low frequency range • LF, [ms2] - power in the low frequency range• LFnorm, n.u. - LF power in normalized units: • 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 • LF/HF - ratio LF /HF
HRV ANA
Indices derived from long-term recordings (24 h)
• Total Power [ms2] - Variance of all NN intervals• ULF, [ms2] - power in the ultra low frequency range• VLF, [ms2] - power in the very low frequency range • LF, [ms2] - power in the low frequency range• LFnorm, n.u. - LF power in normalized units: • LF/(Total Power - VLF)*100 • HF, [ms2] - power in the high frequency range
HRV ANA Physiological interpretation of the different spectralcomponents
ULF-band: origin is unknown, however the prognosis of a sudden death according to its power is the most accurate.
VLF-band: still a matter of investigation. Most probable corre-lates: thermoregulation, renin-angiotensin system activation, changes in physical activity.
LF-band: to some extent generated by baroreceptormodulations of sympathetic and vagus nervous tone. Accordingto other references it is mostly dependent on the sympatheticactivation.
HF-band: respiratory modulation of the vagus nerve activity.
HRV ANA
(3) Non - Linear Methods
The stochastic indexes of the regulatory systems functioningmay be obtained by chaos analyses of the heart rate variability. Such indexes are thought to reflect the stressresistance of regulatory systems.
(4) Mathematic Modeling Methods
Mathematic modeling is a special tool that gives the possibilityto evaluate those properties of regulatory systems and processes that can't be obtained by direct measurements.Sensitivity and specificity of the effective systems to humoralsympathetic and parasympathetic influences can be obtainedwith the help of these methods.
HRV ANA
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.40
20
40
60
80
100
120
LF HF
LF/HF = 2,53
LF-band (0.04÷0.15 Hz): power is influenced by the sympathetic efferent activity
HF-band (0.15÷0.4 Hz): power mainly determined by the vagal efferent activity
LF/HF - typical:
LF-power
HF-powerLF/HF =
Rest
Orthostasis
Sleeping
≥≥≥≥ 1
÷÷÷÷ 20
< 1
Index of „sympatho-vagal“ balance
PSD [n.u.]
Frequency [Hz]
HRV ANA
Beispiel: Herzrate
4456 4458 4460 4462 4464 4466 4468 4470 4472 4474
0
0.5
1
1.5
2
2.5
3
Abtastung nicht äquidistant
Solution: Interpolation and resampling of the heart rate at a frequency sufficiently higher than half of the maximumfrequency of interest.(1) definition of a resampling frequency fr (recommended 4 Hz)(2) Define a local window at each sampling time tk between
tk-1 and tk+1(3) calculate a fractional R rk = fr nk/2 (see figure), e. g.
(b/I3+c/I4)/(fr/2) average beats per windowlength
HR, resampled
(4) Deconvolution with local window spectrum
1/I1 1/I2 1/I3 1/I4
t
HR [1/s]
ffr/2
original HR-spectrum warped HR-spectrum
window spectrum W
f
restauration of originalspectrum by multiplicationwith 1/W
1/W
T=2/fr
HRV ANA