Home > classes > @ao > resample.m

resample

PURPOSE ^

RESAMPLE overloads resample function for AOs.

SYNOPSIS ^

function bs = 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.8 2007/10/29 18:15:37 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 bs = 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.8 2007/10/29 18:15:37 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 VERSION = '$Id: resample.m,v 1.8 2007/10/29 18:15:37 ingo Exp $';
0025 
0026 %% Check if this is a call for parameters
0027 if nargin == 2
0028   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0029     in = char(varargin{2});
0030     if strcmp(in, 'Params')
0031       bs = getDefaultPL();
0032       return
0033     elseif strcmp(in, 'Version')
0034       bs = VERSION;
0035       return
0036     end
0037   end
0038 end
0039 
0040 ALGONAME = mfilename;
0041 VERSION  = '$Id: resample.m,v 1.8 2007/10/29 18:15:37 ingo Exp $';
0042 
0043 %% capture input variables
0044 invars = {};
0045 as = [];
0046 bs = [];
0047 pl = [];
0048 for j=1:nargin
0049   a = varargin{j};
0050   if isa(a, 'ao')
0051     d = a.data;
0052     if isa(d, 'tsdata')
0053       as = [as a];
0054       invars = [invars cellstr(inputname(j))];
0055     else
0056       warning('!!! ignoring non-time-series AO.');
0057     end
0058   end
0059   if isa(a, 'plist')
0060     pl = a;
0061   end
0062 end
0063 
0064 if isempty(pl)
0065   error('### Please give a plist with a parameter ''fsout''.');
0066 end
0067 
0068 fsout = find(pl, 'fsout');
0069 if isempty(fsout)
0070   error('### Please give a plist with a parameter ''fsout''.');
0071 end
0072 
0073 for j=1:numel(as)
0074 
0075   a  = as(j);
0076   d  = a.data;
0077   x  = d.x;
0078   fs = d.fs;
0079 
0080   % resample x
0081   y = resample(x, fsout, fs);
0082 
0083   % make new output tsdata
0084   do = tsdata(y, fsout);
0085   d = set(d, 't', do.t);
0086   d = set(d, 'x', do.x);
0087   d = set(d, 'fs', do.fs);
0088 
0089   %--------- create output AO
0090 
0091   % make a new history object
0092   h = history(ALGONAME, VERSION, pl, a.hist);
0093   h = set(h, 'invars', invars);
0094 
0095   % get names for output
0096   if isempty(char(invars{1}))
0097     n1 = a.name;
0098   else
0099     n1 = char(invars{1});
0100   end
0101 
0102   % make output analysis object
0103   b = ao(d, h);
0104   b = set(b, 'name', sprintf('resample(%s)', n1));
0105 
0106   bs = [bs b];
0107 
0108 end
0109 
0110 % Reshape the ouput to the same size of the input
0111 bs = reshape(bs, size(as));
0112 
0113 % Get default params
0114 function plo = getDefaultPL()
0115 
0116 plo = plist();
0117 plo = append(plo, param('fsout', 100));
0118 
0119 % END

Generated on Fri 02-Nov-2007 19:39:27 by m2html © 2003