robert bristow-johnson <rbj@audioimagination.com> writes:> On 9/5/13 10:48 AM, radams2000@gmail.com wrote: >> I would suggest; >> >> 1) compute the analytic signal for each of your inputs in the time domain, using either FIR or IIR parallel filters. >> >> 2) compute the magnitude of each of the complex signals computed above. >> >> 3) search for the maximum cross- correlation for the magnitude signals computed above. >> >> 4) if you need better than 1-sample accuracy then find the true peak using quadratic interpolation around the peak (posted here on comp.dsp many times). >> >> I have to admit that I'm guessing that using the analytic envelope would give a better result than using the signal itself. I have more neurons in my gut than in my brain. >> > On 9/5/13 11:35 AM, radams2000@gmail.com wrote: >> Of course if you have the dsp power to do frequency-domain >> processing then that's the best choice, just take the fft of both >> signals, convert to polar, subtract phases and divide by bin >> frequency to get a delay estimate per bin, then average all those >> delays together. If the signal is very long then break into windowed >> segments. >> > > i don't see the use for doing this in the frequency domain at all.maybe it would be better if you need fractional-sample accuracy since the phases aren't "quantized" to a sample. -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com
Delay calculation between two signals
Started by ●September 5, 2013
Reply by ●September 6, 20132013-09-06
Reply by ●September 6, 20132013-09-06
On 9/6/13 3:42 PM, Randy Yates wrote:> robert bristow-johnson<rbj@audioimagination.com> writes: >...>> so let's call the first signal x1(t) and the second one x2(t). and >> let's also define a window function w(t) that is centered at t=0. >> >> Im{ w(t) } = 0 >> w(t)>= 0 >> w(-t) = w(t) >> w(t) = 0 for |t|> W >> >> so in the vicinity of time t0, we want to know how much x2(t) is >> delayed from x1(t). so compute (using some discrete-time >> approximation to integrals): >> >> +inf >> R(tau, t0) = integral{ (x2(t)*w(t-t0)) * x1(t-tau) dt} >> -inf >> >> look for the value of tau that maximizes R(tau) for a fixed t0. > > ... that maximizes R(tau, t0) for a specific t0 ... > >> that's how much time x1(t) precedes x2(t). > > i think that should be how much time x2(t) precedes x1(t), or, > equivalently, how much x1(t) lags x2(t). >i might have gotten the sign wrong... but think about it... if x2(t) = x1(t-T) which means that x2(t) is delayed by T units of time, when tau is about T, i would expect R(tau) to be the greatest. so i *think* i got that right. i dunno.>> it's insensitive to amplitude/gain differences, does not need any >> periodicity or sinusoidality or any other notion that might make sense >> for the analytic signal. no FFT. no worrying about phase wrapping. no >> fiddling. >> >> if there is a component of x1(t) that is correlated to x2(t), this >> should tell you the time lag that makes this correlation the >> strongest. > > but one point is that your algorithm will have a practical limit on how > far we can search in tau.oh sure. you have to search all possible lags. and that possibility has to be limited. if the delay is 23 hours, you might have trouble measuring that delay unless you had apriori knowledge of about what the delay might be. for efficiency there are ways to skip some unpromising lags and hone in on the promising lags.> also, how fine do you need t0?i dunno why it needs to be better than integer sample times. it's just there to place the window. if it were off by 1 whole sample, i wouldn't expect the resulting max lag (which is tau) to differ very much.> only to a nearest sample, or will you need to fractionally resample?well the x(t) becomes x[n] and the integral becomes a summation, so yes, the lag tau will be integer samples. hopefully the sample rate is good enough that there is sufficient resolution to apply a simple quadratic interpolation to get a lag value that is accurate enough. i know quadratic interpolation is crude, but i dunno what else to do with only the discrete peak lag and its two adjacent neighbors. any higher-order interpolation would require more points around the discrete-lag peak.> >> i dunno. maybe there's something basic i am missing, but it looks >> like Deadsville around here, so i thought i might mix it up a little. > > i sorta thought the same thing - why not a basic correlator?this sorta thing is what they're for. On 9/6/13 3:46 PM, Randy Yates wrote:> robert bristow-johnson<rbj@audioimagination.com> writes: >> >> i don't see the use for doing this in the frequency domain at all. > > maybe it would be better if you need fractional-sample accuracy since > the phases aren't "quantized" to a sample.i would use some sorta interpolation with the discrete lag values to get fractional-sample resolution. if the sample rate is high enough and the sampling period of R(tau) is the same, then i would just interpolate the peak location with a quadratic using the discrete peak and its left and right neighbors. another method would be an LMS adaptive filter, and i would calculate the phase delay (or maybe the group delay) of the LMS coefficients once the LMS had settled down. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●September 6, 20132013-09-06
Robert Sorry things are so dull! I think the advantage of the frequency-domain approach is that you are more immune to large interfering signals. If you have a large sine- wave that is not the signal you are trying to locate, then you only affect the delay calculation of a single bin. In fact you could get a little fancier and apply a median filter to eliminate all the outliers. I forgot to mention that you need to unwrap the phase before taking the difference. I don't think this is a novel idea, it's a pretty standard approach. It might be called the the PHAT algorithm? Bob Bob
Reply by ●September 7, 20132013-09-07
On Friday, September 6, 2013 4:03:39 AM UTC+12, mri...@gmail.com wrote:> Hi, > > I need to calculate the delay between two signals which are not periodic signals but they are similar except the second signal having different amount of delay at different points. Would anybody please suggest which algorithm will be better to find this different delay at different position of second signal corresponding to first signal ?? > > > > please help..You could use ordinary cross-correlation and look for the peak. However, that only works well for white-noise signals. What you need is Generalised Cross Correlation (GCC) using say the Hanan Thomson method or the SCOT method, PHAT method etc.
Reply by ●September 7, 20132013-09-07
robert bristow-johnson <rbj@audioimagination.com> writes:> [...] > i might have gotten the sign wrong... but think about it... if > > x2(t) = x1(t-T) > > which means that x2(t) is delayed by T units of time,Yeah, that's right. I passed some brain wind. -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com
Reply by ●September 7, 20132013-09-07
radams2000@gmail.com writes:> PHAT algorithmhttp://research.microsoft.com/pubs/81320/WhyPHAT.pdf -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com






