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.2 2007/11/26 14:48:13 ingo Exp $

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

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

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