1 %This file is part of TEAP.
3 %TEAP is free software: you can redistribute it and/or modify
4 %it under the terms of the GNU General Public License as published by
5 %the Free Software Foundation, either version 3 of the License, or
6 %(at your option) any later version.
8 %TEAP is distributed in the hope that it will be useful,
9 %but WITHOUT ANY WARRANTY; without even the implied warranty of
10 %MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 %GNU General Public License
for more details.
13 %You should have received a copy of the GNU General Public License
14 %along with TEAP. If not, see <http://www.gnu.org/licenses/>.
17 %> @brief This
function interpolate an HR/IBI signal (from a list of peaks) with the
18 %> method proposed in:
19 %> Berger et al.,
"An Efficient Algorithm for Spectral Analysis of
20 %> Heart Rate Variability", IEEE Trans. on Biomedical Engineering,
21 %> Vol. 33, No. 9, sept. 1986
22 %> @param peaks: a list of R peaks expressed in seconds (e.g. [0.3 1.4 2.3 3.2])
23 %> @param fs: sampling frequency desired
for the interpolated HR/IBI signal
24 %> @param duration: duration desired. Concerning time aspects, the first sample
25 %> is assumed to lie at time 1/fs (which can be before the first peak) and
26 %> the last at time
'duration'. If point in time that are not computable
27 %> because of lack of peaks (beginning and end of the output signals), they are
28 %> simply padded with the closest computed value.
30 %> @retval IBI [1*N]: N interbeat intervals (in seconds)
31 %> @retval HR [1*N]: N heart rate values
32 %> @retval t [1*N]: N time stamps corresponding to the IBI and HR values
34 % @author: Guillaume Chanel
35 function [IBI,HR,t] =
interpIBI(peaks,fs,duration, silent)
36 %
function [IBI,HR,t] =
interpIBI(peaks,fs,duration)
38 % This
function interpolate an HR/IBI signal (from a list of peaks) with the
40 % Berger et al.,
"An Efficient Algorithm for Spectral Analysis of
41 % Heart Rate Variability", IEEE Trans. on Biomedical Engineering,
42 % Vol. 33, No. 9, sept. 1986
46 % peaks: a list of R peaks expressed in seconds (e.g. [0.3 1.4 2.3 3.2])
48 % fs : sampling frequency desired
for the interpolated HR/IBI signal
50 % duration : duration desired. Concerning time aspects, the first sample
51 % is assumed to lie at time 1/fs (which can be before the first peak) and
52 % the last at time
'duration'. If point in time that are not computable
53 % because of lack of peaks (beginning and end of the output signals), they are
54 % simply padded with the closest computed value.
58 % IBI [1*N]: N interbeat intervals (in seconds)
60 % HR [1*N]: N heart rate values
62 % t [1*N]: N time stamps corresponding to the IBI and HR values
64 % Author: Guillaume Chanel
71 %construction of time vector (starting at t=1/fs up to duration, with fs
72 %sampling rate) and corresponding HR vector
73 t = [1/fs:1/fs:duration]
';
77 %Construction of the uneven sampled IBI vector (to be replaced in the end)
80 % Define the first and last sample for HR computation : it starts 2 samples
81 % after the first peak and stop 2 samples before the last peak. This is
82 % necessary to have a full window for HR computation
83 firstSpl = find(t > peaks(1));
84 firstSpl = firstSpl(2);
85 lastSpl = find(t < peaks(end));
86 lastSpl = lastSpl(end-2);
91 % First the first computable to the last computable samples:
92 % compute the HR values !
93 for(i=firstSpl:lastSpl)
94 %Definition of boundaries of interval used for HR computation
98 %Identify the peaks that are present in the current interval
99 pInt = (peaks > minT) & (peaks < maxT);
102 %Depending on the differents cases:
103 if(nbP < 1) % no peaks in the current interval
104 %Find the unique IBI that correspond to the current time
105 idxIBI = find(peaks > t(i));
106 idxIBI = max(idxIBI(1)-1,1);
109 HR(i) = 1/IBI(idxIBI);
111 else %At least one peak in the current interval
112 %Send waring if more than one peak in an interval
113 if((nbP > 1) && ~silent) %more than one peak in an interval
114 warning([num2str(nbP) ' peaks were found in an interval -> consider increasing frequency
']);
117 %Compute the number of peaks (sum of IBI before peaks + IBI after
119 idxPeaks = find(pInt);
122 nbPeaks = nbPeaks + (peaks(iP)-max(minT,peaks(iP-1)))/IBI(iP-1);
124 nbPeaks = nbPeaks + (maxT-peaks(idxPeaks(end)))/IBI(idxPeaks(end)); %add IBI after the last peak
127 HR(i) = fs*nbPeaks/2;
133 %Fill begining and ending values with the first and last computed HR
134 HR(1:firstSpl) = HR(firstSpl);
135 HR(lastSpl:end) = HR(lastSpl);