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.3 2008/02/12 10:11:13 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.3 2008/02/12 10:11:13 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.3 2008/02/12 10:11:13 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.3 2008/02/12 10:11:13 mauro Exp $';
0060 
0061 %% capture input variables
0062 invars = {};
0063 as     = [];
0064 pl     = [];
0065 
0066 for j=1:nargin
0067   a = varargin{j};
0068   if isa(a, 'ao')
0069     d = a.data;
0070     if isa(d, 'tsdata')
0071       as = [as a];
0072 
0073       ao_name = inputname(j);
0074       if isempty(ao_name)
0075         ao_name = 'no_ao_name';
0076       end
0077 
0078       % Memorise the variable name of the corresponding analysis object.
0079       % If the ao is an array or vector add the index to the variable name
0080       if numel(varargin{j}) == 1
0081         invars{end+1} = ao_name;
0082       else
0083         for ii=1:numel(varargin{j})
0084           [I,J] = ind2sub(size(varargin{j}),ii);
0085           invars{end+1} = sprintf('%s(%d,%d)', ao_name, I, J);
0086         end
0087       end
0088     else
0089       warning('!!! ignoring non-time-series AO.');
0090     end
0091   end
0092   if isa(a, 'plist')
0093     pl = a;
0094   end
0095 end
0096 
0097 
0098 if isempty(pl)
0099   error('### Please give a plist with a parameter ''N''.');
0100 end
0101 
0102 % Get output sample rate
0103 Nup = find(pl, 'N');
0104 if isempty(Nup)
0105   error('### Please give a plist with a parameter ''N''.');
0106 end
0107 % Get initial phase
0108 phase = find(pl, 'phase');
0109 if isempty(phase)
0110   phase = 0;
0111 end
0112 
0113 for j=1:numel(as)
0114 
0115   d  = as(j).data;
0116 
0117   % upsample y
0118   y = upsample(d.y, floor(Nup), phase);
0119 
0120   % make new output tsdata
0121   do = tsdata(y, Nup*d.fs);
0122   d = set(d, 'x', do.x);
0123   d = set(d, 'y', do.y);
0124   d = set(d, 'fs', do.fs);
0125 
0126   %--------- create output AO
0127 
0128   % make a new history object
0129   h = history(ALGONAME, VERSION, pl, as(j).hist);
0130   h = set(h, 'invars', invars);
0131 
0132   % make output analysis object
0133   b = ao(d, h);
0134   b = setnh(b, 'name', sprintf('upsample(%s)', invars{j}));
0135 
0136   bs = [bs b];
0137 
0138 end
0139 
0140 % Reshape the ouput to the same size of the input
0141 bs = reshape(bs, size(as));
0142 
0143 % Get default params
0144 function plo = getDefaultPL()
0145 
0146 plo = plist();
0147 plo = append(plo, param('N', 1));
0148 plo = append(plo, param('phase', 0));
0149 
0150 % END

Generated on Tue 26-Feb-2008 10:52:52 by m2html © 2003