I have two signals y1[i] and y2[i]. y2 is just a shifted and slightly scaled version of y1. I want to find the optimal lag dt. Using e.g. xcorr() in Matlab I can find the correlation between y1 and y2 as a function of integer lag, and then choose the lag with highest correlation value. However I want to find the lag as a real number. That is I want to interpolate y1 and y2 with e.g. polynomials and then find the optimal lag between the interpolated signals. How do I do this? My previous attempt used Savitzky Golay to find the derivative in each point and then find peaks as zero crossings of the derivative. Having found a peak in signal y1 I would then choose the closest peak in signal y2 and use the shift between these two peaks as optimal lag. This worked quite good as the optimal lag usually is quite small. However sometimes it is larger and then I would like to also take into account the shape of the signal around the peak; hence correlation. Can I use Savitzky Golay to find optimal lag as a real number? Thanks in advance for any answers! Andreas
How do I find the real numbered lag betweent two shifted versions of a signal?
Started by ●March 27, 2012
Reply by ●March 27, 20122012-03-27
On 3/27/2012 8:07 AM, Andy wrote:> I have two signals y1[i] and y2[i]. > y2 is just a shifted and slightly scaled version of y1. > I want to find the optimal lag dt. > Using e.g. xcorr() in Matlab I can find the correlation between y1 and > y2 as a function of integer lag, > and then choose the lag with highest correlation value. > However I want to find the lag as a real number. > That is I want to interpolate y1 and y2 with e.g. polynomials and then > find the optimal lag between the interpolated signals. > How do I do this? > > My previous attempt used Savitzky Golay to find the derivative in each > point and then find peaks as zero crossings of the derivative. Having > found a peak in signal y1 I would then choose the closest peak in > signal y2 and use the shift between these two peaks as optimal lag. > This worked quite good as the optimal lag usually is quite small. > However sometimes it is larger and then I would like to also take into > account the shape of the signal around the peak; hence correlation. > Can I use Savitzky Golay to find optimal lag as a real number? > > Thanks in advance for any answers!There are many ways to compute the "derivative" of a sampled signal. As a general rule, when there are many ways worth considering to do something, all of them have defects of some kind. If your results are inconsistent, look to which process you choose for differentiating. More generally, derivatives introduce noise, and noise shifts zero crossings. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●March 27, 20122012-03-27
On 3/27/12 8:07 AM, Andy wrote:> I have two signals y1[i] and y2[i]. > y2 is just a shifted and slightly scaled version of y1. > I want to find the optimal lag dt. > Using e.g. xcorr() in Matlab I can find the correlation between y1 and > y2 as a function of integer lag, > and then choose the lag with highest correlation value. > However I want to find the lag as a real number. > That is I want to interpolate y1 and y2 with e.g. polynomials and then > find the optimal lag between the interpolated signals. > How do I do this?you interpolated sampled bandlimited signals the same way we normally do. in MATLAB there is the resample() function to do it. but, perhaps all you need to do is interpolate the crosscorrelation result and look for a peak. there is a *very* simple quadratic interpolation where you give it your discrete peak value and the two adjacent correlation values and you fit a simple quadratic to those three points and get the location of the "true" peak (with a fractional component) from that. it would always be withing 1/2 sample from the discrete peak. it's pretty simple. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●March 27, 20122012-03-27
On Tuesday, March 27, 2012 8:07:45 AM UTC-4, Andy wrote:> I have two signals y1[i] and y2[i]. > y2 is just a shifted and slightly scaled version of y1. > I want to find the optimal lag dt. > Using e.g. xcorr() in Matlab I can find the correlation between y1 and > y2 as a function of integer lag, > and then choose the lag with highest correlation value. > However I want to find the lag as a real number. > That is I want to interpolate y1 and y2 with e.g. polynomials and then > find the optimal lag between the interpolated signals. > How do I do this? > > My previous attempt used Savitzky Golay to find the derivative in each > point and then find peaks as zero crossings of the derivative. Having > found a peak in signal y1 I would then choose the closest peak in > signal y2 and use the shift between these two peaks as optimal lag. > This worked quite good as the optimal lag usually is quite small. > However sometimes it is larger and then I would like to also take into > account the shape of the signal around the peak; hence correlation. > Can I use Savitzky Golay to find optimal lag as a real number? > > Thanks in advance for any answers! > AndreasAndreas, Start with your 2 signals in the time domain (indexed in time) signal1 = {x1,x2,x3,...} signal2 = {y1,y2,y3,...} calculate the dft of each signal, yielding {X1,X2,X3,...} and {Y1,Y2,Y3,...} where these complex valued signals are indexed in frequency. then create a new signal, Z, (complex inner product where one half is conjugated) {Z1,Z2,Z3,...} = {X1^ * Y1, X2^ * Y2, X3^ *Y3,...} now create a vector of angles theta={arg(Z1), arg(Z2), arg(Z3),...} This is still a function of frequency. If you plot "theta" as a function of frequency, you get a straight line where the slope is the time offset and intercept is the frequency offset. You may use regression to find the best fit line to reduce the effects of noise. In doing the regression, you may even weight the data based upon the S/N per each frequency. Notice how this method does not require locating a peak on an autocorrelation curve. Also this is not affected by a frequency offset between one signal compared to the other - useful for received signals. The autocorrelation method does not separate time delay from the frequency offset effects in the two signals. IHTH, Clay
Reply by ●March 27, 20122012-03-27
On 3/27/12 1:53 PM, clay@claysturner.com wrote:> > Start with your 2 signals in the time domain (indexed in time) > > signal1 = {x1,x2,x3,...} > signal2 = {y1,y2,y3,...} >Clay, I know you're also a physicist and mathematician, but why would a self-respecting DSPer (who must also program to do DSP) count from 1? Edsger Dijkstra would not approve. http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html :-) sorry, it's just the never-ending battle against MATLAB and any other lingua that prefers counting from 1. i couldn't remember if you were on one side or the other. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●March 30, 20122012-03-30
On Wednesday, March 28, 2012 2:38:40 PM UTC-4, Mauritz Jameson wrote:> Here is a plot which shows the relationship between theta slope and > the delay. > > This relationship doesn't look simple. Am I doing something wrong? > > Click the following link and select "Click Here To Download From > SendSpace" to download the plot. > There is another "Download" link on the page, but that is an > advertisement...so don't click that! > > http://www.sendspace.com/file/49wqzcHi Mauritz, Sorry I didn't respoind earlier - I was travelling for work and in court (expert witness). I believe you have an error, but I don't do matlab so I can't point to a specific issue in your code. I'll put together a example showing how the whole process works. Clay
Reply by ●March 30, 20122012-03-30
On Friday, March 30, 2012 10:11:27 AM UTC-4, cl...@claysturner.com wrote:> On Wednesday, March 28, 2012 2:38:40 PM UTC-4, Mauritz Jameson wrote: > > Here is a plot which shows the relationship between theta slope and > > the delay. > > > > This relationship doesn't look simple. Am I doing something wrong? > > > > Click the following link and select "Click Here To Download From > > SendSpace" to download the plot. > > There is another "Download" link on the page, but that is an > > advertisement...so don't click that! > > > > http://www.sendspace.com/file/49wqzc > > Hi Mauritz, > > Sorry I didn't respoind earlier - I was travelling for work and in court (expert witness). I believe you have an error, but I don't do matlab so I can't point to a specific issue in your code. I'll put together a example showing how the whole process works. > > ClayHere is a detailed example showing how to find the time difference of arrival of two signals in the frequency domain. www.claysturner.com/tdoa.pdf IHTH, Clay
Reply by ●March 31, 20122012-03-31
> > Here is a detailed example showing how to find the time difference of arrival of two signals in the frequency domain. >Awesome Clay ...Thank you so much!
Reply by ●April 4, 20122012-04-04
On 3/27/2012 6:41 PM, robert bristow-johnson wrote:> On 3/27/12 1:53 PM, clay@claysturner.com wrote: >> >> Start with your 2 signals in the time domain (indexed in time) >> >> signal1 = {x1,x2,x3,...} >> signal2 = {y1,y2,y3,...} >> > > Clay, I know you're also a physicist and mathematician, but why would a > self-respecting DSPer (who must also program to do DSP) count from 1? > > Edsger Dijkstra would not approve. > > http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html > > > :-) > > sorry, it's just the never-ending battle against MATLAB and any other > lingua that prefers counting from 1. i couldn't remember if you were on > one side or the other. >Ever drive in England or Bermuda? Were you able to deal with it? Were the personal dangers so great that you refused to enter the zone? I don't know Robert, sometimes this argument tempts me to say "man up dudes". We have learned to deal with much more difficult problems over our lives. So why should we elevate this insoluble one? Yes, I assert "insoluble". I don't want to take sides; not because there are no merits but because I don't see progress being likely Don Q. I don't mean to be insulting, I understand that one might feel it important to sway the populace one person at a time and certainly to teach. As far as citing Dijkstra goes, well .. all of us have one time or another ranted about something fairly trivial. I have to wonder if this isn't the case here. Surely Dijkstra has made more important contributions. Looks a bit like technical one-upsmanship resulting from an academic disagreement with a misguided soul (and misguided in more than just counting conventions). But, I suppose it would be dangerous to suggest that he wasn't serious or that this little piece was done tongue-in-cheek. So, I surely won't suggest that. It is nicely done ...... Fred
Reply by ●April 4, 20122012-04-04
On Tue, 27 Mar 2012 21:41:43 -0400, robert bristow-johnson wrote:> On 3/27/12 1:53 PM, clay@claysturner.com wrote: >> >> Start with your 2 signals in the time domain (indexed in time) >> >> signal1 = {x1,x2,x3,...} >> signal2 = {y1,y2,y3,...} >> >> > Clay, I know you're also a physicist and mathematician, but why would a > self-respecting DSPer (who must also program to do DSP) count from 1? > > Edsger Dijkstra would not approve. > > http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html > > > :-) > > sorry, it's just the never-ending battle against MATLAB and any other > lingua that prefers counting from 1. i couldn't remember if you were on > one side or the other."In corporate religions as in others, the heretic must be cast out not because of the probability that he is wrong but because of the possibility that he is right." :) -- My liberal friends think I'm a conservative kook. My conservative friends think I'm a liberal kook. Why am I not happy that they have found common ground? Tim Wescott, Communications, Control, Circuits & Software http://www.wescottdesign.com






