comparison m-toolbox/classes/@matrix/fftfilt.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 % FFTFILT fft filter for matrix objects
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: FFTFILT fft filter for matrix objects
5 %
6 % CALL: output = fftfilt(input,filter)
7 %
8 % <a href="matlab:utils.helper.displayMethodInfo('matrix', 'fftfilt')">Parameters Description</a>
9 %
10 % VERSION: $Id: fftfilt.m,v 1.16 2011/04/08 08:56:31 hewitson Exp $
11 %
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 function varargout = fftfilt(varargin)
14
15 % utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
16
17 % Check if this is a call for parameters
18 if utils.helper.isinfocall(varargin{:})
19 varargout{1} = getInfo(varargin{3});
20 return
21 end
22
23 % Collect input variable names
24 in_names = cell(size(varargin));
25 for ii = 1:nargin
26 in_names{ii} = inputname(ii);
27 end
28
29 % Collect all smodels and plists
30 % [as, matrix_invars, rest] = utils.helper.collect_objects(varargin(:), 'matrix', in_names);
31 [pl, pl_invars, rest] = utils.helper.collect_objects(varargin(:), 'plist', in_names);
32
33 % Merge with default plist
34 pl = parse(pl, getDefaultPlist);
35
36 % separate data and filter matrices
37 is = varargin{1};
38 filt = varargin{2};
39
40 [rw1,cl1] = size(filt.objs); % size filter
41 [rw2,cl2] = size(is.objs); % size input signals
42 % consistency check
43 if (cl1 ~= rw2)
44 error('!!! Matrices inner dimensions must agree')
45 end
46
47 % init output
48 nobjs = feval(sprintf('%s.initObjectWithSize', class(is.objs(1))), rw1, cl2);
49 os = matrix(nobjs,plist('shape',[rw1,cl2]));
50
51 % get number of Bins for zero padding
52 Npad = find(pl,'Npad');
53 % do row by colum product
54 for kk = 1:rw1
55 for jj = 1:cl2
56 % fix the first element of the sum
57 try % try to do filter
58 tobj = fftfilt_core(copy(is.objs(1,jj),1), copy(filt.objs(kk,1),1), Npad);
59 catch ME % if the input ao is empty, ao/filter output an error and tobj is set to []
60 tobj = [];
61 end
62 for zz = 2:cl1
63 try % try to do filter
64 if isempty(tobj)
65 tobj = fftfilt_core(copy(is.objs(zz,jj),1), copy(filt.objs(kk,zz),1), Npad);
66 else
67 tobj = tobj + fftfilt_core(copy(is.objs(zz,jj),1), copy(filt.objs(kk,zz),1), Npad);
68 end
69 catch ME % if the input ao is empty, ao/filter output an error
70 end
71 end
72 % simplify y units
73 tobj_yu = tobj.yunits;
74 tobj_yu.simplify;
75 tobj.setYunits(tobj_yu);
76 % simplify x units
77 if ~isempty(tobj.xunits)
78 tobj_xu = tobj.xunits;
79 tobj_xu.simplify;
80 tobj.setXunits(tobj_xu);
81 end
82 os.objs(kk,jj) = tobj;
83 end
84 end
85
86 if nargout == 1
87 varargout{1} = os;
88 else
89 error('Set at least one output value')
90 end
91
92 end
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, 'matrix', 'ltpda', utils.const.categories.op, '$Id: fftfilt.m,v 1.16 2011/04/08 08:56:31 hewitson Exp $', sets, pls);
108 ii.setModifier(false);
109 end
110
111 %--------------------------------------------------------------------------
112 % Get Default Plist
113 %--------------------------------------------------------------------------
114 function plout = getDefaultPlist()
115 persistent pl;
116 if exist('pl', 'var')==0 || isempty(pl)
117 pl = buildplist();
118 end
119 plout = pl;
120 end
121
122 function pl = buildplist()
123 pl = plist();
124
125 % Number of bins for zero padding
126 p = param({'Npad', 'Number of bins for zero padding.'}, paramValue.EMPTY_DOUBLE);
127 pl.append(p);
128
129 end