TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
RES_feat_mainfreq.m
Go to the documentation of this file.
1 %This file is part of TEAP.
2 %
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.
7 %
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.
12 %
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/>.
15 %
16 %> @file RES_feat_mainfreq.m
17 %> @brief Computes the main frequency of a respiration signal.
18 %
19 %> @param RESsignal: the RES signal.
20 %
21 %> @retval mainFreq: the main respiration frequency, given in Hz
22 %
23 %> @author Copyright Guillaume Chanel 2013
24 %> @author Copyright Frank Villaro-Dixon, 2014
25 
26 function [mainFreq] = RES_feat_mainfreq(RESsignal)
27 
28 
29 %Make sure we have a RES signal
30 RESsignal = RES__assert_type(RESsignal);
31 
32 
33 raw = Signal__get_raw(RESsignal);
34 fs = Signal__get_samprate(RESsignal);
35 
36 %Make a filter for our signal
37 Fpeak = 0.375; % Peak Frequency
38 BW = 0.5; % Bandwidth
39 Apass = 1; % Bandwidth Attenuation
40 [b, a] = iirpeak(Fpeak/(fs/2), BW/(fs/2), Apass);
41 Resp_filt = filtfilt(b, a, raw);
42 
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')
45 end
46 %Compute the energy spectrum
47 win_length = round(length(Resp_filt)/4.5);
48 nfft = sqrt(2^ceil(log2(win_length)));
49 
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');
52 
53 %Take the frequencies we want
54 iFreqInterest = find(0.16 <= fResp & fResp <= 1.0);
55 
56 [dummy, iMainFreq] = max(RespPower(iFreqInterest));
57 
58 mainFreq = fResp(iFreqInterest(iMainFreq));
59 % if isempty(mainFreq)
60 % mainFreq = NaN;
61 % end
62 
Signal__get_samprate
function Signal__get_samprate(in Signal)
iirpeak
function iirpeak(in Wo, in BW, in varargin)
RES_feat_mainfreq
function RES_feat_mainfreq(in RESsignal)
Signal__get_raw
function Signal__get_raw(in Signal)
RES__assert_type
function RES__assert_type(in Signal)