# Correlation : How is correlation analogous to dot product?

Till now I know correlation tells about similarity. I was watching a video lecture on image similarity in which I came to know that correlation is analogous to dot product. And hence correlation of two images is maximum when these images are similar as happens in dot product of two aligned(similar) vectors.

Dot product of two vectors $a=[a_1, a_2, a_3, .....]$ and $b=[b_1, b_2, b_3, .....]$ is given as $$a\cdot b=\sum_{i}a_ib_i$$ While cross correlation of two discrete real signals $x(n)$ and $y(n)$ is given as $$R_{xy}(n)=\sum_mx(m)y(n+m)$$
So now I want to know:

• How correlation is analogous to dot product?
• When is correlation maximum?
• Why?
• So write down the formula for dot product of two functions (add that to your question). Do the same for correlation (and add that to your question). Dec 16 '16 at 9:39
• @Marcus I dont understand what exactly you are asking me to do. Can you please answer this question or is there something wrong in the question ? Dec 16 '16 at 9:49
• I think the question doesn't show your real problem: since you're asking about the analogy between correlation and dot product, you definitely know what both of them are - and if you added that knowledge, in the shape of formulas, to your question, we could much easier answer it! Dec 16 '16 at 10:27
• So: edit your question to include the definition of correlation and of dot-product. Then, explain with these what you need help with. The way you ask this now, I really don't know where to start explaining! Dec 16 '16 at 10:30
• I have edited the question and I am waiting for explanation. Dec 16 '16 at 15:15

So using your formula for the cross-correlation:

$$R_{xy}(n)=\sum_m x(m)y(n+m)$$

we see that

\begin{align} R_{xy}[n]&=\sum_m x[m]y[n+m]\\ &= \sum_m x[m] \tilde y_n[m]\\ &= x \cdot \tilde y_n\\ \text{for}\\ \tilde y_n[k] &= y[n+k]\text{ ,}\\ \end{align} which is a dot product.

So for any "shift" in the cross-correlation, you have the dot product of the first operand with the $n$-shifted second operand.

Note, by the way, that your formulas are only correct for real-valued $x$, i.e. in general, the correct formula for dot product and cross correlation are:

\begin{align} x\cdot y &= \sum\limits_{i=0}^{N-1} x^*[i]y[i]\\ R_{xy}[n] &= \sum\limits_{i=0}^{N-1} x^*[i]y[n+i]\\ \text{with}\\ x,y &\in \mathbb C^N\\ {z}^*&= \Re\{z\} - \Im\{z\} \end{align}