MATLAB: Finding inverse cross-correlation

cross_correlationrespirometry

Hello,
I am trying to compute the inverse cross-correlation of two signals ; that is, I have two signal A and B such that A should reach its positive peak when B hits its negative peak, and I want to find the delay between the two. How can I do this in Matlab?
If it helps, I am working with respiratory data, specifically co2 and 02 volume concentrations. Our respirometer starts collecting co2 data about 1-2 seconds before it starts with the o2 – hence the delay we are trying to account for.
edit: I have enclosed a graph of some sample data to be corrected – the blue signal is oxygen concentration and the orange signal is co2 concentration. As you can see, the o2 concentration is delayed (in this case) by about 1.5 seconds, which is caused entirely by our instrumentation. The goal would be to have a function which could calculate the maximal inverse cross-correlation, so that the maxima of one signal match up with the minima of the other.
Thank you!

Best Answer

Although often true, and maybe true for your signals, the best signal overlap is not guaranteed to occur when the cross correlation is maximum. That is a very common misconception. A simple thought experiment should reveal why. That is why I never use it and use normalized cross correlation instead. There is a function for that in the Image Processing Toolbox called normxcorr2(), however it should work for 1-D signals also I believe. I'm attaching a 2D pattern recognition demo (sorry I don't have any 1-D signal demo for it all ready to go).