comparison m-toolbox/m/sigproc/frequency_domain/phasetrack.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 function varargout = phasetrack(varargin)
2
3 ALGONAME = mfilename;
4 VERSION = '$Id: phasetrack.m,v 1.1 2008/05/21 09:53:13 anneke Exp $';
5 CATEGORY = 'Signal Processing';
6
7 %% Check if this is a call for parameters, the CVS version string
8 % or the function category
9 if nargin == 1 && ischar(varargin{1})
10 in = char(varargin{1});
11 if strcmp(in, 'Params')
12 varargout{1} = getDefaultPL();
13 return
14 elseif strcmp(in, 'Version')
15 varargout{1} = VERSION;
16 return
17 elseif strcmp(in, 'Category')
18 varargout{1} = CATEGORY;
19 return
20 end
21 end
22
23
24 invars = {};
25 for j=1:nargin
26 invars = [invars cellstr(inputname(j))];
27 end
28
29
30
31 as = [];
32 pl = [];
33 for j=1:nargin
34 a = varargin{j};
35 if isa(a, 'plist')
36 pl = a;
37 end
38 if isa(a, 'ao')
39 for k=1:length(a)
40 ak = a(k);
41 d = ak.data;
42 if isa(d, 'tsdata')
43 as = [as ak];
44 else
45 warning('### works only for time series');
46 end
47 end
48 end
49 end
50 na = length(as);
51 % unpack parameter list
52 plo = plist();
53
54 % Initialise output
55 bo = [];
56
57 for i=1:na
58
59 % get data out
60 a = as(i);
61 d = a.data;
62 dinfo = whos('d');
63 if ~isa(d, 'tsdata')
64 error('### I only work with time-series at the moment.');
65 end
66 if ~isreal(d.y)
67 error('### I only work with real time-series at the moment.');
68 end
69 add = 0;
70 ydata = a.data.y;
71 y = ydata;
72
73 for i = 2:length(ydata)
74
75 diff = ydata(i)-ydata(i-1);
76 if diff > pi/2
77 add = add-pi;
78 elseif diff < -pi/2
79 add = add+pi;
80 end
81 y(i) = ydata(i) + add;
82 end
83 % Make output analysis object
84 nameStr = sprintf('phasetrack(%s)', d.name);
85
86 % create new output data
87 data = tsdata(y, d.fs);
88 data = set(data, 'name', nameStr);
89 data = set(data, 'xunits', d.xunits);
90 data = set(data, 'yunits', d.yunits);
91
92 % create new output history
93 h = history(ALGONAME, VERSION, pl, a.hist);
94 h = set(h, 'invars', invars);
95
96 % make output analysis object
97 b = ao(data, h);
98
99 % set name
100 % name for this object
101 if isempty(invars{j})
102 n1 = a.name;
103 else
104 n1 = invars{j};
105 end
106
107 nameStr = sprintf('phasetrack(%s)', n1);
108 b = setnh(b, 'name', nameStr);
109
110 % Add to output array
111 bo = [bo b];
112
113
114 end
115 varargout{1} = bo;
116
117 %--------------------------------------------------------------------------
118 % Get default params
119 function plo = getDefaultPL()
120
121 disp('* creating default plist...');
122 plo = plist();
123 disp('* done.');
124
125
126 % END
127
128