Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Cross-Correlation and Phase Difference

Status
Not open for further replies.

dynaman

New member
Dec 17, 2011
75
0
0
AU
Hi guys

I'm trying to implement a phase shift meter in VB.NET between 2 audio signals. I'm using Math.NET cross-correlation functions however they can't calculate the phase shift or lag between the 2 signals as far as I can tell. Can anyone recommend a .NET DSP library that can calculate phase shift using FFT cross-correlation methods?

thanks

DM
 
Replies continue below

Recommended for you

Yeah, it's a bit frustrating. I couldn't find anything specific to cross-correlation in that library. From what I understand, this process can be used;

[ul]
[li]take the FFT of both signals[/li]
[li]multiply one with conjugate of the other (element-wise multiplication)[/li]
[li]do the inverse FFT[/li]
[li]get max value as a correlation coefficient and its index as the delay(signal lag)[/li]
[/ul]

I just wish there was a library that had a "find phase difference" function.

thanks

DM
 
I don't understand your process.

The formula is, where F is the complex fourier transform,is phase((Fx.*Fy)./(Fy.*Fy)) where dot indicates element by element. Perhaps easier for you is that the phase of the transfer function is phase(Fx.*Fy).-phase(Fy.*Fy), which simplifies back to phase(Fx).-phase(Fy). Note that the delay is a function of frequency and is meaningless where there is little signal. The coherence is a useful measure of phase stability.

Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Hi Greg

Can I please clarify by what you mean when the delay is meaningless where there is little signal? Is there are a better process for measuring phase difference when the signals are small and somewhat noisy?

regards

DM
 
SLCarttopolar(SLDividecomplex(SLFourier(signal1),SLFourier(signal2))) should give you the complex spectrum of the transfer function in (mag,phase) format, or you could try one of the other formulations i gave above. there are others, with various deep and meaningful differences, but that's where I'd start.



Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Hi Greg

Just implemented the complex spectrum of the transfer function and plotted phase vs frequency. It seems to work OK if the two signals are sine waves. However one is a sine wave and the other is a square wave (i.e. pulse of 5% duty cycle). It seems to give noisy readings that seem to jump around for this configuration even after averaging results.

Sorry, a bit confused about implementing the method.

regards

DM
 
So I tried simulating my results using Multi-Instrument Pro (
I can generate essentially the same results for the Phase Spectrum. However, Multi-Instrument has a great Cross-Correlation function which calculates the delay between Signal 1 & Signal 2 even with noise present. I'm not sure how they created that function?
 
Well I was able to replicate Multi-Instrument Pro's function by applying the method as originally stated;

[ul]
[li]take the FFT of both signals[/li]
[li]multiply one with conjugate of the other (element-wise multiplication)[/li]
[li]do the inverse FFT[/li]
[/ul]

Plotting the Inverse FFT result vs time Delay produces the same result. I think I'm on the home stretch now.
 
Status
Not open for further replies.
Back
Top