From: <car...@us...> - 2011-12-17 00:55:22
|
Revision: 9421 http://octave.svn.sourceforge.net/octave/?rev=9421&view=rev Author: carandraug Date: 2011-12-17 00:55:16 +0000 (Sat, 17 Dec 2011) Log Message: ----------- xcorr2: * simpler input check and default setting * remove ancient functions warn_empty_list_elements and empty_list_elements_ok * help text to texinfo * update GPL version Modified Paths: -------------- trunk/octave-forge/main/signal/inst/xcorr2.m Modified: trunk/octave-forge/main/signal/inst/xcorr2.m =================================================================== --- trunk/octave-forge/main/signal/inst/xcorr2.m 2011-12-16 23:21:53 UTC (rev 9420) +++ trunk/octave-forge/main/signal/inst/xcorr2.m 2011-12-17 00:55:16 UTC (rev 9421) @@ -1,8 +1,9 @@ ## Copyright (C) 2000 Dave Cogdell <cog...@as...> +## Copyright (C) 2000 Paul Kienzle <pki...@us...> ## ## 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 -## the Free Software Foundation; either version 2 of the License, or +## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, @@ -13,46 +14,49 @@ ## You should have received a copy of the GNU General Public License ## along with this program; If not, see <http://www.gnu.org/licenses/>. -## C = xcorr2 (A, B) -## Compute the 2D cross-correlation of matrices A and B. -## C = xcorr2 (A) -## Compute two-dimensional autocorrelation of matrix A. -## C = xcorr2 (..., 'scale') -## biased - scales the raw cross-correlation by the maximum number -## of elements of A and B involved in the generation of -## any element of C -## unbiased - scales the raw correlation by dividing each element -## in the cross-correlation matrix by the number of -## products A and B used to generate that element -## coeff - normalizes the sequence so that the largest -## cross-correlation element is identically 1.0. -## none - no scaling (this is the default). +## -*- texinfo -*- +## @deftypefn {Function File} {@var{c} =} xcorr2 (@var{a}) +## @deftypefnx {Function File} {@var{c} =} xcorr2 (@var{a}, @var{b}) +## @deftypefnx {Function File} {@var{c} =} xcorr2 (@dots{}, @var{scale}) +## Compute the 2D cross-correlation of matrices @var{a} and @var{b}. +## +## If @var{b} is not specified, it defaults to the same matrix as @var{a}, i.e., +## it's the same as @code{xcorr(@var{a}, @var{a})}. +## +## The optional argument @var{scale}, defines the type of scaling applied to the +## cross-correlation matrix (defaults to "none"). Possible values are: +## @itemize @bullet +## @item "biased" +## +## Scales the raw cross-correlation by the maximum number of elements of @var{a} +## and @var{b} involved in the generation of any element of @var{c}. +## +## @item "unbiased" +## +## Scales the raw correlation by dividing each element in the cross-correlation +## matrix by the number of products @var{a} and @var{b} used to generate that +## element +## +## @item "coeff" +## +## Normalizes the sequence so that the largest cross-correlation element is +## identically 1.0. +## +## @item "none" +## +## No scaling (this is the default). +## @end itemize +## @seealso{conv2, corr2, xcorr} +## @end deftypefn -## Author: Dave Cogdell <cog...@as...> -## 2000-05-02 Paul Kienzle <pki...@us...> -## * joined R. Johnson's xcorr2f.m and Dave Cogdell's xcorr2x.m -## * adapted for Octave -## 2001-01-15 Paul Kienzle -## * vectorized code for 'unbiased' correction -## 2001-02-06 Paul Kienzle -## * replaced R. Johnson's xcorr2f code with code based on conv2 +function c = xcorr2 (a, b = a, biasflag = "none") -function c = xcorr2(a,b,biasflag) - if (nargin < 1 || nargin > 3) - usage ("c = xcorr2(A [, B] [, 'scale'])"); + print_usage; + elseif (nargin == 2 && ischar (b)) + biasflag = b; + b = a; endif - if nargin == 1 - b = a; - biasflag = 'none'; - elseif nargin == 2 - if ischar (b) - biasflag = b; - b = a; - else - biasflag = 'none'; - endif - endif ## compute correlation [ma,na] = size(a); @@ -64,26 +68,20 @@ if strcmp(lower(biasflag), 'biased'), c = c / ( min ([ma, mb]) * min ([na, nb]) ); elseif strcmp(lower(biasflag), 'unbiased'), - try eleo = empty_list_elements_ok; - catch eleo = 0; - end - try wele = warn_empty_list_elements; - catch wele = 0; - end - unwind_protect - empty_list_elements_ok = 1; - warn_empty_list_elements = 0; - lo = min ([na,nb]); hi = max ([na, nb]); - row = [ 1:(lo-1), lo*ones(1,hi-lo+1), (lo-1):-1:1 ]; - lo = min ([ma,mb]); hi = max ([ma, mb]); - col = [ 1:(lo-1), lo*ones(1,hi-lo+1), (lo-1):-1:1 ]'; - unwind_protect_cleanup - empty_list_elements_ok = eleo; - warn_empty_list_elements = wele; - end_unwind_protect + lo = min ([na,nb]); + hi = max ([na, nb]); + row = [ 1:(lo-1), lo*ones(1,hi-lo+1), (lo-1):-1:1 ]; + + lo = min ([ma,mb]); + hi = max ([ma, mb]); + col = [ 1:(lo-1), lo*ones(1,hi-lo+1), (lo-1):-1:1 ]'; + bias = col*row; - c = c./bias; + c = c./bias; + elseif strcmp(lower(biasflag),'coeff'), c = c/max(c(:))'; + else + error ("invalid type of scale %s", biasflag); endif endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-08-23 17:54:21
|
Revision: 10899 http://octave.svn.sourceforge.net/octave/?rev=10899&view=rev Author: carandraug Date: 2012-08-23 17:54:14 +0000 (Thu, 23 Aug 2012) Log Message: ----------- xcorr2: add simple test Modified Paths: -------------- trunk/octave-forge/main/signal/inst/xcorr2.m Modified: trunk/octave-forge/main/signal/inst/xcorr2.m =================================================================== --- trunk/octave-forge/main/signal/inst/xcorr2.m 2012-08-23 17:15:22 UTC (rev 10898) +++ trunk/octave-forge/main/signal/inst/xcorr2.m 2012-08-23 17:54:14 UTC (rev 10899) @@ -88,3 +88,15 @@ error ("invalid type of scale %s", biasflag); endswitch endfunction + +%!test +%! a = magic (5); +%! b = [6 13 22; 10 18 23; 8 15 23]; +%! c = [391 807 519 391 473 289 120 +%! 920 1318 1045 909 1133 702 278 +%! 995 1476 1338 1534 2040 1161 426 +%! 828 1045 1501 2047 2108 1101 340 +%! 571 1219 2074 2155 1896 821 234 +%! 473 1006 1643 1457 946 347 108 +%! 242 539 850 477 374 129 54]; +%! assert (xcorr2 (a, b), c); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-08-24 02:56:27
|
Revision: 10905 http://octave.svn.sourceforge.net/octave/?rev=10905&view=rev Author: carandraug Date: 2012-08-24 02:56:21 +0000 (Fri, 24 Aug 2012) Log Message: ----------- xcorr2: improved texinfo Modified Paths: -------------- trunk/octave-forge/main/signal/inst/xcorr2.m Modified: trunk/octave-forge/main/signal/inst/xcorr2.m =================================================================== --- trunk/octave-forge/main/signal/inst/xcorr2.m 2012-08-24 02:45:33 UTC (rev 10904) +++ trunk/octave-forge/main/signal/inst/xcorr2.m 2012-08-24 02:56:21 UTC (rev 10905) @@ -22,34 +22,32 @@ ## Compute the 2D cross-correlation of matrices @var{a} and @var{b}. ## ## If @var{b} is not specified, it defaults to the same matrix as @var{a}, i.e., -## it's the same as @code{xcorr(@var{a}, @var{a})}. +## same as @code{xcorr(@var{a}, @var{a})}. ## ## The optional argument @var{scale}, defines the type of scaling applied to the -## cross-correlation matrix (defaults to "none"). Possible values are: -## @itemize @bullet -## @item "biased" +## cross-correlation matrix. Possible values are: ## +## @table @asis +## @item "none" (default) +## No scaling. +## +## @item "biased" ## Scales the raw cross-correlation by the maximum number of elements of @var{a} ## and @var{b} involved in the generation of any element of @var{c}. ## -## @item "none" -## No scaling (this is the default). -## ## @item "unbiased" -## ## Scales the raw correlation by dividing each element in the cross-correlation ## matrix by the number of products @var{a} and @var{b} used to generate that -## element +## element. ## ## @item "coeff" +## Normalizes the sequence dividing by the max of the cross-correlation, so that +## the largest cross-correlation element is 1. ## -## Normalizes the sequence so that the largest cross-correlation element is -## identically 1.0. -## ## @item "norm" -## ## Returns the normalized cross-correlation. -## @end itemize +## @end table +## ## @seealso{conv2, corr2, xcorr} ## @end deftypefn @@ -69,6 +67,7 @@ ## bias routines by Dave Cogdell (cog...@as...) ## optimized by Paul Kienzle (pki...@us...) + ## norm routine by Carnë Draug (car...@gm...) switch lower (biasflag) case {"none"} ## do nothing, it's all done This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-08-27 01:52:02
|
Revision: 10920 http://octave.svn.sourceforge.net/octave/?rev=10920&view=rev Author: carandraug Date: 2012-08-27 01:51:54 +0000 (Mon, 27 Aug 2012) Log Message: ----------- xcorr2: fix bug when no arguments are passed Modified Paths: -------------- trunk/octave-forge/main/signal/inst/xcorr2.m Modified: trunk/octave-forge/main/signal/inst/xcorr2.m =================================================================== --- trunk/octave-forge/main/signal/inst/xcorr2.m 2012-08-26 19:32:20 UTC (rev 10919) +++ trunk/octave-forge/main/signal/inst/xcorr2.m 2012-08-27 01:51:54 UTC (rev 10920) @@ -21,8 +21,8 @@ ## @deftypefnx {Function File} {@var{c} =} xcorr2 (@dots{}, @var{scale}) ## Compute the 2D cross-correlation of matrices @var{a} and @var{b}. ## -## If @var{b} is not specified, it defaults to the same matrix as @var{a}, i.e., -## same as @code{xcorr(@var{a}, @var{a})}. +## If @var{b} is not specified, computes autocorrelation of @var{a}, i.e., +## same as @code{xcorr (@var{a}, @var{a})}. ## ## The optional argument @var{scale}, defines the type of scaling applied to the ## cross-correlation matrix. Possible values are: @@ -51,13 +51,18 @@ ## @seealso{conv2, corr2, xcorr} ## @end deftypefn -function c = xcorr2 (a, b = a, biasflag = "none") +function c = xcorr2 (a, b, biasflag = "none") if (nargin < 1 || nargin > 3) print_usage; elseif (nargin == 2 && ischar (b)) biasflag = b; b = a; + elseif (nargin == 1) + ## we have to set this case here instead of the function line, because if + ## someone calls the function with zero argument, since a is never set, we + ## will fail with "`a' undefined" error rather that print_usage + b = a; endif ## compute correlation This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-08-27 01:53:24
|
Revision: 10921 http://octave.svn.sourceforge.net/octave/?rev=10921&view=rev Author: carandraug Date: 2012-08-27 01:53:16 +0000 (Mon, 27 Aug 2012) Log Message: ----------- xcorr2: fix bug on norm option when input is not double Modified Paths: -------------- trunk/octave-forge/main/signal/inst/xcorr2.m Modified: trunk/octave-forge/main/signal/inst/xcorr2.m =================================================================== --- trunk/octave-forge/main/signal/inst/xcorr2.m 2012-08-27 01:51:54 UTC (rev 10920) +++ trunk/octave-forge/main/signal/inst/xcorr2.m 2012-08-27 01:53:16 UTC (rev 10921) @@ -94,6 +94,10 @@ c = c/max(c(:))'; case {"norm"} + ## FIXME maybe these conversions for double can be removed when + ## https://savannah.gnu.org/bugs/?37199 gets fixed? + a = double (a); + b = double (b); a = conv2 (a.^2, ones (size (b))); b = dot (b(:), b(:)); c(:,:) = c(:,:) ./ sqrt (a(:,:) * b); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-08-27 01:58:20
|
Revision: 10922 http://octave.svn.sourceforge.net/octave/?rev=10922&view=rev Author: carandraug Date: 2012-08-27 01:58:14 +0000 (Mon, 27 Aug 2012) Log Message: ----------- xcorr2: check if input is 2D only Modified Paths: -------------- trunk/octave-forge/main/signal/inst/xcorr2.m Modified: trunk/octave-forge/main/signal/inst/xcorr2.m =================================================================== --- trunk/octave-forge/main/signal/inst/xcorr2.m 2012-08-27 01:53:16 UTC (rev 10921) +++ trunk/octave-forge/main/signal/inst/xcorr2.m 2012-08-27 01:58:14 UTC (rev 10922) @@ -64,6 +64,9 @@ ## will fail with "`a' undefined" error rather that print_usage b = a; endif + if (ndims (a) != 2 || ndims (b) != 2) + error ("xcorr2: input matrices must must have only 2 dimensions"); + endif ## compute correlation [ma,na] = size(a); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |