diff scripts/signal/synthesis.m @ 17718:6ed0a8532bcf

Overhaul stft and synthesis functions * scripts/signal/stft.m: Redo docstring to list all calling forms. Use default values to simplify input processing. Use switch statements instead of if/elseif trees for clarity. * scripts/signal/synthesis.m: Use numel() to simplify input validation. Use range st+1:st+inc, rather than st:st+inc-1 to avoid bad indexing error when window size is equal to increment. Use in-place operator for efficiency.
author Rik <rik@octave.org>
date Mon, 21 Oct 2013 16:57:02 -0700
parents 1c89599167a6
children d63878346099
line wrap: on
line diff
--- a/scripts/signal/synthesis.m
+++ b/scripts/signal/synthesis.m
@@ -17,7 +17,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} synthesis (@var{y}, @var{c})
+## @deftypefn {Function File} {@var{x} =} synthesis (@var{y}, @var{c})
 ## Compute a signal from its short-time Fourier transform @var{y} and a
 ## 3-element vector @var{c} specifying window size, increment, and
 ## window type.
@@ -27,6 +27,7 @@
 ## @example
 ## [@var{y}, @var{c}] = stft (@var{x} , @dots{})
 ## @end example
+## @seealso{stft}
 ## @end deftypefn
 
 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at>
@@ -38,8 +39,7 @@
     print_usage ();
   endif
 
-  [nr, nc] = size (c);
-  if (nr * nc != 3)
+  if (numel (c) != 3)
     error ("synthesis: C must contain exactly 3 elements");
   endif
 
@@ -59,12 +59,12 @@
 
   z = real (ifft (y));
   st = fix ((w_size-inc) / 2);
-  z = z(st:st+inc-1, :);
-  w_coeff = w_coeff(st:st+inc-1);
+  z = z(st+1:st+inc, :);
+  w_coeff = w_coeff(st+1:st+inc);
 
   nc = columns (z);
   for i = 1:nc
-    z(:, i) = z(:, i) ./ w_coeff;
+    z(:, i) ./= w_coeff;
   endfor
 
   x = reshape (z, inc * nc, 1);