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.13 2007/11/26 14:48:13 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.13 2007/11/26 14:48:13 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.13 2007/11/26 14:48:13 ingo Exp $';
0025 bs      = [];
0026 
0027 %% Check if this is a call for parameters
0028 if nargin == 2
0029   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0030     in = char(varargin{2});
0031     if strcmp(in, 'Params')
0032       bs = getDefaultPL();
0033       return
0034     elseif strcmp(in, 'Version')
0035       bs = VERSION;
0036       return
0037     end
0038   end
0039 end
0040 
0041 ALGONAME = mfilename;
0042 VERSION  = '$Id: resample.m,v 1.13 2007/11/26 14:48:13 ingo Exp $';
0043 
0044 %% capture input variables
0045 invars = {};
0046 as     = [];
0047 pl     = [];
0048 
0049 for j=1:nargin
0050   a = varargin{j};
0051   if isa(a, 'ao')
0052     d = a.data;
0053     if isa(d, 'tsdata')
0054       as = [as a];
0055 
0056       ao_name = inputname(j);
0057       if isempty(ao_name)
0058         ao_name = 'no_ao_name';
0059       end
0060 
0061       % Memorise the variable name of the corresponding analysis object.
0062       % If the ao is an array or vector add the index to the variable name
0063       if numel(varargin{j}) == 1
0064         invars{end+1} = ao_name;
0065       else
0066         for ii=1:numel(varargin{j})
0067           [I,J] = ind2sub(size(varargin{j}),ii);
0068           invars{end+1} = sprintf('%s(%d,%d)', ao_name, I, J);
0069         end
0070       end
0071     else
0072       warning('!!! ignoring non-time-series AO.');
0073     end
0074   end
0075   if isa(a, 'plist')
0076     pl = a;
0077   end
0078 end
0079 
0080 
0081 if isempty(pl)
0082   error('### Please give a plist with a parameter ''fsout''.');
0083 end
0084 
0085 % Get output sample rate
0086 fsout = find(pl, 'fsout');
0087 if isempty(fsout)
0088   error('### Please give a plist with a parameter ''fsout''.');
0089 end
0090 
0091 % Get a filter if specified
0092 filt = find(pl, 'filter');
0093 
0094 for j=1:numel(as)
0095 
0096   d  = as(j).data;
0097 
0098   % resample y
0099   if isempty(filt)
0100     [y,b] = resample(d.y, fsout, d.fs);
0101   else
0102     [p,q] = rat( fsout/d.fs, 1e-12 );
0103     b = p*filt.a;
0104     y = resample(d.y, fsout, d.fs, b);
0105   end
0106 
0107 
0108   % make new output tsdata
0109   do = tsdata(y, fsout);
0110   d = set(d, 'x', do.x);
0111   d = set(d, 'y', do.y);
0112   d = set(d, 'fs', do.fs);
0113 
0114   %--------- create output AO
0115 
0116   % make a new history object
0117   h = history(ALGONAME, VERSION, pl, as(j).hist);
0118   h = set(h, 'invars', invars);
0119 
0120   % make output analysis object
0121   b = ao(d, h);
0122   b = setnh(b, 'name', sprintf('resample(%s)', invars{j}));
0123 
0124   bs = [bs b];
0125 
0126 end
0127 
0128 % Reshape the ouput to the same size of the input
0129 bs = reshape(bs, size(as));
0130 
0131 % Get default params
0132 function plo = getDefaultPL()
0133 
0134 plo = plist();
0135 plo = append(plo, param('fsout', 100));
0136 
0137 % END

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003