# Cross Correlation values

I'm trying to develop a flow meter using the cross correlation algorithm.

I'm using 2x IR leds and 2x phototransistors and a MSP430F5529. One pair of phototransistor-Led go in the upper level and the other in a lower level.

When the liquid passes in the first pair of phototransistor - IR Led, the microcontroller reads the voltage from the phototransistor out, and after the liquid cross the other pair and the microcontroller reads the voltage again.

The signals collected are very similar but phase shifted as expected.

I analysed the data collected in Matlab software and used the cross correlation algorithm to calculate the phase shift between them, in windows of 250 points.

The results were very good, but sometimes the algorithm results in values of zero phase shift. And analysing the plot, it can be seen, visually, that the 2 waves have a nonzero phase shift.

An example of a window is showed below.

For this 2 signals, the cross correlation results 0. But as can be seen, the 2 signals are phase shifted by about 13 points.

I know that the cross correlation algorithm will give me the delay of the maximum value of the multiplication of each point. But how I can calculate the phase shift between 2 signals like this example?

• Can you post the matlab code? If you have the Signal Processing Toolbox, do the examples for xcor help? Nov 17 '14 at 20:09
• For those of us not familiar with building a flow meter like this, can you provide a link to a good introductory reference? All of the papers I found are behind pay walls. Nov 19 '14 at 1:30
• Dealing with the same problem for some time, especially coding the algorithm into the microcontroller, as it is very time sensitive. Did you have any progress? As far as tired codes are taking too long.
– caga
Feb 19 '15 at 20:17