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.html,v 1.14 2008/03/31 10:27:33 hewitson Exp $

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

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

 The following call returns a string that contains the routine CVS version:

 >> version = resample(ao,'Version')

 The following call returns a string that contains the routine category:

 >> category = resample(ao,'Category')

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

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003