From: <ad...@us...> - 2008-07-30 08:47:40
|
Revision: 5206 http://octave.svn.sourceforge.net/octave/?rev=5206&view=rev Author: adb014 Date: 2008-07-30 08:47:50 +0000 (Wed, 30 Jul 2008) Log Message: ----------- Add 1 to phase in upsample/downsample for matlab compatiblity (For Jonathan Coker) Modified Paths: -------------- trunk/octave-forge/main/signal/inst/downsample.m trunk/octave-forge/main/signal/inst/upsample.m Modified: trunk/octave-forge/main/signal/inst/downsample.m =================================================================== --- trunk/octave-forge/main/signal/inst/downsample.m 2008-07-30 07:59:40 UTC (rev 5205) +++ trunk/octave-forge/main/signal/inst/downsample.m 2008-07-30 08:47:50 UTC (rev 5206) @@ -7,8 +7,8 @@ ## it prefilters the high frequency components of the signal and ## avoids aliasing effects. ## -## @deftypefnx {Function File} @var{y} = downsample(@var{x},@var{n},@var{phase}) -## Select every nth element starting at sample @var{phase}. +## @deftypefnx {Function File} @var{y} = downsample(@var{x},@var{n},@var{offset}) +## Select every nth element starting at sample @var{offset}. ## @end deftypefn ## @seealso{decimate, interp, resample, upfirdn, upsample} @@ -16,24 +16,24 @@ ## This function is public domain function y = downsample(x,n,phase) - if nargin<2 || nargin>3, usage('downsample(x,n,[phase]'); end - if nargin==2, phase = 1; end + if nargin<2 || nargin>3, usage('downsample(x,n,[offset]'); end + if nargin==2, phase = 0; end - if phase > n + if phase > n - 1 warning("This is incompatible with Matlab (phase = 0:n-1). See\ octave-forge signal package release notes for details." ) end if isvector(x) - y = x(phase:n:end); + y = x(phase + 1:n:end); else - y = x(phase:n:end,:); + y = x(phase + 1:n:end,:); end end %!assert(downsample([1,2,3,4,5],2),[1,3,5]); %!assert(downsample([1;2;3;4;5],2),[1;3;5]); %!assert(downsample([1,2;3,4;5,6;7,8;9,10],2),[1,2;5,6;9,10]); -%!assert(downsample([1,2,3,4,5],2,2),[2,4]); -%!assert(downsample([1,2;3,4;5,6;7,8;9,10],2,2),[3,4;7,8]); +%!assert(downsample([1,2,3,4,5],2,1),[2,4]); +%!assert(downsample([1,2;3,4;5,6;7,8;9,10],2,1),[3,4;7,8]); Modified: trunk/octave-forge/main/signal/inst/upsample.m =================================================================== --- trunk/octave-forge/main/signal/inst/upsample.m 2008-07-30 07:59:40 UTC (rev 5205) +++ trunk/octave-forge/main/signal/inst/upsample.m 2008-07-30 08:47:50 UTC (rev 5206) @@ -3,7 +3,7 @@ ## 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}) +## @deftypefnx {Function File} @var{y} = upsample(@var{x},@var{n},@var{offset}) ## Control the position of the inserted sample in the block of n zeros. ## @end deftypefn ## @seealso{decimate, downsample, interp, resample, upfirdn} @@ -13,22 +13,27 @@ function y = upsample(x,n,phase) if nargin<2 || nargin>3, usage('upsample(x,n,[phase]'); end - if nargin==2, phase = 1; end + if nargin==2, phase = 0; end + if phase > n - 1 + warning("This is incompatible with Matlab (phase = 0:n-1). See\ + octave-forge signal package release notes for details." ) + end + [nr,nc] = size(x); if any([nr,nc]==1), y = zeros(n*nr*nc,1); - y(phase:n:end) = x; + y(phase + 1:n:end) = x; if nr==1, y = y.'; end else y = zeros(n*nr,nc); - y(phase:n:end,:) = x; + y(phase + 1: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]); +%!assert(upsample([2,4],2,1),[0,2,0,4]); +%!assert(upsample([3,4;7,8],2,1),[0,0;3,4;0,0;7,8]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |