# Normalization and cross-correlation - what am I doing wrong?

Started by February 23, 2006
```Hi NG,

I have a problem regarding normalization when performing
cross-correlation:

I have a relatively short signal/waveform ("A") which I'm
cross-correlating with a longer timeseries ("B") to look for this
waveform. Since there are large fluctuations in B, I have decided to
apply some sort of normalization scheme to both A and B. So, for A I
divided all the samples with the squareroot of the average power of the
signal, i.e. sqrt(sum(A(i)^2)/N). As for B, I do the same thing FOR
EACH WINDOW OF "B" THAT "A" PASSES IN THE CORRELATION. That is, before
the windows are multiplied and summed in the correlation, the segment
of B in question undergoes the same treatment as described above.

The result looks very strange, and is definately not correct. Do you
see any flaws in my method?

Thanks!

Best,

M.L.

```
```Normalized correlation is:

sum(A(i)B(i))/sqrt(sum(A(i)^2) sum(B(i)^2))

Where all summations are over the same number of elements N (regardless
of the actual length of each signal, which may have elements that do not
participate in the correlation).

M.L. wrote:
> Hi NG,
>
> I have a problem regarding normalization when performing
> cross-correlation:
>
> I have a relatively short signal/waveform ("A") which I'm
> cross-correlating with a longer timeseries ("B") to look for this
> waveform. Since there are large fluctuations in B, I have decided to
> apply some sort of normalization scheme to both A and B. So, for A I
> divided all the samples with the squareroot of the average power of the
> signal, i.e. sqrt(sum(A(i)^2)/N). As for B, I do the same thing FOR
> EACH WINDOW OF "B" THAT "A" PASSES IN THE CORRELATION. That is, before
> the windows are multiplied and summed in the correlation, the segment
> of B in question undergoes the same treatment as described above.
>
> The result looks very strange, and is definately not correct. Do you
> see any flaws in my method?
>
>
> Thanks!
>
> Best,
>
> M.L.
>
```
```the description of your problem is not easy to understand.

why normalize with power?

I would do it like this

a_new=a/max(a);
b_new=b/max(b);

cross-correlate a_new with b_new and look for peak(s) in cross-correlation.

can you upload screenshots to some webpage so we can see why it looks
"strange"?

which language are you programming in?

```
```Hi,

Thanks - both of you. I changed my code (MatLab by the way) to use the
formula stated in twains post and now it seems to work much better. I
think my mistake was that I divided the sqrt(power) with the number of
samples in the window. Apart from that, I had the same calculation..

Thanks! I appreciate it..

Best,

M.L.

```