# What is the difference between convolution and cross-correlation?

I've found on multiple sites that convolution and cross-correlation are similar (including the tag wiki for convolution), but I didn't find anywhere how they differ.

What is the difference between the two? Can you say that autocorrelation is also a kind of a convolution?

-
It may be interesting to note that for even, real functions, the cross-correlation and convolution produce the same result. – user5135 Jul 30 '13 at 0:06
One uses a 5-pointed star ★ and the other uses a 6-pointed star ✶. – endolith Apr 9 '14 at 16:02

The only difference between cross-correlation and convolution is a time reversal on one of the inputs. Discrete convolution and cross-correlation are defined as follows (for real signals; I neglected the conjugates needed when the signals are complex):

$$x[n] * h[n] = \sum_{k=0}^{\infty}h[k] x[n-k]$$

$$corr(x[n],h[n]) = \sum_{k=0}^{\infty}h[k] x[n+k]$$

This implies that you can use fast convolution algorithms like overlap-save to implement cross-correlation efficiently; just time reverse one of the input signals first. Autocorrelation is identical to the above, except $h[n] = x[n]$, so you can view it as related to convolution in the same way.

Edit: Since someone else just asked a duplicate question, I've been inspired to add one more piece of information: if you implement correlation in the frequency domain using a fast convolution algorithm like overlap-save, you can avoid the hassle of time-reversing one of the signals first by instead conjugating one of the signals in the frequency domain. It can be shown that conjugation in the frequency domain is equivalent to reversal in the time domain.

-
This answer is fine for real signals, but Jason brought up complex-valued signals, in which case it is important to note that it is not quite the case that the "only difference is .... time reversal ..." Indeed, complex conjugates are needed on one of the two signals in the correlation formula (which one is conjugated is a matter of convention - some say to may to and some say to mah to - but both call a fruit a vegetable). On the other hand, neither signal is conjugated in the convolution formula. – Dilip Sarwate Jun 20 '12 at 2:44
but what does it mean that they so similar? Using some deep intuitive words! – Diego Dec 14 '12 at 17:20
I don't see how this is reversing it, rather than shifting it in the opposite direction to what is useful? – Jonathan. Dec 16 '15 at 0:13
@Jonathan.: The reversal occurs because the time index $k$ inside of the summation is negated in the case of correlation versus convolution. If you work out the math for an example signal, you'll see the effect. – Jason R Dec 16 '15 at 4:11
@JasonR, surely this just results in a shift in the opposite direction? I've tried working it out and all that happens is the x input shifts away from the h input and everything ends up as zero. jsfiddle.net/ua5d1uo2 – Jonathan. Dec 16 '15 at 15:03

For continuous convolution $$[Hf](x) \equiv f(x) * h(x) \equiv \int\mathrm{d}x' h(x-x')f(x')$$ and continuous cross-correlation $$[Gf](x) \equiv f(x) \star h(x) \equiv \int \mathrm{d}x'h^*(x'-x)f(x')$$ It's easy to show that the cross-correlation operator $G$ is the adjoint operator of the the convolution operator $H$.

Also, the convolution operation is commutative$$f(x) * h(x) = h(x) * f(x),$$ while cross-correlation does not have such a property.

$\\\\\\\\$

-

Here's a visualization of the two in case it helps with intuition: