changeset 2952:f76319f63fa2 octave-forge

Add upsample; correct documentation; index the new functions.
author pkienzle
date Sat, 20 Jan 2007 18:31:16 +0000
parents 8c158bac3f98
children c1b64f055b07
files main/signal/INDEX main/signal/inst/downsample.m main/signal/inst/upsample.m
diffstat 3 files changed, 38 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/main/signal/INDEX	Sat Jan 20 18:21:17 2007 +0000
+++ b/main/signal/INDEX	Sat Jan 20 18:31:16 2007 +0000
@@ -133,6 +133,8 @@
 Sample rate change
  decimate 
  interp 
+ downsample
+ upsample
  resample 
  upfirdn 
 Compatibility
--- a/main/signal/inst/downsample.m	Sat Jan 20 18:21:17 2007 +0000
+++ b/main/signal/inst/downsample.m	Sat Jan 20 18:31:16 2007 +0000
@@ -1,6 +1,6 @@
 ## -*- texinfo -*-
 ## @deftypefn {Function File} @var{y} = downsample(@var{x},@var{n})
-## Downsample the signal, selecting every nth element.  Every @var{x}
+## Downsample the signal, selecting every nth element.  If @var{x}
 ## is a matrix, downsample every column.
 ##
 ## For most signals you will want to use decimate() instead since
@@ -10,7 +10,7 @@
 ## @deftypefnx {Function File} @var{y} = downsample(@var{x},@var{n},@var{phase})
 ## Select every nth element starting at sample @var{phase}.
 ## @end deftypefn
-## @seealso{decimate, interp, resample, upfirdn}
+## @seealso{decimate, interp, resample, upfirdn, upsample}
 
 ## Author: Paul Kienzle
 ## This function is public domain
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/signal/inst/upsample.m	Sat Jan 20 18:31:16 2007 +0000
@@ -0,0 +1,34 @@
+## -*- texinfo -*-
+## @deftypefn {Function File} @var{y} = upsample(@var{x},@var{n})
+## Upsample the signal, inserting n-1 zeros between every element.  
+## If @var{x} is a matrix, upsample every column.
+##
+## @deftypefnx {Function File} @var{y} = upsample(@var{x},@var{n},@var{phase})
+## Control the position of the inserted sample in the block of n zeros.
+## @end deftypefn
+## @seealso{decimate, downsample, interp, resample, upfirdn}
+
+## Author: Paul Kienzle
+## This function is public domain
+
+function y = upsample(x,n,phase)
+  if nargin<2 || nargin>3, usage('upsample(x,n,[phase]'); end
+  if nargin==2, phase = 1; end
+
+  [nr,nc] = size(x);
+  if any([nr,nc]==1),
+    y = zeros(n*nr*nc,1);
+    y(phase:n:end) = x;
+    if nr==1, y = y.'; end
+  else
+    y = zeros(n*nr,nc);
+    y(phase:n:end,:) = x;
+  end
+end
+
+%!assert(upsample([1,3,5],2),[1,0,3,0,5,0]);
+%!assert(upsample([1;3;5],2),[1;0;3;0;5;0]);
+%!assert(upsample([1,2;5,6;9,10],2),[1,2;0,0;5,6;0,0;9,10;0,0]);
+%!assert(upsample([2,4],2,2),[0,2,0,4]);
+%!assert(upsample([3,4;7,8],2,2),[0,0;3,4;0,0;7,8]);
+