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?