


DFT computes the DFT of the input time-series at the requested frequencies.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DESCRIPTION: DFT computes the DFT of the input time-series at the requested
frequencies.
CALL: b = dft(a, pl)
PARAMETERS:
'f' - vector of frequencies at which to compute the DFT.
[default: linspace(1/ndata,fs/2,ndata/2+1)]
M-FILE INFO: Get information about this methods by calling
>> ao.getInfo('dft')
Get information about a specified set-plist by calling:
>> ao.getInfo('dft', 'None')
VERSION: $Id: dft.m,v 1.13 2008/09/05 14:14:11 hewitson Exp $
HISTORY: 25-04-08 M Hewitson
Creation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


0001 % DFT computes the DFT of the input time-series at the requested frequencies. 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: DFT computes the DFT of the input time-series at the requested 0005 % frequencies. 0006 % 0007 % CALL: b = dft(a, pl) 0008 % 0009 % PARAMETERS: 0010 % 'f' - vector of frequencies at which to compute the DFT. 0011 % [default: linspace(1/ndata,fs/2,ndata/2+1)] 0012 % 0013 % M-FILE INFO: Get information about this methods by calling 0014 % >> ao.getInfo('dft') 0015 % 0016 % Get information about a specified set-plist by calling: 0017 % >> ao.getInfo('dft', 'None') 0018 % 0019 % VERSION: $Id: dft.m,v 1.13 2008/09/05 14:14:11 hewitson Exp $ 0020 % 0021 % HISTORY: 25-04-08 M Hewitson 0022 % Creation 0023 % 0024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0025 0026 function varargout = dft(varargin) 0027 0028 % Check if this is a call for parameters 0029 if utils.helper.isinfocall(varargin{:}) 0030 varargout{1} = getInfo(varargin{3}); 0031 return 0032 end 0033 0034 import utils.const.* 0035 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename); 0036 0037 % Collect input variable names 0038 in_names = cell(size(varargin)); 0039 for ii = 1:nargin,in_names{ii} = inputname(ii);end 0040 0041 % Collect all AOs 0042 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); 0043 [pl, pl_invars] = utils.helper.collect_objects(varargin(:), 'plist', in_names); 0044 0045 % Make copies or handles to inputs 0046 bs = copy(as, nargout); 0047 0048 % Combine plists 0049 pl = combine(pl, getDefaultPlist); 0050 0051 % Loop over input AOs 0052 for j=1:length(bs) 0053 if ~isa(bs(j).data, 'tsdata') 0054 warning('!!! The DFT can only be computed on input time-series. Skipping AO %s', ao_invars{j}); 0055 else 0056 0057 % Extract necessary parameters 0058 f = find(pl, 'f'); 0059 0060 % Compute f if necessary 0061 if f == -1 0062 f = linspace(0, bs(j).data.fs/2, length(bs(j).data.getY)/2+1); 0063 end 0064 0065 % Compute DFT 0066 fs = bs(j).data.fs; 0067 N = length(bs(j).data.getY); 0068 J = -2*pi*1i.*[0:N-1]/fs; 0069 dft = zeros(size(f)); 0070 for kk = 1:length(f) 0071 dft(kk) = exp(f(kk)*J)*bs(j).data.getY; 0072 end 0073 0074 % Make output fsdata AO 0075 yunits = bs(j).data.yunits; 0076 % Keep the data shape of the input AO 0077 if size(bs(j).data.y,1) ~= 1 0078 f = f.'; 0079 dft = dft.'; 0080 end 0081 bs(j).data = fsdata(f, dft, bs(j).data.fs); 0082 bs(j).setXunits('Hz', 'internal'); 0083 bs(j).setYunits(yunits./unit('Hz'), 'internal'); 0084 % Set name 0085 bs(j).setName(sprintf('dft(%s)', ao_invars{j}), 'internal'); 0086 % Add history 0087 bs(j).addHistory(getInfo, pl, ao_invars(j), bs(j).hist); 0088 end 0089 end 0090 0091 % Set outputs 0092 if nargout > 0 0093 varargout{1} = bs; 0094 end 0095 end 0096 0097 %-------------------------------------------------------------------------- 0098 % Get Info Object 0099 %-------------------------------------------------------------------------- 0100 function ii = getInfo(varargin) 0101 if nargin == 1 && strcmpi(varargin{1}, 'None') 0102 sets = {}; 0103 pls = []; 0104 else 0105 sets = {'Default'}; 0106 pls = getDefaultPlist; 0107 end 0108 % Build info object 0109 ii = minfo(mfilename, 'ao', '', utils.const.categories.sigproc, '$Id: dft.m,v 1.13 2008/09/05 14:14:11 hewitson Exp $', sets, pls); 0110 end 0111 0112 %-------------------------------------------------------------------------- 0113 % Get Default Plist 0114 %-------------------------------------------------------------------------- 0115 function pl = getDefaultPlist() 0116 pl = plist('f', -1); 0117 end 0118 0119