1 ## Copyright (C) 2000 Dave Cogdell <cogdelld@asme.org>
2 ## Copyright (C) 2000 Paul Kienzle <pkienzle@users.sf.net>
4 ## This program is free software; you can redistribute it and/or modify it under
5 ## the terms of the GNU General Public License as published by the Free Software
6 ## Foundation; either version 3 of the License, or (at your option) any later
9 ## This program is distributed in the hope that it will be useful, but WITHOUT
10 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 ## You should have received a copy of the GNU General Public License along with
15 ## this program; if not, see <http://www.gnu.org/licenses/>.
18 ## @deftypefn {Function File} {@var{c} =} xcorr2 (@var{a})
19 ## @deftypefnx {Function File} {@var{c} =} xcorr2 (@var{a}, @var{b})
20 ## @deftypefnx {Function File} {@var{c} =} xcorr2 (@dots{}, @var{scale})
21 ## Compute the 2D cross-correlation of matrices @var{a} and @var{b}.
23 ## If @var{b} is not specified, it defaults to the same matrix as @var{a}, i.e.,
24 ## it's the same as @code{xcorr(@var{a}, @var{a})}.
26 ## The optional argument @var{scale}, defines the type of scaling applied to the
27 ## cross-correlation matrix (defaults to "none"). Possible values are:
31 ## Scales the raw cross-correlation by the maximum number of elements of @var{a}
32 ## and @var{b} involved in the generation of any element of @var{c}.
36 ## Scales the raw correlation by dividing each element in the cross-correlation
37 ## matrix by the number of products @var{a} and @var{b} used to generate that
42 ## Normalizes the sequence so that the largest cross-correlation element is
47 ## No scaling (this is the default).
49 ## @seealso{conv2, corr2, xcorr}
52 function c = xcorr2 (a, b = a, biasflag = "none")
54 if (nargin < 1 || nargin > 3)
56 elseif (nargin == 2 && ischar (b))
61 ## compute correlation
64 c = conv2 (a, conj (b (mb:-1:1, nb:-1:1)));
66 ## bias routines by Dave Cogdell (cogdelld@asme.org)
67 ## optimized by Paul Kienzle (pkienzle@users.sf.net)
68 if strcmp(lower(biasflag), 'biased'),
69 c = c / ( min ([ma, mb]) * min ([na, nb]) );
70 elseif strcmp(lower(biasflag), 'unbiased'),
73 row = [ 1:(lo-1), lo*ones(1,hi-lo+1), (lo-1):-1:1 ];
77 col = [ 1:(lo-1), lo*ones(1,hi-lo+1), (lo-1):-1:1 ]';
82 elseif strcmp(lower(biasflag),'coeff'),
85 error ("invalid type of scale %s", biasflag);