# Re: [music-dsp] Clock drift and compensation

```Hi GM,

Thanks for the suggestion. Yes, it should work for sine tone kind of signals.```
```
I have this doubt on sampling and drift.

- Suppose transmitter is sampling a sine tone say  (Fin) 1KHz at 8kHZ (Fs)
sample rate.
This means 8 samples should correspond to one cycle of 1 kHz.

- Receiver is sampling at 7.999 kHz  because of drift in crystal,
but I'm thinking my receiver is having a sample rate of 8kHz and takes 8
samples for one cycle.
which gives  999.875 Hz and not 1kHz.

So, how to detect this drift and take only that many samples for the
in this case 7.999 samples corresponds to 1 kHz.

-ben

________________________________
From: music-dsp-boun...@music.columbia.edu
<music-dsp-boun...@music.columbia.edu> on behalf of gm <g...@voxangelica.net>
Sent: Monday, January 29, 2018 1:29 AM
To: music-dsp@music.columbia.edu
Subject: Re: [music-dsp] Clock drift and compensation

diff gives you the phase step per sample,
basically the frequency.

However the phase will jump back to zero periodically when the phase exceeds
360°
(when it wraps around) in this case diff will get you a wrong result.

So you need to "unwrap" the phase or the phase difference, for example:

diff = phase_new - phase_old
if phase_old > Pi and phase_new < Pi then diff += 2Pi

or similar.

Am 28.01.2018 um 17:19 schrieb Benny Alexandar:
Hi GM,

>> HT -> Atan2 -> differenciate -> unwrap
Could you please explain how to find the drift using HT,

HT -> gives real(I) & imaginary (Q) components of real signal
Atan2 -> the phase of an I Q signal
diff-> gives what ?
unwrap ?

-ben

________________________________
From:
music-dsp-boun...@music.columbia.edu<mailto:music-dsp-boun...@music.columbia.edu>

<music-dsp-boun...@music.columbia.edu><mailto:music-dsp-boun...@music.columbia.edu>
on behalf of gm <g...@voxangelica.net><mailto:g...@voxangelica.net>
Sent: Saturday, January 27, 2018 5:20 PM
To: music-dsp@music.columbia.edu<mailto:music-dsp@music.columbia.edu>
Subject: Re: [music-dsp] Clock drift and compensation

I don't understand your project at all so not sure if this is helpful,
probably not,
but you can calculate the drift or instantanous frequency of a sine wave
on a per sample basis
using a Hilbert transform
HT -> Atan2 -> differenciate -> unwrap
_______________________________________________
dupswapdrop: music-dsp mailing list
music-dsp@music.columbia.edu<mailto:music-dsp@music.columbia.edu>
https://lists.columbia.edu/mailman/listinfo/music-dsp

```
```_______________________________________________
dupswapdrop: music-dsp mailing list
music-dsp@music.columbia.edu
https://lists.columbia.edu/mailman/listinfo/music-dsp```