Finding inverse cross-correlation
조회 수: 12 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
채택된 답변
Image Analyst
2016년 3월 26일
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).
댓글 수: 4
Ced
2016년 3월 26일
Great demo, thanks! Seems quite obvious when put like that ^^. One more reason to careful filter the result.
추가 답변 (2개)
Ced
2016년 3월 26일
If I interpret your description of "inverse cross-correlation" correctly, wouldn't that just be the cross-correlation with one of the signals flipped?
[ r, lag ] = xcorr(A,-B)
댓글 수: 2
Ced
2016년 3월 26일
Ah, I just saw the figure. Yes, you should remove the mean beforehand and normalize their magnitude. Have a look at ImageAnalysts response, I was not familiar with that method. Sounds interesting.
Star Strider
2016년 3월 26일
I’ve not worked with respirometry data with the sort of instrumentation you describe. Does it collect the O2 and CO2 simultaneously and there is a lag because of your experimental set-up (the O2 signal lags the CO2 signal), or is the lag in the instrumentation itself? If the instrumentation analyses the signals simultaneously and lags in the output, you could just shift them. Otherwise, from your description, the easiest way do assess the lags would be to negate one signal and then just use the Signal Processing Toolbox xcorr function, for example, on both the unchanged O2 signal and negated CO2 signal. Assuming that I understand your Question correctly, that’s how I would do it.
댓글 수: 3
Image Analyst
2016년 3월 26일
Attaching actual data - numbers in a .mat file or something - would be also useful in case someone wants to try something with it.
Star Strider
2016년 3월 26일
The problem is that ‘respiration’ exists on the cellular level so I didn’t know if you meant cellular or ventilatory ‘respiration’.
This is an instrumentation problem going back at least a half century. Going to the literature, for example ‘Time delay technique in respiratory instrumentation’ Respiration Physiology Volume 7, Issue 3, October 1969, Pages 399–402 and PubMed (with 146 related articles, such as ‘A computer-based instrumentation system for measurement of breath-by-breath oxygen consumption and carbon dioxide production’ Biomed Sci Instrum. 1994;30:1-8) can be beneficial. They’re not all free, but you should be able to get most of them from your university library.
참고 항목
카테고리
Help Center 및 File Exchange에서 Spectral Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!