I have been trying to cross correlate two spectra with the intent of finding the radial velocity of one relative to the other. I've been working on a Python code to do this for some time, but was having complications. Although there is clearly a shift between the two spectra, the numpy cross correlation function that the code uses kept coming up with a shift of zero. I recently came across the concept of "regularizing" data on a python help website. Someone was having a similar problem (coming up with a cross correlation result of a zero shift), and it was pointed out that they weren't regularizing their data. To regularize data is to subtract off the mean, and divide by the standard deviation. I tried doing this in my code, and it actually started to work, and give me very nice answers! The problem is that I don't particularly understand why this makes the cross correlation work.

Is anyone familiar with the concept of regularizing data? Or has anyone had a similar problem regarding cross correlations?

It is instructive to plot the cross-correlation of two spectra that have no features whatsoever but non-zero means. There will (typically) be a hump peaked gently at zero. If you remove the mean, it will be flat. The key idea is that there is a big positive "dot product" between all-positive (say) vectors, even if they have nothing to do with one another (ie, are completely uncorrelated). Not sure if that helps? You can build intuition by cross-correlating three-element vectors / spectra. Then you can really look at the different cases.

Hi,

I recently saw this example - this can probably be adapted to your needs.

https://www.cfa.harvard.edu/~jbattat/computer/python/science/#correlation