# Cross-correlation between brain signals: how to handle autocorrelation?

I've been asked to calculate the cross correlation in the 3-12 Hz band between two simultaneously recorded brain signals in two distinct brain areas. Data were acquired at 32 kHz then preprocessed by applying a 3-pole Butterworth filter (lowpass 1 kHz) then downsampling to 2 kHz. By applying the method in Adhikari et al. (2010), I obtained a result for each pair that looks similar to this: There´s a huge peak at 0 lags, which, upon review of the literature and further discussion, we attributed to the strong autocorrelation these kind of signals show, and the volume conduction between the two areas. To remove it, an approach appears to be the whitening of the spectrum in our band of interest before the calculation of the cross-correlation. I understand that this would yield a spectrum that is flat over the same band, but I can't bring myself to understand:

1. Is this approach correct in principle?
2. How can I implement this in MATLAB? Despite a lot of reading, the practical steps to obtain a white spectrum are still elusive to me.
3. Should I use a sliding window approach or just apply the filter to the full 1-hour recording?
• I must admit, I'm missing the actual method being described in that paper; section 2.5.4 seems to be the core of the whole algorithm, and it's not saying at all what they actually calculate there: "the distribution of the lags at which the cross-correlation peaks occur was obtained." is the whole description: What's a "peak" in this context, exactly, what's the distribution here? How was it obtained? Commented Mar 20 at 11:47
• and auto-correlation of one or both of the signals being cross-correlation has no direct effect on the cross-correlation. Could you elaborate on why you came to the conclusion that this is the problem? If it is, why would you do step 2.5.1 from the paper? Commented Mar 20 at 11:49
• Thank you for taking the time to go through the source. I think a more straightforward explanation of the thought process might come from this toolbox, where from my understanding it takes the steps described in the paper to calculate the cross correlation. The peak in that context refers to the maximum of the cross correlation for a particular window, and it can be done after the cross correlation has been calculated, but it's not necessary. Commented Mar 20 at 13:10
• I came to this conclusion by both discussing with colleagues and with online resources, this being the most important. Sorry if I make a bit of confusion, I'm far from being an expert on this topic. Commented Mar 20 at 13:13
• @Jdip yes I pretty much followed the steps outlined in the main question + the script I linked a few comments above; the bandpass filter is applied on lines 15 through 18. Commented Mar 20 at 15:40

A quick and dirty attempt to do this is to simply find the sample-to-sample difference between each signal:

$$x_{\tt diff}[n] = x[n] - x[n-1] \tag{1}$$

I had a similar problem when finding patch locations in images. Images tend to have values between 0 and 255, and so have a non-zero mean. That leads to a similar problem to what you're seeing.

In the image above, I'm trying to find Jack's nose. If I just correlate the nose patch with the image, I get the bottom left image. If I do the diff operation on the image (which does what (1) above does, but on the columns of the image), I get the bottom right image.

It's a bit hard to see, but the peak is a small red done exactly where it should be.

The keyword you're looking for is "pre-whitening".

A sideways view of the same two bottom images is below.

• But your trick here is essentially getting rid of the mean of the signal (which is a good thing to do, clearly), and the band-pass filter as described in 2.5.1 of the cited paper should do pretty much that. Commented Mar 20 at 11:56
• @MarcusMüller. True, but it doesn't seem to have removed it. I hope the OP humors me and tries it first.
– Peter K.
Commented Mar 20 at 11:58
• yes, trying the differences is clearly a good thing to do here, purely from my impression that what seems to be important about the signals observed is local changes and not global trends. Commented Mar 20 at 11:59
• Thank you for your reply. I think I need to have a pre-whitening step before the calculations, still I find it unclear how to implement it. Should I calculate the sample-to-sample difference within each of the two signals, then apply the following calculations, as in the toolbox that I linked above responding to @MarcusMüller? Commented Mar 20 at 13:19
• @NeuroDSP You're welcome! What is unclear about (1) ? Yes, just do the sample to sample differences for both signals to be correlated. As Marcus says, there might still be more work to do, but I'd start there.
– Peter K.
Commented Mar 20 at 15:09