Home > classes > @ao > upsample.m

upsample

PURPOSE ^

UPSAMPLE overloads upsample function for AOs.

SYNOPSIS ^

function bs = upsample(varargin)

DESCRIPTION ^

 UPSAMPLE overloads upsample function for AOs.

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

 DESCRIPTION: UPSAMPLE overloads upsample function for AOs.

              A signal at sample rate fs is upsampled by inserting N-1 zeros between the
              input samples.

 CALL:        b = upsample(a, pl)

 Parameters: 'N'     - specify the desired upsample rate.
             'phase' - specify an initial phase in range [0, N-1].

 VERSION:     $Id: upsample.m,v 1.5 2008/03/17 06:35:19 mauro Exp $

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

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

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

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

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

 >> category = upsample(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 = upsample(varargin)
0002 % UPSAMPLE overloads upsample function for AOs.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: UPSAMPLE overloads upsample function for AOs.
0007 %
0008 %              A signal at sample rate fs is upsampled by inserting N-1 zeros between the
0009 %              input samples.
0010 %
0011 % CALL:        b = upsample(a, pl)
0012 %
0013 % Parameters: 'N'     - specify the desired upsample rate.
0014 %             'phase' - specify an initial phase in range [0, N-1].
0015 %
0016 % VERSION:     $Id: upsample.m,v 1.5 2008/03/17 06:35:19 mauro Exp $
0017 %
0018 % The following call returns a parameter list object that contains the
0019 % default parameter values:
0020 %
0021 % >> pl = upsample(ao, 'Params')
0022 %
0023 % The following call returns a string that contains the routine CVS version:
0024 %
0025 % >> version = upsample(ao,'Version')
0026 %
0027 % The following call returns a string that contains the routine category:
0028 %
0029 % >> category = upsample(ao,'Category')
0030 %
0031 % HISTORY: 19-03-07 M Hewitson
0032 %             Creation
0033 %
0034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0035 
0036 ALGONAME = mfilename;
0037 VERSION  = '$Id: upsample.m,v 1.5 2008/03/17 06:35:19 mauro Exp $';
0038 CATEGORY = 'Signal Processing';
0039 
0040 bs       = [];
0041 
0042 %% Check if this is a call for parameters
0043 if nargin == 2
0044   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0045     in = char(varargin{2});
0046     if strcmp(in, 'Params')
0047       bs = getDefaultPL();
0048       return
0049     elseif strcmp(in, 'Version')
0050       bs = VERSION;
0051       return
0052         elseif strcmp(in, 'Category')
0053     bs = CATEGORY;
0054     return
0055     end
0056   end
0057 end
0058 
0059 VERSION  = '$Id: upsample.m,v 1.5 2008/03/17 06:35:19 mauro Exp $';
0060 
0061 % Collect input ao's, plist's and ao variable names
0062 in_names = {};
0063 for ii = 1:nargin
0064   in_names{end+1} = inputname(ii);
0065 end
0066 [as, pl, invars] = collect_inputs(varargin, in_names);
0067 
0068 if isempty(pl)
0069   error('### Please give a plist with a parameter ''N''.');
0070 end
0071 
0072 % Get output sample rate
0073 Nup = find(pl, 'N');
0074 if isempty(Nup)
0075   error('### Please give a plist with a parameter ''N''.');
0076 end
0077 % Get initial phase
0078 phase = find(pl, 'phase');
0079 if isempty(phase)
0080   phase = 0;
0081 end
0082 
0083 for j=1:numel(as)
0084 
0085   d  = as(j).data;
0086 
0087   % upsample y
0088   y = upsample(d.y, floor(Nup), phase);
0089 
0090   % make new output tsdata
0091   do = tsdata(y, Nup*d.fs);
0092   d = set(d, 'x', do.x);
0093   d = set(d, 'y', do.y);
0094   d = set(d, 'fs', do.fs);
0095 
0096   %--------- create output AO
0097 
0098   % make a new history object
0099   h = history(ALGONAME, VERSION, pl, as(j).hist);
0100   h = set(h, 'invars', invars);
0101 
0102   % make output analysis object
0103   b = ao(d, h);
0104   b = setnh(b, 'name', sprintf('upsample(%s)', invars{j}));
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('N', 1, ...
0117   'phase', 0);
0118 
0119 % END

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003