Home > classes > @ao > resample.m

resample

PURPOSE ^

RESAMPLE overloads resample function for AOs.

SYNOPSIS ^

function b = resample(varargin)

DESCRIPTION ^

 RESAMPLE overloads resample function for AOs.

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

 DESCRIPTION: RESAMPLE overloads resample function for AOs.

 CALL:        b = resample(a, pl)

 Parameters: 'fsout' - specify the desired output sample rate

 VERSION:     $Id: resample.m,v 1.6 2007/06/22 08:32:49 ingo Exp $

 The following call returns a parameter list object that contains the
 default parameter values:

 >> pl = resample(ao, 'Params')

 HISTORY: 19-03-07 M Hewitson
             Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function b = resample(varargin)
0002 % RESAMPLE overloads resample function for AOs.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: RESAMPLE overloads resample function for AOs.
0007 %
0008 % CALL:        b = resample(a, pl)
0009 %
0010 % Parameters: 'fsout' - specify the desired output sample rate
0011 %
0012 % VERSION:     $Id: resample.m,v 1.6 2007/06/22 08:32:49 ingo Exp $
0013 %
0014 % The following call returns a parameter list object that contains the
0015 % default parameter values:
0016 %
0017 % >> pl = resample(ao, 'Params')
0018 %
0019 % HISTORY: 19-03-07 M Hewitson
0020 %             Creation
0021 %
0022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0023 
0024 %% Check if this is a call for parameters
0025 if nargin == 2
0026   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0027     in = char(varargin{2});
0028     if strcmp(in, 'Params')
0029       b = getDefaultPL();
0030       return
0031     end
0032   end
0033 end
0034 
0035 ALGONAME = mfilename;
0036 VERSION  = '$Id: resample.m,v 1.6 2007/06/22 08:32:49 ingo Exp $';
0037 
0038 %% capture input variables
0039 invars = {};
0040 as = [];
0041 pl = [];
0042 for j=1:nargin
0043   a = varargin{j};
0044   if isa(a, 'ao')
0045     d = a.data;
0046     if isa(d, 'tsdata')
0047       as = [as a];
0048       invars = [invars cellstr(inputname(j))];
0049     else
0050       warning('!!! ignoring non-time-series AO.');
0051     end
0052   end
0053   if isa(a, 'plist')
0054     pl = a;
0055   end
0056 end
0057 
0058 if isempty(pl)
0059   error('### Please give a plist with a parameter ''fsout''.');
0060 end
0061 
0062 fsout = find(pl, 'fsout');
0063 if isempty(fsout)
0064   error('### Please give a plist with a parameter ''fsout''.');
0065 end
0066 
0067 na = length(as);
0068 for j=1:na
0069 
0070   a  = as(j);
0071   d  = a.data;
0072   x  = d.x;
0073   fs = d.fs;
0074 
0075   % resample x
0076   y = resample(x, fsout, fs);
0077 
0078   % make new output tsdata
0079   do = tsdata(y, fsout);
0080   d = set(d, 't', do.t);
0081   d = set(d, 'x', do.x);
0082   d = set(d, 'fs', do.fs);
0083 
0084   %--------- create output AO
0085 
0086   % make a new history object
0087   h = history(ALGONAME, VERSION, pl, a.hist);
0088   h = set(h, 'invars', invars);
0089 
0090   % get names for output
0091   if isempty(char(invars{1}))
0092     n1 = a.name;
0093   else
0094     n1 = char(invars{1});
0095   end
0096 
0097   % make output analysis object
0098   b = ao(d, h);
0099   b = set(b, 'name', sprintf('resample(%s)', n1));
0100 
0101 end
0102 
0103 % Get default params
0104 function plo = getDefaultPL()
0105 
0106 disp('* creating default plist...');
0107 plo = plist();
0108 plo = append(plo, param('fsout', ''));
0109 disp('* done.');
0110 
0111 % END

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003