On 5 February 2014 19:56, Benjamin Eltzner <

[hidden email]> wrote:

> when I recently had to use cross correlations in a project, I found

> that the xcorr2 function (especially using the "coeff" option) in the

> signal package of Octave does not yield correct results and

> implemented it quick and dirty myself. My code yields the same result

> as the matlab function.

>

> Referring to this state of the source:

>

>

http://sourceforge.net/p/octave/signal/ci/0e2141a26533942734b0d8e1a096eb4d5213fd9d/tree/inst/xcorr2.m>

> the lines 69-71 and 94-98 would need to be replaced. (I highlight this

> in the source appended to this mail.)

How can it return the same result as Matlab, when Matlab does not even

have a "coeff" option? Your patch actually makes xcorr2 wrong.

Consider the following example, using examples from Matlab

documentation:

I1 = [17 24 1 8 15

23 5 7 14 16

4 6 13 20 22

10 12 19 21 3

11 18 25 2 9];

I2 = [8 1 6

3 5 7

4 9 2];

xcorr2 (I1, I2)

This will return the following which is exactly the same as Matlab

34 201 286 121 106 167 60

165 470 329 244 334 299 109

271 359 405 570 585 479 256

186 229 550 615 730 409 206

116 309 595 760 575 349 221

137 263 504 434 339 222 51

66 119 256 181 256 25 72

Ignoring the "coeff" option, your code returns

-51 -4 76 -44 -14 52 -15

-35 125 -56 -51 29 34 -46

51 -36 -95 80 5 4 -9

1 -71 55 30 55 -71 1

-9 4 5 80 -95 -36 51

32 8 29 -51 -56 47 -9

11 -26 -14 -44 76 -30 27

which is completely different.

Also, while Matlab's xcorr2 does not have the "coeff" option, it says

on its documentation[1]

"""

The normalized cross-correlation of the (2,4) output element is

585/sqrt(sum(dot(I1p,I1p))*sum(dot(I2,I2))) = 0.8070

where I1p = [1 8 15; 7 14 16; 13 20 22].

"""

They're are off by 1 row and 1 column (probably forgot to account for

the extra padding or meant to say "input" instead of "output"), but

the current code returns 0.80696 (at 3,5), while yours returns

0.0345582

> I don't have the time to understand your bug tracking system, but I

> would love to help you fix this function (which is very important in

> scientific computing). I would therefore be glad, if you forwarded my

> code to whom it may concern although I do not follow protocol.

That's probably me. If you want to submit a bug, please do so on the

bug tracker [2]. There is nothing to learn, you don't even have to

create an account. Just a text box and a big submit button at the

bottom of the page. Please, enter at least your email so we can ask

you more details about the bug (like I am now). Bug reports tend to be

lost quickly and forgotten in the mailing list.

Carnë

[1]

http://www.mathworks.co.uk/help/signal/ref/xcorr2.html[2]

https://savannah.gnu.org/bugs/?func=additem&group=octave