Mercurial > hg > ltpda
comparison m-toolbox/classes/@smodel/convol_integral.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 % CONVOL_INTEGRAL implements the convolution integral for smodel objects. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: CONVOL_INTEGRAL implements the convolution integral to evaluate | |
5 % the time-domain response of smodel objects whose impulse response is h(t), | |
6 % to input signals in_signal(t): | |
7 % o(t) = int(h(t1) * in_signal(t-t1), t1=0..t) (1) | |
8 % | |
9 % CALL: out = convol_integral(mdl, sig) | |
10 % | |
11 % INPUTS: mdl smodel with the time-domain impulse response of | |
12 % the system | |
13 % sig smodel with the time-domain applied signal | |
14 % | |
15 % OUTPUTS: out smodel with the time-domain response of the system | |
16 % | |
17 % NOTE: Eq (1) assumes that in_signal(t<0) = 0 | |
18 % | |
19 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'convol_integral')">Parameters Description</a> | |
20 % | |
21 % VERSION: $Id: convol_integral.m,v 1.8 2011/04/08 08:56:29 hewitson Exp $ | |
22 % | |
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
24 | |
25 function varargout = convol_integral(varargin) | |
26 | |
27 % Check if this is a call for parameters | |
28 if utils.helper.isinfocall(varargin{:}) | |
29 varargout{1} = getInfo(varargin{3}); | |
30 return | |
31 end | |
32 | |
33 % Check if the method was called by another method | |
34 callerIsMethod = utils.helper.callerIsMethod; | |
35 | |
36 % Collect input variable names | |
37 in_names = cell(size(varargin)); | |
38 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
39 | |
40 % Collect all input smodels and plists | |
41 [mdls, smodel_invars, rest] = utils.helper.collect_objects(varargin(:), 'smodel', in_names); | |
42 pl = utils.helper.collect_objects(rest(:), 'plist'); | |
43 | |
44 % Merge with default plist | |
45 usepl = parse(pl, getDefaultPlist()); | |
46 | |
47 % Check for the number of inputs | |
48 if numel(mdls) ~= 2 | |
49 error('### Please provide an smodel with the system impulse response and an smodel with the signal') | |
50 else | |
51 mdl = copy(mdls(1), false); | |
52 sig = copy(mdls(2), false); | |
53 end | |
54 | |
55 % Replace .* like expressions with * to allow symbolic evaluation | |
56 h = utils.prog.convertComString(mdl.expr.s, 'ToSymbolic'); | |
57 in_signal = utils.prog.convertComString(sig.expr.s, 'ToSymbolic'); | |
58 | |
59 % Go symbolic now | |
60 syms t t1 | |
61 % Input Signal | |
62 in_signal_t1 = sym(regexprep(in_signal,'\<t\>','t1')); | |
63 | |
64 % System impulse response | |
65 h_t_t1 = sym(regexprep(h,'\<t\>','(t-t1)')); | |
66 | |
67 % Calculate the system response via convolution (linear system) | |
68 out_s = simplify(int([h_t_t1 * in_signal_t1], t1, 0, t)); | |
69 | |
70 % Go back to string after calcuation | |
71 out.expr.s = utils.prog.mup2mat(out_s); | |
72 | |
73 % Replace * like expressions with .* to allow numeric evaluation | |
74 out.expr.s = utils.prog.convertComString(out.expr.s , 'FromSymbolic'); | |
75 | |
76 % Set variables, units | |
77 out.setXvar(sig.xvar); | |
78 out.setXunits(sig.xunits); | |
79 out.setYunits(mdl.yunits * sig.yunits); | |
80 | |
81 % Add history step | |
82 out.addHistory(getInfo('None'), usepl, [smodel_invars(:)], [mdls(:).hist]); | |
83 | |
84 % Set output | |
85 | |
86 % Single output | |
87 varargout{1} = out; | |
88 end | |
89 | |
90 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
91 % Local Functions % | |
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
93 | |
94 %-------------------------------------------------------------------------- | |
95 % Get Info Object | |
96 %-------------------------------------------------------------------------- | |
97 function ii = getInfo(varargin) | |
98 | |
99 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
100 sets = {}; | |
101 pls = []; | |
102 else | |
103 sets = {'Default'}; | |
104 pls = getDefaultPlist; | |
105 end | |
106 % Build info object | |
107 ii = minfo(mfilename, 'smodel', 'ltpda', utils.const.categories.op, '$Id: convol_integral.m,v 1.8 2011/04/08 08:56:29 hewitson Exp $', sets, pls); | |
108 ii.setArgsmin(2); | |
109 end | |
110 | |
111 %-------------------------------------------------------------------------- | |
112 % Get Default Plist | |
113 %-------------------------------------------------------------------------- | |
114 function plout = getDefaultPlist() | |
115 persistent pl; | |
116 if ~exist('pl', 'var') || isempty(pl) | |
117 pl = buildplist(); | |
118 end | |
119 plout = pl; | |
120 end | |
121 | |
122 function pl = buildplist() | |
123 pl = plist.EMPTY_PLIST; | |
124 end | |
125 | |
126 | |
127 | |
128 |