changeset 595:bd9f895d2e77

cconv.m: conform to Octave coding style * cconv.m: Use @code macro in doc string. Add and remove whitespace to conform to Octave coding style. Strip trailing whitespace.
author Mike Miller <mtmiller@octave.org>
date Mon, 02 Apr 2018 12:06:28 -0700
parents 787912148e02
children 5e3061733a6d
files inst/cconv.m
diffstat 1 files changed, 33 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/inst/cconv.m	Mon Apr 02 11:52:53 2018 -0700
+++ b/inst/cconv.m	Mon Apr 02 12:06:28 2018 -0700
@@ -1,4 +1,4 @@
-## Copyright (C) 2018 Leonardo Araujo <leolca@gmail.com>
+## Copyright (C) 2018 Leonardo Araujo
 ##
 ## This program is free software: you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -19,10 +19,10 @@
 ## @deftypefnx {Function File} {@var{c} =} cconv (@var{a}, @var{b})
 ## Compute the modulo-N circular convolution.
 ##
-## @var{a} and @var{b} are input vectors and @var{c} is the modolo-@var{n} 
+## @var{a} and @var{b} are input vectors and @var{c} is the modolo-@var{n}
 ## convolution of @var{a} and @var{b}. If @var{n} is not provided,
-## its assumed default value is (length(@var{a}) + length(@var{b}) - 1 ), 
-## which provides the same result as a linear convolution. 
+## its assumed default value is @code{length(@var{a}) + length(@var{b}) - 1},
+## which provides the same result as a linear convolution.
 ##
 ## Examples:
 ##
@@ -32,7 +32,7 @@
 ##    @result{}  1   4   7   10   8
 ## @end group
 ## @end example
-## 
+##
 ## @example
 ## @group
 ## cconv (1:2, 1:4, 2)
@@ -57,8 +57,8 @@
     print_usage ();
   endif
 
-  la = length(a); 
-  lb = length(b);
+  la = length (a);
+  lb = length (b);
   if (nargin == 3)
     if (! isscalar (n))
       error ("cconv: N must be a scalar");
@@ -74,61 +74,61 @@
   endif
 
   flgcolumn = false;
-  if ( (la > 1 && iscolumn (a)) || (lb > 1 && iscolumn (b)) )
+  if ((la > 1 && iscolumn (a)) || (lb > 1 && iscolumn (b)))
     flgcolumn = true;
   endif
 
   a = a(:);
   b = b(:);
-  if ( la < lb )
-    a = [ a; zeros(lb - la, 1) ]; 
-  elseif ( lb < la ) 
-    b = [ b; zeros(la - lb, 1) ];
+  if (la < lb)
+    a = [a; zeros(lb - la, 1)];
+  elseif (lb < la)
+    b = [b; zeros(la - lb, 1)];
   end
 
-  N = length(a);
+  N = length (a);
   if (n < N)
-    an = zeros(n, 1); 
-    bn = zeros(n, 1);
+    an = zeros (n, 1);
+    bn = zeros (n, 1);
     for i = 0 : N - 1,
-      an( mod(i, n) + 1 ) += a(i + 1);
-      bn( mod(i, n) + 1 ) += b(i + 1);
+      an(mod (i, n) + 1) += a(i + 1);
+      bn(mod (i, n) + 1) += b(i + 1);
     endfor
-    a = an; 
+    a = an;
     b = bn;
   elseif (n > N)
     a = [a; zeros(n - N, 1)];
     b = [b; zeros(n - N, 1)];
   endif
 
-  c = [];
-  c = ifft ( fft(a) .* fft(b) ) ;
+  c = ifft (fft (a) .* fft (b)) ;
 
   if (!flgcolumn)
     c = c';
   endif
+
 endfunction
 
 
 %!shared x
 %! x = [1, 2, 3, 4, 5];
 
-%!assert (cconv(x, 1), [1, 2, 3, 4, 5])
-%!assert (cconv(x', 1), [1; 2; 3; 4; 5])
-%!assert (cconv(x, [1 1]), [1, 3, 5, 7, 9, 5])
-%!assert (cconv(x, [1 1],3), [8, 12, 10])
+%!assert (cconv (x, 1), [1, 2, 3, 4, 5])
+%!assert (cconv (x', 1), [1; 2; 3; 4; 5])
+%!assert (cconv (x, [1 1]), [1, 3, 5, 7, 9, 5])
+%!assert (cconv (x, [1 1], 3), [8, 12, 10])
 
-%!assert (cconv([2 1 2 1], [1 2 3 4]), [2 5 10 16 12 11 4], 1E-14)
-%!assert (cconv([2 1 2 1], [1 2 3 4], 4), [14 16 14 16])
-%!assert (cconv([2 1 2 1], [1 2 3 4], 3), [22 17 21])
-%!assert (cconv([2 1 2 1], [1 2 3 4], 2), [28 32])
-%!assert (cconv([2 1 2 1], [1 2 3 4], 1), 60)
+%!assert (cconv ([2 1 2 1], [1 2 3 4]), [2 5 10 16 12 11 4], 1e-14)
+%!assert (cconv ([2 1 2 1], [1 2 3 4], 4), [14 16 14 16])
+%!assert (cconv ([2 1 2 1], [1 2 3 4], 3), [22 17 21])
+%!assert (cconv ([2 1 2 1], [1 2 3 4], 2), [28 32])
+%!assert (cconv ([2 1 2 1], [1 2 3 4], 1), 60)
 
 ## Test input validation
 %!error cconv ()
 %!error cconv (1)
-%!error <N must be a scalar> cconv(1,1,[1 1])
-%!error <both arguments A and B must be vectors> cconv(ones(2,2),1)
-%!error <both arguments A and B must be vectors> cconv(1,ones(2,2))
-%!error <N must be an integer> cconv(1,1,3.5)
+%!error <N must be a scalar> cconv (1, 1, [1 1])
+%!error <both arguments A and B must be vectors> cconv (ones (2, 2), 1)
+%!error <both arguments A and B must be vectors> cconv (1, ones (2, 2))
+%!error <N must be an integer> cconv (1, 1, 3.5)