time-nuts@lists.febo.com

Discussion of precise time and frequency measurement

View all threads

ADC sample voting algorithm?

NS
Nick Sayer
Wed, Oct 5, 2016 11:45 PM

This is tangentially on topic, I suppose. It’s for my GPSDO.

I notice periodically that the phase measurements seem “noisy.” You can see that over the course of several seconds the value doesn’t change, then it jumps a bunch and then comes right back.

My theory at the moment is that sampling the ADC multiple times in a row might help, but then what’s the best way to (quickly) pick which sample to use?

The mean would allow a bad sample undue influence.

At the moment, I’ve coded taking 3 samples, averaging them and picking the sample that is closest to the mean. If I’m right, and two of the samples happen to be very close to each other and a third is an outlier, then that seems like it would eliminate it.

I guess what I want is the mode, but with 3 samples, that’s going to be poorly defined (if at all).

Anyone have any suggestions (besides a larger sample size)?

This is tangentially on topic, I suppose. It’s for my GPSDO. I notice periodically that the phase measurements seem “noisy.” You can see that over the course of several seconds the value doesn’t change, then it jumps a bunch and then comes right back. My theory at the moment is that sampling the ADC multiple times in a row might help, but then what’s the best way to (quickly) pick which sample to use? The mean would allow a bad sample undue influence. At the moment, I’ve coded taking 3 samples, averaging them and picking the sample that is closest to the mean. If I’m right, and two of the samples happen to be very close to each other and a third is an outlier, then that seems like it would eliminate it. I guess what I want is the mode, but with 3 samples, that’s going to be poorly defined (if at all). Anyone have any suggestions (besides a larger sample size)?
BS
Bob Stewart
Wed, Oct 5, 2016 11:52 PM

Hi Nick,
Are you applying sawtooth correction to your phase measurement?  If not, are you merely seeing a hanging bridge that dissolves into at a normal sort of tick-tock movement?
Bob

  From: Nick Sayer via time-nuts <time-nuts@febo.com>

To: Discussion of precise time and frequency measurement time-nuts@febo.com
Sent: Wednesday, October 5, 2016 6:45 PM
Subject: [time-nuts] ADC sample voting algorithm?

This is tangentially on topic, I suppose. It’s for my GPSDO.

I notice periodically that the phase measurements seem “noisy.” You can see that over the course of several seconds the value doesn’t change, then it jumps a bunch and then comes right back.

My theory at the moment is that sampling the ADC multiple times in a row might help, but then what’s the best way to (quickly) pick which sample to use?

The mean would allow a bad sample undue influence.

At the moment, I’ve coded taking 3 samples, averaging them and picking the sample that is closest to the mean. If I’m right, and two of the samples happen to be very close to each other and a third is an outlier, then that seems like it would eliminate it.

I guess what I want is the mode, but with 3 samples, that’s going to be poorly defined (if at all).

Anyone have any suggestions (besides a larger sample size)?


time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.

Hi Nick, Are you applying sawtooth correction to your phase measurement?  If not, are you merely seeing a hanging bridge that dissolves into at a normal sort of tick-tock movement? Bob From: Nick Sayer via time-nuts <time-nuts@febo.com> To: Discussion of precise time and frequency measurement <time-nuts@febo.com> Sent: Wednesday, October 5, 2016 6:45 PM Subject: [time-nuts] ADC sample voting algorithm? This is tangentially on topic, I suppose. It’s for my GPSDO. I notice periodically that the phase measurements seem “noisy.” You can see that over the course of several seconds the value doesn’t change, then it jumps a bunch and then comes right back. My theory at the moment is that sampling the ADC multiple times in a row might help, but then what’s the best way to (quickly) pick which sample to use? The mean would allow a bad sample undue influence. At the moment, I’ve coded taking 3 samples, averaging them and picking the sample that is closest to the mean. If I’m right, and two of the samples happen to be very close to each other and a third is an outlier, then that seems like it would eliminate it. I guess what I want is the mode, but with 3 samples, that’s going to be poorly defined (if at all). Anyone have any suggestions (besides a larger sample size)? _______________________________________________ time-nuts mailing list -- time-nuts@febo.com To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts and follow the instructions there.
BC
Bob Camp
Thu, Oct 6, 2016 12:00 AM

Hi

What does the signal you are sampling look like?

Does it (maybe) have a bit of noise on it?

If it is the output of a “normal” TDC, then the answer is to sample once.

Bob

On Oct 5, 2016, at 7:45 PM, Nick Sayer via time-nuts time-nuts@febo.com wrote:

This is tangentially on topic, I suppose. It’s for my GPSDO.

I notice periodically that the phase measurements seem “noisy.” You can see that over the course of several seconds the value doesn’t change, then it jumps a bunch and then comes right back.

My theory at the moment is that sampling the ADC multiple times in a row might help, but then what’s the best way to (quickly) pick which sample to use?

The mean would allow a bad sample undue influence.

At the moment, I’ve coded taking 3 samples, averaging them and picking the sample that is closest to the mean. If I’m right, and two of the samples happen to be very close to each other and a third is an outlier, then that seems like it would eliminate it.

I guess what I want is the mode, but with 3 samples, that’s going to be poorly defined (if at all).

Anyone have any suggestions (besides a larger sample size)?


time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.

Hi What does the signal you are sampling look like? Does it (maybe) have a bit of noise on it? If it is the output of a “normal” TDC, then the answer is to sample once. Bob > On Oct 5, 2016, at 7:45 PM, Nick Sayer via time-nuts <time-nuts@febo.com> wrote: > > This is tangentially on topic, I suppose. It’s for my GPSDO. > > I notice periodically that the phase measurements seem “noisy.” You can see that over the course of several seconds the value doesn’t change, then it jumps a bunch and then comes right back. > > My theory at the moment is that sampling the ADC multiple times in a row might help, but then what’s the best way to (quickly) pick which sample to use? > > The mean would allow a bad sample undue influence. > > At the moment, I’ve coded taking 3 samples, averaging them and picking the sample that is closest to the mean. If I’m right, and two of the samples happen to be very close to each other and a third is an outlier, then that seems like it would eliminate it. > > I guess what I want is the mode, but with 3 samples, that’s going to be poorly defined (if at all). > > Anyone have any suggestions (besides a larger sample size)? > _______________________________________________ > time-nuts mailing list -- time-nuts@febo.com > To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts > and follow the instructions there.
NS
Nick Sayer
Thu, Oct 6, 2016 12:22 AM

On Oct 5, 2016, at 5:00 PM, Bob Camp kb8tq@n1k.org wrote:

Hi

What does the signal you are sampling look like?

The last time I actually looked (it was a while ago), it looked reasonable as closely as I could look, but the ADC resolution is something like 1mV per LSB, and I’m not sure I looked that closely.

Does it (maybe) have a bit of noise on it?

If it is the output of a “normal” TDC, then the answer is to sample once.

I dunno about a “normal” one… This one is the one I got from Jim Harman. The phase difference between the divided-by-10 output and PPS goes through a diode, JFET and then an RC (with a much higher discharge resistor).

As long as you sample at least 1 µs after the PPS (and it takes at least that long to get into the ISR anyway), it ought to be stable for dozens of µs.

That’s kind of why I’m going down the road of multiple samples - to see if there’s anything to it.

> On Oct 5, 2016, at 5:00 PM, Bob Camp <kb8tq@n1k.org> wrote: > > Hi > > What does the signal you are sampling look like? The last time I actually looked (it was a while ago), it looked reasonable as closely as I could look, but the ADC resolution is something like 1mV per LSB, and I’m not sure I looked that closely. > > Does it (maybe) have a bit of noise on it? > > If it is the output of a “normal” TDC, then the answer is to sample once. I dunno about a “normal” one… This one is the one I got from Jim Harman. The phase difference between the divided-by-10 output and PPS goes through a diode, JFET and then an RC (with a much higher discharge resistor). As long as you sample at least 1 µs after the PPS (and it takes at least that long to get into the ISR anyway), it *ought* to be stable for dozens of µs. That’s kind of why I’m going down the road of multiple samples - to see if there’s anything to it.
BC
Bob Camp
Thu, Oct 6, 2016 12:54 AM

Hi

If you are looking at a high impedance source with a “normal” ADC, you need a buffer amp.

If you have a signal that decays, it is generally not a good idea to toss all the samples into a
single bucket. You probably need to do some sort of slope estimation.

The still better solution is to get an ADC that is not super noisy. Most built in ADC’s on
MCU’s are quite noisy when evaluated against their claimed resolution level. Even with a few
thousand samples, this may not improve as much as you would wish for.

Better still, use a converter with a fast enough slope that the ADC noise is not an issue.

Bob

On Oct 5, 2016, at 8:22 PM, Nick Sayer via time-nuts time-nuts@febo.com wrote:

On Oct 5, 2016, at 5:00 PM, Bob Camp kb8tq@n1k.org wrote:

Hi

What does the signal you are sampling look like?

The last time I actually looked (it was a while ago), it looked reasonable as closely as I could look, but the ADC resolution is something like 1mV per LSB, and I’m not sure I looked that closely.

Does it (maybe) have a bit of noise on it?

If it is the output of a “normal” TDC, then the answer is to sample once.

I dunno about a “normal” one… This one is the one I got from Jim Harman. The phase difference between the divided-by-10 output and PPS goes through a diode, JFET and then an RC (with a much higher discharge resistor).

As long as you sample at least 1 µs after the PPS (and it takes at least that long to get into the ISR anyway), it ought to be stable for dozens of µs.

That’s kind of why I’m going down the road of multiple samples - to see if there’s anything to it.


time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.

Hi If you are looking at a high impedance source with a “normal” ADC, you need a buffer amp. If you have a signal that decays, it is generally not a good idea to toss all the samples into a single bucket. You probably need to do some sort of slope estimation. The still better solution is to get an ADC that is not super noisy. Most built in ADC’s on MCU’s are quite noisy when evaluated against their claimed resolution level. Even with a few thousand samples, this may not improve as much as you would wish for. Better still, use a converter with a fast enough slope that the ADC noise is not an issue. Bob > On Oct 5, 2016, at 8:22 PM, Nick Sayer via time-nuts <time-nuts@febo.com> wrote: > > >> On Oct 5, 2016, at 5:00 PM, Bob Camp <kb8tq@n1k.org> wrote: >> >> Hi >> >> What does the signal you are sampling look like? > > The last time I actually looked (it was a while ago), it looked reasonable as closely as I could look, but the ADC resolution is something like 1mV per LSB, and I’m not sure I looked that closely. > >> >> Does it (maybe) have a bit of noise on it? >> >> If it is the output of a “normal” TDC, then the answer is to sample once. > > I dunno about a “normal” one… This one is the one I got from Jim Harman. The phase difference between the divided-by-10 output and PPS goes through a diode, JFET and then an RC (with a much higher discharge resistor). > > As long as you sample at least 1 µs after the PPS (and it takes at least that long to get into the ISR anyway), it *ought* to be stable for dozens of µs. > > That’s kind of why I’m going down the road of multiple samples - to see if there’s anything to it. > > > _______________________________________________ > time-nuts mailing list -- time-nuts@febo.com > To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts > and follow the instructions there.
SS
Scott Stobbe
Thu, Oct 6, 2016 1:05 AM

It sounds like once in awhile your sampling something else too. Ground
bounce of a 10 MHz buffer, or something coupling onto your phase detector,
or running your adc at the edge of a timing spec?

How large would the outlier be in mV?

On Wednesday, 5 October 2016, Nick Sayer via time-nuts time-nuts@febo.com
wrote:

This is tangentially on topic, I suppose. It’s for my GPSDO.

I notice periodically that the phase measurements seem “noisy.” You can
see that over the course of several seconds the value doesn’t change, then
it jumps a bunch and then comes right back.

My theory at the moment is that sampling the ADC multiple times in a row
might help, but then what’s the best way to (quickly) pick which sample to
use?

The mean would allow a bad sample undue influence.

At the moment, I’ve coded taking 3 samples, averaging them and picking the
sample that is closest to the mean. If I’m right, and two of the samples
happen to be very close to each other and a third is an outlier, then that
seems like it would eliminate it.

I guess what I want is the mode, but with 3 samples, that’s going to be
poorly defined (if at all).

Anyone have any suggestions (besides a larger sample size)?


time-nuts mailing list -- time-nuts@febo.com javascript:;
To unsubscribe, go to https://www.febo.com/cgi-bin/
mailman/listinfo/time-nuts
and follow the instructions there.

It sounds like once in awhile your sampling something else too. Ground bounce of a 10 MHz buffer, or something coupling onto your phase detector, or running your adc at the edge of a timing spec? How large would the outlier be in mV? On Wednesday, 5 October 2016, Nick Sayer via time-nuts <time-nuts@febo.com> wrote: > This is tangentially on topic, I suppose. It’s for my GPSDO. > > I notice periodically that the phase measurements seem “noisy.” You can > see that over the course of several seconds the value doesn’t change, then > it jumps a bunch and then comes right back. > > My theory at the moment is that sampling the ADC multiple times in a row > might help, but then what’s the best way to (quickly) pick which sample to > use? > > The mean would allow a bad sample undue influence. > > At the moment, I’ve coded taking 3 samples, averaging them and picking the > sample that is closest to the mean. If I’m right, and two of the samples > happen to be very close to each other and a third is an outlier, then that > seems like it would eliminate it. > > I guess what I want is the mode, but with 3 samples, that’s going to be > poorly defined (if at all). > > Anyone have any suggestions (besides a larger sample size)? > _______________________________________________ > time-nuts mailing list -- time-nuts@febo.com <javascript:;> > To unsubscribe, go to https://www.febo.com/cgi-bin/ > mailman/listinfo/time-nuts > and follow the instructions there. >
JH
Jim Harman
Thu, Oct 6, 2016 1:31 AM

On Wed, Oct 5, 2016 at 7:45 PM, Nick Sayer via time-nuts <time-nuts@febo.com

wrote:

I notice periodically that the phase measurements seem “noisy.” You can
see that over the course of several seconds the value doesn’t change, then
it jumps a bunch and then comes right back.

Hi Nick,

At one point I had a problem with noisy phase readings where the "noise"
took the form of an occasional reading that was low by up to about 50
counts. These events were quite rare - less often than once per hour on
average. After much head-scratching, it turned out that I had an interrupt
conflict that sometimes caused the PPS interrupt to be delayed, Because the
ADC was triggered inside this routine, the analog signal had drooped a
little before the ADC was triggered.

I was able to completely solve this by setting up the ADC sample/hold and
conversion to be triggered directly by the PPS signal, thus eliminating any
dependency on the interrupt latency. The PPS still generates an interrupt,
but in the interrupt routine, all I have to do is wait for the ADC to
finish, clear the Done bit, and reset the trigger.

--

--Jim Harman

On Wed, Oct 5, 2016 at 7:45 PM, Nick Sayer via time-nuts <time-nuts@febo.com > wrote: > I notice periodically that the phase measurements seem “noisy.” You can > see that over the course of several seconds the value doesn’t change, then > it jumps a bunch and then comes right back. > Hi Nick, At one point I had a problem with noisy phase readings where the "noise" took the form of an occasional reading that was low by up to about 50 counts. These events were quite rare - less often than once per hour on average. After much head-scratching, it turned out that I had an interrupt conflict that sometimes caused the PPS interrupt to be delayed, Because the ADC was triggered inside this routine, the analog signal had drooped a little before the ADC was triggered. I was able to completely solve this by setting up the ADC sample/hold and conversion to be triggered directly by the PPS signal, thus eliminating any dependency on the interrupt latency. The PPS still generates an interrupt, but in the interrupt routine, all I have to do is wait for the ADC to finish, clear the Done bit, and reset the trigger. -- --Jim Harman
PK
Poul-Henning Kamp
Thu, Oct 6, 2016 7:08 AM

In message 59AB451C-CA1B-4824-A953-4F0F28B66AAC@kfu.com, Nick Sayer via time-nuts writes:

My theory at the moment is that sampling the ADC multiple times in a row might help, but then what’s the best way to (quickly) pick which sample to use?

If you are sampling for noise:  Always the median.

--
Poul-Henning Kamp      | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG        | TCP/IP since RFC 956
FreeBSD committer      | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.

-------- In message <59AB451C-CA1B-4824-A953-4F0F28B66AAC@kfu.com>, Nick Sayer via time-nuts writes: >My theory at the moment is that sampling the ADC multiple times in a row might help, but then what’s the best way to (quickly) pick which sample to use? If you are sampling for noise: Always the median. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence.
A
Angus
Thu, Oct 6, 2016 7:34 AM

Hi,

You may have already done this, but if you log the same pulses with a
counter or actual TDC IC you can view it and see how they compare with
your measurements.
Then you can look at how to get them closer - or find that it's
actually correct and that's just where the pulse is at the time.

Angus.

On Wed, 5 Oct 2016 16:45:21 -0700, you wrote:

This is tangentially on topic, I suppose. It’s for my GPSDO.

I notice periodically that the phase measurements seem “noisy.” You can see that over the course of several seconds the value doesn’t change, then it jumps a bunch and then comes right back.

My theory at the moment is that sampling the ADC multiple times in a row might help, but then what’s the best way to (quickly) pick which sample to use?

The mean would allow a bad sample undue influence.

At the moment, I’ve coded taking 3 samples, averaging them and picking the sample that is closest to the mean. If I’m right, and two of the samples happen to be very close to each other and a third is an outlier, then that seems like it would eliminate it.

I guess what I want is the mode, but with 3 samples, that’s going to be poorly defined (if at all).

Anyone have any suggestions (besides a larger sample size)?


time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.

Hi, You may have already done this, but if you log the same pulses with a counter or actual TDC IC you can view it and see how they compare with your measurements. Then you can look at how to get them closer - or find that it's actually correct and that's just where the pulse is at the time. Angus. On Wed, 5 Oct 2016 16:45:21 -0700, you wrote: >This is tangentially on topic, I suppose. It’s for my GPSDO. > >I notice periodically that the phase measurements seem “noisy.” You can see that over the course of several seconds the value doesn’t change, then it jumps a bunch and then comes right back. > >My theory at the moment is that sampling the ADC multiple times in a row might help, but then what’s the best way to (quickly) pick which sample to use? > >The mean would allow a bad sample undue influence. > >At the moment, I’ve coded taking 3 samples, averaging them and picking the sample that is closest to the mean. If I’m right, and two of the samples happen to be very close to each other and a third is an outlier, then that seems like it would eliminate it. > >I guess what I want is the mode, but with 3 samples, that’s going to be poorly defined (if at all). > >Anyone have any suggestions (besides a larger sample size)? >_______________________________________________ >time-nuts mailing list -- time-nuts@febo.com >To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts >and follow the instructions there.