TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
Signal__assert_type.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 Signal__assert_type.m
17 %> @brief Checks that the signal given on the input is of the type nameWanted
18 %> This function is mainly used by @b SSS_assert_type(Sig), with params @b Sig and @b SSS.
19 %
20 %> @attention NOTA BENE: in the case that Signal is a BULK signal, this function will
21 %> return, if it exists, the wanted signal, or fail if it doesn't.
22 %
23 %> @param Signal: The signal you want to make sure of the type (can be a BULK signal,
24 %> in that case, will take the component.
25 %> Bulk: if the input is a bulk than the bulk is also returned to keep a
26 %> backup of it. An empty vector is returned if the input is not a Bulk
27 %> @param nameWanted: the type the signal must be of (ex: 'GSR').
28 %
29 %> @retval Signal: the signal. Can be the same as the input if single signal, or the
30 %> signal from the bulk if the input signal is a bulk one.
31 
32 function [Signal, Bulk] = Signal__assert_type(Signal, nameWanted)
33 
34 if(nargin ~= 2 || nargout > 2)
35  %If matlab was clever, they'd have implemented print_usage, like octave
36  error('Usage: [Signal, Bulk] = Signal__assert_type(Signal, nameWanted)')
37 end
38 
39 if(~isfield(Signal, 'TEAP'))
40  error('The signal seems not to be a TEAP one.');
41 end
42 
43 if(length(Signal) ~= 1)
44  error(['You seem to have given a bulk signal with multiple epochs. ' ...
45  'Could you please choose the epoch you want (eg: with Bulk(1))']);
46 end
47 
48 %Initialize bulk to empty (in the case the input was not bulk)
49 Bulk = [];
50 
51 %can either be a Bulk or a single signal
52 if(Signal.TEAP == 'S') %Single speed ^W Signal
53  Signal__assert_mine(Signal);
54 elseif(Signal.TEAP == 'B') %Bulk signal
55  %We have to choose the signal that we want
56  Bulk = Signal;
57  Signal = Bulk_get_signal(Signal, nameWanted); %Will fail if does not exist
58 else
59  error('The signal type is unknown. Should either be Signal or Bulk');
60 end
61 
62 %And then, compare their name (redundant for 2nd case, but anyways :p)
63 name = Signal__get_signame(Signal);
64 if(~strcmp(name, nameWanted))
65  error(['Signal is of type: ' name '. Should be ' nameWanted])
66 end
Signal__assert_mine
function Signal__assert_mine(in Signal)
Signal__assert_type
function Signal__assert_type(in Signal, in nameWanted)
Bulk_get_signal
function Bulk_get_signal(in BulkSignal, in typeWanted)
Signal__get_signame
function Signal__get_signame(in Signal)