Mercurial > hg > ltpda
comparison m-toolbox/m/mdcs/mdc1_UTN/ltpda_parfit_derivative.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 = ltpda_parfit_derivative(varargin) | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: LTPDA_PARFIT_DERIVATIVE performs the numeric time derivative using the method | |
5 % of 5 points parabolic fit [1]. The function can perform the second | |
6 % derivative, the first derivative and the point estimation. | |
7 % | |
8 % | |
9 % | |
10 % CALL: Deriv = ltpda_parfit_derivative(a, ... , pl) | |
11 % | |
12 % | |
13 % INPUTS: | |
14 % - Aos containing the data to be differentiated. | |
15 % - pl: is a parameter list containing the options for the | |
16 % calculation. Parameters are: | |
17 % - 'ORDER' whose accepeted options are: | |
18 % - 'ZERO' perform the point estimation using the | |
19 % coefficients vector d0 = [-3 12 17 12 -3]./35 | |
20 % - 'FIRST' perform the first derivative using the | |
21 % couefficients vector d1 = [-2 -1 0 1 2]./(10*T) | |
22 % - 'SECOND' perform the second derivative using the | |
23 % coefficients vector d2 = [2 -1 -2 -1 2]./(7*T^2) | |
24 % | |
25 % NOTE1: T is the sampling period | |
26 % NOTE2: The default option for 'ORDER' is 'SECOND' | |
27 % | |
28 % | |
29 % | |
30 % OUTPUTS: | |
31 % - Deriv is the resulting Ao after the operation defined by the | |
32 % input parameters | |
33 % | |
34 % REFERENCES: | |
35 % [1] L. Carbone et al., Physical Review D 75, 042001 (2007) | |
36 % | |
37 % VERSION: $Id: ltpda_parfit_derivative.m,v 1.1 2008/04/24 16:13:12 luigi Exp $ | |
38 % | |
39 % HISTORY: 18-03-2008 L Ferraioli | |
40 % Creation | |
41 % | |
42 % The following call returns a parameter list object that contains the | |
43 % default parameter values: | |
44 % | |
45 % >> pl = ltpda_parfit_derivative('Params') | |
46 % | |
47 % The following call returns a string that contains the routine CVS version: | |
48 % | |
49 % >> version = ltpda_parfit_derivative('Version') | |
50 % | |
51 % The following call returns a string that contains the routine category: | |
52 % | |
53 % >> category = ltpda_parfit_derivative('Category') | |
54 % | |
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
56 | |
57 | |
58 | |
59 %% Standard history variables | |
60 | |
61 ALGONAME = mfilename; | |
62 VERSION = '$Id: ltpda_parfit_derivative.m,v 1.1 2008/04/24 16:13:12 luigi Exp $'; | |
63 CATEGORY = 'Signal Processing'; | |
64 | |
65 %% Check if this is a call for parameters, the CVS version string | |
66 % or the method category | |
67 if nargin == 1 && ischar(varargin{1}) | |
68 in = char(varargin{1}); | |
69 if strcmpi(in, 'Params') | |
70 varargout{1} = getDefaultPL(); | |
71 return | |
72 elseif strcmpi(in, 'Version') | |
73 varargout{1} = VERSION; | |
74 return | |
75 elseif strcmpi(in, 'Category') | |
76 varargout{1} = CATEGORY; | |
77 return | |
78 end | |
79 end | |
80 | |
81 %% Collect input ao's, plist's and ao variable names | |
82 | |
83 in_names = {}; | |
84 | |
85 for ii = 1:nargin | |
86 in_names{end+1} = inputname(ii); % Collect the inputs names | |
87 end | |
88 | |
89 [as, pl, invars] = collect_inputs(varargin, in_names); | |
90 | |
91 % produce one parameter list | |
92 if isa(pl, 'plist') | |
93 pl = combine(pl, getDefaultPL()); | |
94 else | |
95 pl = getDefaultPL(); | |
96 end | |
97 | |
98 %% Initialize outputs | |
99 bs = []; | |
100 | |
101 %% Go through analysis objects | |
102 | |
103 % Assigning coefficients values based on the input options | |
104 switch find(pl, 'ORDER') | |
105 case 'ZERO' | |
106 Coeffs = [-3 12 17 12 -3]./35; | |
107 case 'FIRST' | |
108 Coeffs = [-2 -1 0 1 2]./10; | |
109 case 'SECOND' | |
110 Coeffs = [2 -1 -2 -1 2]./7; | |
111 end | |
112 | |
113 for jj = 1:numel(as) | |
114 | |
115 a = as(jj); | |
116 phi = a.data.y; | |
117 fs = get(a, 'fs'); | |
118 T = 1/fs; | |
119 | |
120 %% Building vectors for calculation | |
121 phi_temp = [phi(1);phi(1);phi(1);phi(1);phi;phi(end);phi(end);phi(end);phi(end)]; | |
122 | |
123 % Switching between the input options | |
124 switch find(pl, 'ORDER') | |
125 case 'ZERO' | |
126 Deriv = (Coeffs(1)*phi_temp(1:end-4) + Coeffs(2)*phi_temp(2:end-3) + Coeffs(3)*phi_temp(3:end-2) + Coeffs(4)*phi_temp(4:end-1) + Coeffs(5)*phi_temp(5:end)); | |
127 Deriv = Deriv(3:end-2); | |
128 case 'FIRST' | |
129 Deriv = (1/T).*(Coeffs(1)*phi_temp(1:end-4) + Coeffs(2)*phi_temp(2:end-3) + Coeffs(3)*phi_temp(3:end-2) + Coeffs(4)*phi_temp(4:end-1) + Coeffs(5)*phi_temp(5:end)); | |
130 Deriv = Deriv(3:end-2); | |
131 case 'SECOND' | |
132 Deriv = (1/T^2).*(Coeffs(1)*phi_temp(1:end-4) + Coeffs(2)*phi_temp(2:end-3) + Coeffs(3)*phi_temp(3:end-2) + Coeffs(4)*phi_temp(4:end-1) + Coeffs(5)*phi_temp(5:end)); | |
133 Deriv = Deriv(3:end-2); | |
134 end | |
135 | |
136 %% Building output Aos | |
137 | |
138 % Creating new time series data | |
139 Deriv = tsdata(Deriv,fs); | |
140 | |
141 Deriv = set(Deriv, 'name', ... | |
142 sprintf('ltpda_parfit_derivative(%s)', a.data.name), ... | |
143 'xunits', a.data.xunits, 'yunits', 'm/s^2'); | |
144 | |
145 % make new history objects | |
146 h = history(ALGONAME, VERSION, pl, a.hist); | |
147 h = set(h, 'invars', invars); | |
148 | |
149 % make output analysis objects | |
150 b = ao(Deriv, h); | |
151 clear Deriv | |
152 | |
153 % name, mfilename, description for these objects | |
154 b = setnh(b, 'name', sprintf('ltpda_parfit_derivative(%s)', invars{jj}),... | |
155 'description', find(pl,'description')); | |
156 | |
157 %% Output the data | |
158 | |
159 bs = [bs b]; | |
160 clear a b | |
161 | |
162 end | |
163 | |
164 %% Reshape the ouput to the same size of the input | |
165 varargout{1} = reshape(bs, size(as)); | |
166 | |
167 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
168 % | |
169 % FUNCTION: getDefaultPL | |
170 % | |
171 % DESCRIPTION: Get default params | |
172 % | |
173 % HISTORY: 01-02-2008 M Hueller | |
174 % Creation | |
175 % | |
176 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
177 function plo = getDefaultPL() | |
178 | |
179 plo = plist('NAME', 'ltpda_parfit_derivative', 'ORDER', 'SECOND', ... | |
180 'DESCRIPTION','Parabolic Fit Derivative Method'); | |
181 | |
182 | |
183 % END | |
184 | |
185 | |
186 | |
187 |