# Cross-correlation seems defined backwards

Suppose $$f$$ and $$g$$ are real. Why

$$C(\tau)=(f\star g)(\tau) = \int_{-\infty}^{\infty} f(t) g(t + \tau)dt \tag{1}$$

and not

$$C(\tau)=(f\star g)(\tau) = \int_{-\infty}^{\infty} f(t) g(t - \tau)dt\tag{2}$$

where $$f=$$ input, $$g =$$ template/pattern to be matched. $$(2)$$ properties:

1. If $$g$$ is centered at $$t=0$$, and $$f$$ is $$g$$ shifted to $$T$$, then $$C$$ peaks at $$T$$.

2. If $$g$$ is centered at $$t=T_0$$, and $$f$$ is $$g$$ shifted to $$T_1$$, then $$C$$ peaks at $$T_1 - T_0$$.

• Suppose $$f$$ is $$g$$ shifted to $$t=0$$. Then, $$C$$ peaks at $$-T_0$$, meaning $$g$$ is most similar to $$f$$ when shifted left by $$T_0$$.

$$(1)$$ has all of this backwards. $$C$$ at $$1$$ is similarity of $$g$$ with $$f$$ at $$-1$$, i.e. inner product of $$f$$ with $$g$$ shifted to $$-1$$.

How is this useful? Why not just have $$C(1)$$ mean "similarity of input with template shifted by $$1$$", which for template centered at 0 is nicely "template centered at $$1$$", e.g.

$$C$$ peaks at (1cm, 2cm) because that's where the apple is in the image

Yes, $$(1)$$ becomes $$(2)$$ if we look at it as matching input against template instead, but this answers the reverse of "where at input does this sub-pattern occur". I can also see it as answering "after how long will input match template if we pass it through the template (e.g. signal into system)", but we won't ask this for images and it's more suited as a physics than statistical tool.

Whatever the case, does $$(2)$$ have a name?

• Cross-posted from DSP.SE. Apr 10 at 15:07
• Re "How is this useful?" The one formula is simply converted to the other by negating $\tau,$ so if one is useful, a fortiori so is the other.
– whuber
Apr 10 at 15:14
• @whuber I think a good question here is why is it predominantly given in the form the OP gave? What was the reasoning behind that convention or was it simply a coin toss? Apr 11 at 20:35
• @Dan Agreed. There are different conventions in different communities, but generally (1) is known as a cross-correlation and (2) is related to a convolution. There's nothing inherently "backwards" about (1), though: a step forward in time for $g$ is identical to a step backwards in time for $f,$ so the only thing under discussion concerns the order in which $f$ and $g$ are mentioned in the notation.
– whuber
Apr 11 at 20:44
• I'm not trying to suggest you're confused. I'm saying that we are more likely to make some progress in understanding and resolving this situation once you tell us what you really mean by these terms. Until then it looks likely that a shared understanding and accurate communication might be difficult to achieve.
– whuber
Apr 12 at 21:40

If the interpretation of $$\tau$$ is correlation lag , then use the form of equation given by (1). Which is,
$$C(\tau)=(f\star g)(\tau) = \int_{-\infty}^{\infty} f^*(t) g(t + \tau)dt$$