-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 07/06/11 21:05, RNGolding@aol.com wrote: > Hi, not sure if this should be PIC or EE, but I have opted for PIC > =20 > I have an application where I need to measure the phase difference betwee= n =20 > two sine waves of same frequency. I'm using two zero crossing detectors t= o =20 > trigger the CCP1 and CCP2 inputs of a PIC. The CCP counter is clocked by= a=20 > PLL/VCO at 360 x the sine wave frequency, so the difference between the= =20 > CCP1 and CCP2 counts provides a direct phase measurement with a resoluti= on of=20 > 1 degree. > =20 > So far so good, however the sine waves have some jitter so I thought I =20 > would take the average of a few consecutive phase measurements. That is = where=20 > I come unstuck, how do you average phase readings? > =20 > To illustrate the problem, if the phase is jittering about zero degrees= =20 > giving 4 phase readings of say, 358, 359, 1 and 2 degrees, a simple aver= age=20 > calculation yields 180 deg, which is obviously wrong. Does anyone know h= ow=20 > calculate the true average, which should be 0 degrees? I'm sure the ans= wer=20 > is obvious, but it has defeated me so far.=20 > =20 > Richard Golding > =20 In DSP your problem is called phase-unwrapping. See http://www.dspguide.com/ch8/9.htm for an example when applied to a DFT or FFT. If you can guarantee that your real-world phase doesn't change by more than 180 deg between each sample you could test if | x[n-1] - x[n] | > 180 deg. If so you know you've jumped across the boundary and can adjust accordingly by adding 360 deg. Regards, Brendan -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk3uhwYACgkQHEhZ5Ws5poGJKwCeONWQGnVf35ezD1YpOLFs2J1w na0AoKU9+U1ewso5utV6QfzR+GufT/en =3DWw8h -----END PGP SIGNATURE----- --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .