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. |