An efficient timevarying filter for detrending and bandwidth limiting the heart rate variability tachogram without resampling: MATLAB opensource code and Internet webbased implementation.  
Jump to Full Text  
MedLine Citation:

PMID: 22474535 Owner: NLM Status: MEDLINE 
Abstract/OtherAbstract:

The heart rate variability (HRV) signal derived from the ECG is a beattobeat record of RR intervals and is, as a time series, irregularly sampled. It is common engineering practice to resample this record, typically at 4 Hz, onto a regular time axis for analysis in advance of time domain filtering and spectral analysis based on the DFT. However, it is recognised that resampling introduces noise and frequency bias. The present work describes the implementation of a timevarying filter using a smoothing priors approach based on a Gaussian process model, which does not require data to be regular in time. Its output is directly compatible with the LombScargle algorithm for power density estimation. A webbased demonstration is available over the Internet for exemplar data. The MATLAB (MathWorks Inc.) code can be downloaded as open source. 
Authors:

A Eleuteri; A C Fisher; D Groves; C J Dewhurst 
Related Documents
:

17169905  Effects of ringporous and diffuseporous stem wood anatomy on the hydraulic parameters... 17397855  Systematic errors in analytical measurement results. 6620355  Assessment of the design and performance of the sage syringe pump model 341a, with part... 14545685  Multivariate ftir analysis of substrates for protein, polysaccharide, lipid and microbe... 10292525  Public service announcements: their effect on smoking. 18985175  Predicting airborne particle levels aboard washington state school buses. 
Publication Detail:

Type: Journal Article Date: 20120306 
Journal Detail:

Title: Computational and mathematical methods in medicine Volume: 2012 ISSN: 17486718 ISO Abbreviation: Comput Math Methods Med Publication Date: 2012 
Date Detail:

Created Date: 20120404 Completed Date: 20120716 Revised Date: 20130626 
Medline Journal Info:

Nlm Unique ID: 101277751 Medline TA: Comput Math Methods Med Country: United States 
Other Details:

Languages: eng Pagination: 578785 Citation Subset: IM 
Affiliation:

Department of Medical Physics & Clinical Engineering, Royal Liverpool & Broadgreen University Hospital, Liverpool L7 8XP, UK. 
Export Citation:

APA/MLA Format Download EndNote Download BibTex 
MeSH Terms  
Descriptor/Qualifier:

Adult Algorithms Electrocardiography / methods Heart Rate / physiology* Humans Internet Models, Cardiovascular* Models, Statistical Software 
Comments/Corrections 
Full Text  
Journal Information Journal ID (nlmta): Comput Math Methods Med Journal ID (isoabbrev): Comput Math Methods Med Journal ID (publisherid): CMMM ISSN: 1748670X ISSN: 17486718 Publisher: Hindawi Publishing Corporation 
Article Information Download PDF Copyright © 2012 A. Eleuteri et al. openaccess: Received Day: 13 Month: 5 Year: 2011 Revision Received Day: 3 Month: 11 Year: 2011 Accepted Day: 21 Month: 11 Year: 2011 Print publication date: Year: 2012 Electronic publication date: Day: 6 Month: 3 Year: 2012 Volume: 2012Elocation ID: 578785 ID: 3310232 PubMed Id: 22474535 DOI: 10.1155/2012/578785 
An Efficient TimeVarying Filter for Detrending and Bandwidth Limiting the Heart Rate Variability Tachogram without Resampling: MATLAB OpenSource Code and Internet WebBased Implementation  
A. Eleuteri^{1}  
A. C. Fisher^{1}*  
D. Groves^{2}  
C. J. Dewhurst^{3}  
^{1}Department of Medical Physics & Clinical Engineering, Royal Liverpool & Broadgreen University Hospital, Liverpool L7 8XP, UK 

^{2}National Refractory Angina Centre, Royal Liverpool & Broadgreen University Hospital, Liverpool L7 8XP, UK 

^{3}Department of Neonatal Medicine, Liverpool Women's Hospital, Liverpool L8 7SS, UK 

Correspondence: *A. C. Fisher: a.c.fisher@liv.ac.uk [other] Academic Editor: Quan Long 
A time record consisting of beattobeat RR intervals is referred to as the heart rate tachogram. This forms the basis for a number of metrics of heart rate variability (HRV). The simplest measures of HRV are based on variance determined over a range of time periods. More complex measures can be derived from power spectrum density (PSD) estimations. The two most commonly used PSDs are the Welch Periodogram, based on the DFT, and the AR Spectrum, based on an autoregressive process model [^{1}]. Both approaches require the data to be sampled regularly. Resampling the raw HRV data onto a regular time axis introduces noise into the signal and the information quality is compromised [^{1}]. Conventionally, the HRV power is reported over 3 bandwidths: [0.01 ⋯ 0.04] Hz (Very Low Frequency, VLF) [0.04 ⋯ 0.15] Hz (Low Frequency, LF), and [0.15 ⋯ 0.4] Hz (High Frequency, HF) [^{1}, ^{2}].
Prior to transformation into the frequency domain, normal practice requires that the time series data are “detrended” or “highpass filtered” at a very low frequency, say ~0.005 Hz. There is no universally formal justification for such detrending other than it minimises the effects of mediumterm nonstationarity within the immediate time epoch (window) of interest [^{2}]. Stationarity is an axiomatic assumption in conventional timetofrequency transformation of the PSD (see Appendix B).
A number of methods have been described to identify the trend component in the tachogram such that it can be simply removed by subtraction. These methods include fixed loworder polynomials [^{3}, ^{4}], adaptive higherorder polynomials [^{5}, ^{6}], and, more recently, the smoothing by priors approach (SPA) proposed by [^{7}] which they describe as a timevarying finite impulse highpass filter. The SPA uses a technique wellestablished in modern time series analysis and it addresses directly the phenomenon of nonstationarity.
However, the Tarvainen approach suffers two limitations. The first is conceptual: the algorithm requires resampling by interpolation onto a regular time axis. The second is practical: the MATLAB implementation is computationally inefficient and expensive and consequently very slow. In practice, its application is limited to relatively short tachograms [^{7}].
In the present work, a novel algorithm is introduced which obviates these limitations by extending the SPA. The Smoothing by Gaussian process Priors (SGP) method described here explicitly does not require resampling and executes in MATLAB at least an order of magnitude faster than the SPA. By employing the SGP twice in sequence, the bandpass effect achieves detrending (highpass) and lowpass filtering which is directly compatible with the Lomb Scargle Periodogram (LSP) [^{8}].
The SPA method considers the problem of modelling the trend component in a time series with a linear observation model:
(1)
ztrend=Hy+v, 
(2)
y^σ=argminyHy−z2+σ2Dd(Hy)2, 
By choosing H as the identity matrix, and d = 2, the solution can be written as
(3)
y^σ=(I+σ2D2TD2)−1z. 
Tarvainen et al. argue that selection of the observation matrix is done to simplify things, in the context of estimating parameters in a finitedimensional space. A Bayesian interpretation of (2) is given, but always in the context of finitedimensional parameter spaces. It is interesting and useful to give a different interpretation in the context of Gaussian Process (GP) priors, which implies a functionspace view, rather than a parametric view, of the regression problem. In passing it is noted that the SPA, as published, is markedly inefficient and potentially unstable in using matrix inversion. A more efficient approach is presented as Appendix C.
Use of the D_{2} operator implies uniform sampling of the data and in the case of the HRV tachogram requires that the raw data be projected onto a regular time axis using some means of interpolation. Such a projection is frequently referred to as resampling which is undesirable in that it corrupts, preferentially, the higher frequency components [^{2}]. In the present development, it is proposed that resampling can be avoided by using a different approximation for the secondorder derivative operator. The usual approximation is based on a centred formula:
(4)
f″(xi)=f(xi+1)−2f(xi)+f(xi−1)h2+O(h2), 
A different approximation formula to the derivative, which does not imply uniform sampling, can also be obtained by Taylor expansion with nonuniform increments. After some algebra,
(5)
f″(xi)=2f(xi+1)(xi−1−xi)−f(xi)(xi−1−xi+1)+f(xi−1)(xi−xi+1)(xi−1−xi)(xi−1−xi+1)(xi−xi+1)+O(h), 
The rows of the operator now explicitly depend on the x values as desired:
(6)
[2(xi+1−xi−1)(xi+1−xi), −2(xi+1−xi)(xi−xi−1),2(xi+1−xi−1)(xi−xi−1)]. 
The operator is denoted by the symbol D^2.
An efficient implementation of the above algorithm (MATLAB) is the following:
 T = length(x);
 id = 2 : (T − 1);
 idp1 = id + 1;
 idm1 = id − 1;
 V1 = 2./((x(idm1) − x(idp1)). *(x(id) − x(idp1)));
 V2 = −2./((x(idm1) − x(id)). *(x(id) − x(idp1)));
 V3 = 2./((x(idm1) − x(id)). *(x(idm1) − x(idp1)));
 D2hat = spdiags ([V1, V2, V3]∖V1(1), [0 : 2], T − 2, T);
 L = chol(speye(T) + sigma ^{∧}2 *D2hat' *D2hat, ‘lower');
 z_stat = z − L'∖(L∖z);
Note that to reduce the possibility of numerical instabilities in the solution of the linear systems, the D2hat matrix is normalised by the first element of vector V1.
The operation of the smoothing priors can be understood by looking at the following simplified form:
(7)
y=Hz, 
Since each element of z and y can be thought of as placed at a distinct time point, it is seen that each row of the H matrix acts over all the elements of z to produce a single element of y. Consequently, the filter is noncausal. In fact, each row of H defines a weighting function. Each weighting function is localised around a specific time, and its bandwidth determines how many samples from the past and from the future contribute to the estimate. The wider the weighting function, the smoother the resulting estimates.
In the case of uniformly sampled data, the weighting functions have the same shape (except at the boundaries), which can be imagined as a sliding window translating in time: this is a consequence of the definition of the D_{2} operator, which is time independent. Figure 1 shows some weight functions implied by the D_{2} operator.
However, for the case of arbitrarily (irregularly) sampled data of the HRV tachogram, the D^2 operator actually depends on time; therefore the weighting functions will take on a different shape. This makes the resulting filter effectively a timevariant filter. It is possible to calculate the transfer function of the filter H in the limit as the number of data points tends to infinity. It can be shown [^{2}] that the (nonstationary) spectral density of the Gaussian process prior is
(8)
S(f)∝14π2f4. 
From the above, the power spectral density of the equivalent kernel filter is derived as
(9)
h(f)=1σ24π2f4+1. 
In Figure 2 it is shown an example of the transfer function of the equivalent kernel filter (with σ^{2} = 1): the phase is constant zero.
Although the approximation in (9) is only valid in the limit as the number of data points goes to infinity, it is still useful for calculating the approximate −3 dB bandwidth of the finitesample approximation of the filter in terms of the smoothing parameter σ^{2}. Whereas the SPA as presented [^{7}] does not provide an effective bandwidth estimate but only the qualitative behaviour of the filter, the following approximation provides a quantitative tool.
Inverting (9) and applying the bilinear transformation of the continuous frequencies, we get
(10)
σ2=(2−1)(2tan(ωcπ2))−4, 
Since the number of data points mostly impacts the estimation of low frequencies, the expectation is that the approximation is good in the lowfrequency range.
In a Monte Carlo simulation, 1000 replications of the Welch periodogram estimates were made of white Gaussian noise coloured through the equivalent filter H. Each noise sequence was composed of 5000 regularly spaced samples. In Table 1, it is seen that this approximation is good and, predictably, deteriorates as the cutoff frequency increases.
Figure 3 shows the transfer function of the digital equivalent kernel filter.
There is very little phase distortion, except at very high frequencies close to the Nyquist frequency.
A synthetic data set of was generated (MATLAB) as series of normallydistributed random numbers of mean 0.85(1) s (equivalent to a heart rate of ~75 bpm) and std 0.025 s: this was lowpass filtered at 1 Hz (3rdorder phaseless IIR). These data were projected by interpolation, onto an irregular time axis of mean interval 0.86(1) s and variance 0.01s^{2}. The resulting synthetic HRV record, as a time record of bandlimited Gaussian noise, was of 30 s duration, average sampling frequency of 1.15(6) Hz and had no significant power above 1 Hz.
Clinical ECG data from a Lead II configuration were recorded from a healthy adult seated for a period of 60 minutes using a Spacelabs Medical Pathfinder Holter system. RR intervals were available with 1 ms resolution.
The time domain and frequency domain (as the Lomb Scargle periodogram) representations of the synthetic data set and the clinical data set are shown in Figure 4 to illustrate the bandpass filtering effect achieved using sequential SGP. The synthetic HRV data and the clinical HRV data are filtered in the bandpass [0.025 ⋯ 0.5] Hz and [0.025 ⋯ 0.35] Hz, respectively.
Resources relevant to this work are located at http://clinengnhs.liv.ac.uk/links.htm and include the following.
 A website demonstration of SGP running on an automation instance of MATLAB 2008a. Developed for JavaScriptenabled MS IE6+ and FireFox browsers.
 MATLAB opensource code:
 Smoothing by Gaussian process Priors (SGP): gpsmooth_3.m,
 Optimized Lomb Scargle Periodogram (fLSPw: fastest Lomb Scargle Periodogram in the West): fLSPw.m.
The SGP (Smoothing by Gaussian process Priors) algorithm is a secondorder response timevarying filter which operates on irregularly sampled data without compromising lowfrequency fidelity. In the context of Heart Rate Variability analysis, it provides detrending (highpass) and lowpass filtering with explicitly specified −3 dB cutoff points. A small limitation is the implicit requirement to assume a representative sampling frequency to establish the frequency interval: here this is taken as the reciprocal of the median sampling interval. The SGP MATLAB code is available as open source via a comprehensive website and is directly compatible with an optimised implementation of the Lomb Scargle Periodogram (fLSPw) estimator.
Consider the posterior expectation of a GP regressor (2) at a set of training data points z:
(A.1)
y^σ=K(K+σ2I)−1z, 
(A.2)
y^σ=[(K+σ2I)K−1]−1z≡(KK−1+σ2K−1)−1z≡(I+σ2K−1)−1z. 
Comparing the above with (3),
(A.3)
DdTDd=K−1. 
 The parameter σ describes the amount of (Gaussian) white noise, which affects the data. As σ gets smaller, the filtering process gets smoother.
 The smoothness properties of the resulting estimator depend not only on σ, but also on the choice of the covariance matrix K. Note that polynomials up to (and including) 1st degree are in the null space of the regularization operator (i.e., they are both mapped to constants), which means that they are not penalized at all. This implies that the Gaussian Process prior is not stationary (see Appendix B for a definition).
A Gaussian process is completely described by its mean function and covariance function. Given a real process f(t), these functions are specified as the following expectations:
(B.1)
m(t)=E[f(t)],k(t,t′)=E[(f(t)−m(t))(f(t′)−m(t′))]. 
A stationary covariance function is a function of t − t', that is, it is invariant to translations. The above definitions can be used to define stationarity for Gaussian processes. A process which has constant mean and whose covariance function is stationary is called weakly stationary (or widesense stationary, WSS). A process whose joint distributions are invariant to translations, that is, the statistics of f(t) and f(t + c) are the same for any c, is called strictly stationary (or strictsense stationary, SSS). It can be shown that as SSS process is also WSS, and if the process is Gaussian, then the converse is also true.
If any of the above conditions are violated, then the process is nonstationary; an example is the Gaussian process whose inverse covariance matrix is given by (4) and (5).
In general, matrix inversion is very computationally expensive and should be avoided whenever possible A more efficient solution uses the backslash operator ∖, which in MATLAB implements the solution of a linear system by Gaussian elimination. However, the matrix (I + σ^{2}D_{2}^{T}D_{2}) can be nearly singular and ill conditioned, depending on values of the parameter σ^{2}. To circumvent this risk, the lower Cholesky factor L (the square root) of this matrix is derived, so that
(C.1)
LLT=(I+σ2D2TD2). 
With this decomposition, matrix inversion can then simply be written as the solution, in sequence, of two triangular systems of linear equations, which is a very fast and numerically stable operation:
(C.2)
y^σ=LT∖(L∖z). 
Although the theoretical computational complexity of straight matrix inversion and the above (seemingly more complex) steps is the same, the hidden factors of the actual numerical computations make a very significant difference [^{9}]. The speedup is illustrated by performing the above computations on a sequence of varying length (from 1000 to 3000 samples), repeating the execution of both algorithms 100 times. Figure 5 shows the speedup as a function of the data set size.
It is clear that, as the dimension of the data set increases, the speedup increases quadratically, showing the inefficiency of the matrix inversionbased smoothing. The following code (MATLAB R006b) was used:
 T = length(z);
 D2 = spdiags(ones(T − 2,1) *[1 − 2 1, 0 : 2], T − 2, T);
 L = chol(speye(T) + sigma ^{∧}2 *D2' *D2, ‘lower'); % warning: potential bottleneck!
 z_stat = z − L'∖(L∖z);
It should be noted that in MATLAB R2006a, and possibly previous versions, multiplication of the σ^{2} coefficient by the sparse matrix is anomalously a very slow operation.
References
1.  Moody GB. Spectral analysis of heart rate without resamplingIn: Proceedings of the IEEE Conference on Computers in CardiologySeptember 1993London, UK715718 
2.  Malik M,Camm AJ,Bigger JT Jr.,et al. Heart rate variability. Standards of measurement, physiological interpretation, and clinical useEuropean Heart JournalYear: 19961733543818737210 
3.  Clifford GD. Clifford GD,Azuaje F,McSharry PEECG statistics, noise, artifacts, and missing dataAdvanced Methods for ECG AnalysisYear: 2006Boston, Mass, USAArtechHouse5593 
4.  Litvack DA,Oberlander TF,Carney LH,Saul JP. Time and frequency domain methods for heart rate variability analysis: a methodological comparisonPsychophysiologyYear: 19953254925047568644 
5.  Mitov IP. A method for assessment and processing of biomedical signals containing trend and periodic componentsMedical Engineering and PhysicsYear: 199820966066810098610 
6.  Porges S,Bohrer R. Cacioppo J,Tassinary LThe analysis of periodic processes in psychophysiological researchPrinciples of Psychophysiology Physical Social and Inferential ElementsYear: 1990Cambridge University Press703753 
7.  Tarvainen MP,Rantaaho PO,Karjalainen PA. An advanced detrending method with application to HRV analysisIEEE Transactions on Biomedical EngineeringYear: 200249217217512066885 
8.  Niskanen JP,Tarvainen MP,RantaAho PO,Karjalainen PA. Software for advanced HRV analysisComputer Methods and Programs in BiomedicineYear: 2004761738115313543 
9.  Gustafsson F. Determining the initial states in forwardbackward filteringIEEE Transactions on Signal ProcessingYear: 1996444988992 
Article Categories:

Previous Document: Randomized Comparison of the Therapeutic Effect of Acupuncture, Massage, and TachibanaStyleMethod ...
Next Document: Bayesian assessment of newborn brain maturity from twochannel sleep electroencephalograms.