I have 2 different signals and I'm trying to cross-correlate then using Python 2.7 and scipy.signal.correlate. How do I normalize my results (such that the max amplitude is 1.0? I tried the following:

import numpy as np
import matplotlib.pyplot as plt

t = np.linspace(0,2*np.pi,num=1000)
x1 = 10*np.sin(2*np.pi*t)
x2 = np.sin(2*np.pi*t+np.pi/2)
x12 = scipy.signal.correlate(x1,x2,'full')

results in the following plot enter image description here


2 Answers 2


When you say normalized cross-correlation I guess you mean the Pearson correlation. Anyways you just divide the cross correlation by the multiplication of the std(standard deviation) of both signal, or more conveniently: $ \rho_{xy} =\frac{<x,y>}{\sigma_x\sigma_y}$

and in code:

x1 = x1/x1.std()
x2 = x2/x2.std() and then as you did it
  • 3
    $\begingroup$ i still have to divide x12 by the length of x1 (len(x1)=len(x2)) to get a normalized amplitude (rho(tau)). What is the relevance of that? $\endgroup$ May 25, 2017 at 18:14
  • $\begingroup$ Yea you'r right, you should divide with the length as well $\endgroup$
    – Cherny
    May 26, 2017 at 15:56

To get the cross-correlation function to be normalised between +1 and -1, you can divide the cross correlation like so:

xcorr = scipy.signal.correlate(x2, x1, mode='full')
xcorr /= np.sqrt(np.sum(np.abs(x2)**2)*np.sum(np.abs(x1)**2))

The coefficient seems to be a standard normalisation, see https://gaidi.ca/weblog/normalizing-a-cross-correlation-in-matlab/

e.g. cross correlation of sin(x) and cos(x) as above gives

enter image description here

New contributor
choudhuryh is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.