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: Example 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?
  • $\begingroup$ 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? $\endgroup$ Commented Mar 20 at 11:47
  • $\begingroup$ 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? $\endgroup$ Commented Mar 20 at 11:49
  • $\begingroup$ 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. $\endgroup$
    – NeuroDSP
    Commented Mar 20 at 13:10
  • $\begingroup$ 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. $\endgroup$
    – NeuroDSP
    Commented Mar 20 at 13:13
  • 1
    $\begingroup$ @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. $\endgroup$
    – NeuroDSP
    Commented Mar 20 at 15:40

1 Answer 1


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.

Jack L. image patch search

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.

enter image description here

  • 1
    $\begingroup$ 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. $\endgroup$ Commented Mar 20 at 11:56
  • 1
    $\begingroup$ @MarcusMüller. True, but it doesn't seem to have removed it. I hope the OP humors me and tries it first. $\endgroup$
    – Peter K.
    Commented Mar 20 at 11:58
  • $\begingroup$ 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. $\endgroup$ Commented Mar 20 at 11:59
  • $\begingroup$ 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? $\endgroup$
    – NeuroDSP
    Commented Mar 20 at 13:19
  • $\begingroup$ @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. $\endgroup$
    – Peter K.
    Commented Mar 20 at 15:09

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.