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 Computes the main frequency of a respiration signal.
19 %> @param RESsignal: the RES signal.
21 %> @retval mainFreq: the main respiration frequency, given in Hz
23 %> @author Copyright Guillaume Chanel 2013
24 %> @author Copyright Frank Villaro-Dixon, 2014
29 %Make sure we have a RES signal
36 %Make a filter
for our signal
37 Fpeak = 0.375; % Peak Frequency
39 Apass = 1; % Bandwidth Attenuation
40 [b, a] =
iirpeak(Fpeak/(fs/2), BW/(fs/2), Apass);
41 Resp_filt = filtfilt(b, a, raw);
43 if length(Resp_filt) < 60*fs
44 warning(
'Resp signal too short cannot calculate the spectral features - result of the central respiration frequency is not going to be reliable')
46 %Compute the energy spectrum
47 win_length = round(length(Resp_filt)/4.5);
48 nfft = sqrt(2^ceil(log2(win_length)));
50 %had to specify for compatibility between octave and matlab
51 [RespPower, fResp] = pwelch(Resp_filt, win_length, round(0.5*win_length), [], fs,'power');
53 %Take the frequencies we want
54 iFreqInterest = find(0.16 <= fResp & fResp <= 1.0);
56 [dummy, iMainFreq] = max(RespPower(iFreqInterest));
58 mainFreq = fResp(iFreqInterest(iMainFreq));
59 % if isempty(mainFreq)