Home > classes > @ao > fft.m

fft

PURPOSE ^

FFT overloads the fft method for Analysis objects.

SYNOPSIS ^

function varargout = fft(varargin)

DESCRIPTION ^

 FFT overloads the fft method for Analysis objects.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: FFT overloads the fft operator for Analysis objects.

 CALL:        b = fft(a, pl)

 PARAMETERS:  'type'  - one or two sided fft [default: 'one']

 M-FILE INFO: Get information about this methods by calling
              >> ao.getInfo('fft')

              Get information about a specified set-plist by calling:
              >> ao.getInfo('fft', 'None')

 VERSION:     $Id: fft.m,v 1.26 2008/09/05 11:05:29 ingo Exp $
 
 HISTORY:     12-03-07 M Hewitson
                 Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % FFT overloads the fft method for Analysis objects.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: FFT overloads the fft operator for Analysis objects.
0005 %
0006 % CALL:        b = fft(a, pl)
0007 %
0008 % PARAMETERS:  'type'  - one or two sided fft [default: 'one']
0009 %
0010 % M-FILE INFO: Get information about this methods by calling
0011 %              >> ao.getInfo('fft')
0012 %
0013 %              Get information about a specified set-plist by calling:
0014 %              >> ao.getInfo('fft', 'None')
0015 %
0016 % VERSION:     $Id: fft.m,v 1.26 2008/09/05 11:05:29 ingo Exp $
0017 %
0018 % HISTORY:     12-03-07 M Hewitson
0019 %                 Creation
0020 %
0021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0022 
0023 function varargout = fft(varargin)
0024   
0025   % Check if this is a call for parameters
0026   if utils.helper.isinfocall(varargin{:})
0027     varargout{1} = getInfo(varargin{3});
0028     return
0029   end
0030   
0031   import utils.const.*
0032   utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0033 
0034   % Collect input variable names
0035   in_names = cell(size(varargin));
0036   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0037 
0038   % Collect all AOs
0039   [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
0040   pl              = utils.helper.collect_objects(varargin(:), 'plist', in_names);
0041 
0042   % Decide on a deep copy or a modify
0043   bs = copy(as, nargout);
0044 
0045   % Combine plists
0046   pl = combine(pl, getDefaultPlist);
0047 
0048   % two-sided or one?
0049   type = find(pl, 'type');
0050 
0051   % Check input analysis object
0052   for j=1:numel(bs)
0053     % Which data type do we have
0054     switch class(bs(j).data)
0055       case {'tsdata', 'cdata', 'xydata'}
0056         % Check we have a sample rate
0057         if strcmp(class(bs(j).data), 'tsdata')
0058           fs     = bs(j).data.fs;
0059           fmin   = 0;
0060           xunits = 'Hz';
0061         else
0062           warning('!!! Data has no sample rate: setting to %g', 2+length(bs(j).data.y));
0063           fs     = 2+length(bs(j).data.y);
0064           fmin   = 1;
0065         end
0066         % make FFT of data
0067         nfft = length(bs(j).data.y);
0068         ft   = fft(bs(j).data.y);
0069         switch type
0070           case 'one'
0071             ft   = ft(1:nfft/2+1);
0072             f    = linspace(fmin, fs/2, length(ft));
0073           case 'two'
0074             ft   = [ft(nfft/2+2:end) ft(1:nfft/2+1)];
0075             f    = linspace(-fs/2, fs/2, length(ft));
0076           otherwise
0077             error('### unknown fft type.');
0078         end
0079         % Make new fsdata object
0080         fsd = fsdata(f, ft, fs);
0081         fsd.setXunits(xunits);
0082         fsd.setYunits(bs(j).data.yunits);
0083         % make output analysis object
0084         bs(j).data = fsd;
0085         bs(j).setName(sprintf('fft(%s)', ao_invars{j}), 'internal');
0086         % Add history
0087         bs(j).addHistory(getInfo, pl, ao_invars(j), bs(j).hist);
0088       otherwise
0089         error('### You can only fft tsdata, cdata, or xydata AOs.');
0090     end
0091   end
0092 
0093   % Set output
0094   if nargout > 0
0095     varargout{1} = bs;
0096   end
0097 end
0098 
0099 %--------------------------------------------------------------------------
0100 % Get Info Object
0101 %--------------------------------------------------------------------------
0102 function ii = getInfo(varargin)
0103   if nargin == 1 && strcmpi(varargin{1}, 'None')
0104     sets = {};
0105     pl   = [];
0106   else
0107     sets = {'Default'};
0108     pl   = getDefaultPlist;
0109   end
0110   % Build info object
0111   ii = minfo(mfilename, 'ao', '', utils.const.categories.sigproc, '$Id: fft.m,v 1.26 2008/09/05 11:05:29 ingo Exp $', sets, pl);
0112 end
0113 
0114 %--------------------------------------------------------------------------
0115 % Get Default Plist
0116 %--------------------------------------------------------------------------
0117 function pl_default = getDefaultPlist()
0118   pl_default = plist('type', 'one');
0119 end
0120 
0121

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003