comparison m-toolbox/classes/@ao/dft.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 % DFT computes the DFT of the input time-series at the requested frequencies.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: DFT computes the DFT of the input time-series at the requested
5 % frequencies.
6 %
7 % CALL: b = dft(a, pl)
8 %
9 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'dft')">Parameters Description</a>
10 %
11 % VERSION: $Id: dft.m,v 1.29 2011/04/08 08:56:13 hewitson Exp $
12 %
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
15 function varargout = dft(varargin)
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 import utils.const.*
24 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
25
26 % Collect input variable names
27 in_names = cell(size(varargin));
28 for ii = 1:nargin,in_names{ii} = inputname(ii);end
29
30 % Collect all AOs
31 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
32 [pl, pl_invars] = utils.helper.collect_objects(varargin(:), 'plist', in_names);
33
34 % Make copies or handles to inputs
35 bs = copy(as, nargout);
36
37 % Combine plists
38 pl = parse(pl, getDefaultPlist);
39
40 % Loop over input AOs
41 for j=1:numel(bs)
42 if ~isa(bs(j).data, 'tsdata')
43 warning('!!! The DFT can only be computed on input time-series. Skipping AO %s', ao_invars{j});
44 else
45
46 % Extract necessary parameters
47 f = find(pl, 'f');
48 if isa(f, 'ao') && (isa(f.data, 'fsdata') || isa(f.data, 'xydata'))
49 f = f.data.getX;
50 end
51
52 % Compute f if necessary
53 if f == -1
54 f = linspace(0, bs(j).data.fs/2, length(bs(j).data.getY)/2+1);
55 end
56
57 % Compute DFT
58 fs = bs(j).data.fs;
59 N = length(bs(j).data.getY);
60 J = -2*pi*1i.*[0:N-1]/fs;
61 dft = zeros(size(f));
62 for kk = 1:length(f)
63 dft(kk) = exp(f(kk)*J)*bs(j).data.getY;
64 end
65
66 % Make output fsdata AO
67 yunits = bs(j).data.yunits;
68 % Keep the data shape of the input AO
69 if size(bs(j).data.y,1) ~= 1
70 f = f.';
71 dft = dft.';
72 end
73 bs(j).data = fsdata(f, dft, bs(j).data.fs);
74 bs(j).data.setXunits('Hz');
75 bs(j).data.setYunits(yunits./unit('Hz'));
76 % Set name
77 bs(j).name = sprintf('dft(%s)', ao_invars{j});
78 % Add history
79 bs(j).addHistory(getInfo('None'), pl, ao_invars(j), bs(j).hist);
80 % Clear the errors since they don't make sense anymore
81 clearErrors(bs(j));
82 end
83 end
84
85
86 % Set output
87 if nargout == numel(bs)
88 % List of outputs
89 for ii = 1:numel(bs)
90 varargout{ii} = bs(ii);
91 end
92 else
93 % Single output
94 varargout{1} = bs;
95 end
96 end
97
98 %--------------------------------------------------------------------------
99 % Get Info Object
100 %--------------------------------------------------------------------------
101 function ii = getInfo(varargin)
102 if nargin == 1 && strcmpi(varargin{1}, 'None')
103 sets = {};
104 pls = [];
105 else
106 sets = {'Default'};
107 pls = getDefaultPlist;
108 end
109 % Build info object
110 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: dft.m,v 1.29 2011/04/08 08:56:13 hewitson Exp $', sets, pls);
111 end
112
113 %--------------------------------------------------------------------------
114 % Get Default Plist
115 %--------------------------------------------------------------------------
116
117 function plout = getDefaultPlist()
118 persistent pl;
119 if exist('pl', 'var')==0 || isempty(pl)
120 pl = buildplist();
121 end
122 plout = pl;
123 end
124
125 function pl = buildplist()
126 pl = plist({'f', ['The vector of frequencies at which to compute the DFT <br>or an AO ' ...
127 'where the x-axis is taken for the frequency values.']}, paramValue.DOUBLE_VALUE(-1));
128 end
129
130