DSPRelated.com
Forums

Sampling: What Nyquist Didn't Say, and What to Do About It

Started by Tim Wescott December 20, 2010
Tim Wescott wrote:
> On 12/20/2010 10:30 AM, Les Cargill wrote: >> John Larkin wrote: >>> On Mon, 20 Dec 2010 12:03:37 -0500, Randy Yates<yates@ieee.org> >>> wrote: >>> >>>> On 12/20/2010 11:46 AM, John Larkin wrote: >>>>> [...] >>>>> I sold a couple hundred thousand channels of an AC power meter, used >>>>> for utility end-use surveys, that sampled the power line voltage and >>>>> current signals at 27 Hz. I had a hell of a time arguing with >>>>> "Nyquist" theorists who claimed I should be sampling at twice the >>>>> frequency of the highest line harmonic, like the 15th maybe. >>>> >>>> John, >>>> >>>> If your AC signal had more than 13.5 Hz of bandwidth, how were you >>>> able to accurately sample them at 27 Hz? As far as I know, even >>>> subsampling assumes the _bandwidth_ is less than half the sample rate >>>> (for real sampling). >>> >>> Read Tim's paper! >>> >>> The thing about an electric meter is that you're not trying to >>> reconstruct the waveform, you're only gathering statistics on it. The >>> 27.xxx Hz sample rate was chosen so that its harmonics would dance >>> between the line harmonics up to some highish harmonic of 60 Hz, so as >>> to not create any slow-wobble aliases in the reported values (trms >>> volts, amps, power, PF) that would uglify the local realtime display >>> or the archived time-series records. >>> >> >> Is this something like heterodyning, then? You're building a detector, >> not a ... recorder. Right? > > Pretty much -- read my paper! >
No, I gotcha - I just wasn't thinking in terms of conversion to an... "IF regime" for line voltage measurements!
> You're taking advantage of the fact that the signal you're acquiring is > very cyclic in character. So (for instance), instead of taking samples > every 1/600 seconds, you could take samples every 1/60 + 1/600 seconds, > and get the _effect_ of taking samples faster. > > John chose a frequency that would let him get decent statistics faster > and more reliably, but he's just building on the basic idea that I present. >
Nice paper, BTW. -- Les Cargill
On Mon, 20 Dec 2010 08:14:31 -0800, Tim Wescott <tim@seemywebsite.com>
wrote:

>On 12/20/2010 03:30 AM, Anton Erasmus wrote: >> On Mon, 20 Dec 2010 01:34:44 -0600, Tim Wescott<tim@seemywebsite.com> >> wrote: >> >>> I know there's a few people out there who actually read the papers that I >>> post on my web site. >>> >>> I also know that the papers have gotten a bit ragged, and that I haven't >>> been maintaining them. >>> >>> So here: I've made a start. >>> >>> http://www.wescottdesign.com/articles/Sampling/sampling.pdf >>> >>> My intent (with apologies to all of you with dial-up), is to convert the >>> ratty HTML documents to pdf as time permits, and in a way that leaves the >>> documents easily maintainable and in a form that is easy to look at from >>> the web or to print out, as you desire. >> >> The fonts are terrible. They seem to be bitmap fonts and not vector. >> It looks like you used TeX to generate the document. Go to >> http://www.truetex.com/ for links to quite number of articles on >> how to use truetype fonts in TeX. > >What reader were you using? I'm trying to figure out (a) why some >people think it looks peachy and some think it looks terrible (it looks >great on Evince), and (b) make sure I test it on enough different >readers that I get a true picture of what it looks like to the world at >large.
I used Acrobat Pro 9 on Windows XP. Acroreader 9 on OpenSuse also looks terrible. Looks fine in Evince on the same machine. So it looks like it is Acrobat. Unfortunately that is one PDF Viewer it has to look nice on. Regards Anton Erasmus
On Mon, 20 Dec 2010 19:38:01 +0000 (UTC), glen herrmannsfeldt
<gah@ugcs.caltech.edu> wrote:

>In comp.dsp Randy Yates <yates@ieee.org> wrote: > >(snip) > >> What does concern me, however, is some of the theory you've presented. >> Specifically, this section on p.11: > >> Sampling at some frequency that is equal to the repetition rate >> divided by a prime number will automatically stack these narrow bits >> of signal spectrum right up in the same order that they were in the >> original signal, only jammed much closer together in frequency which >> is the roundabout frequency-domain way of saying that you can sample >> at just the right rate, and interpret the resulting signal as a >> slowed-down replica of the input waveform. > >> There are two points in which I challenge the veracity of your assertions: > >> 1. Sampling at a rate of F/N when N is integer will never help >> subsample a signal since the period of the sampling, N/F, is always a >> multiple of the repetition rate period 1/F. > >One has to choose carefully. > >> 2. It seems that to truely, completely sample a repetitive signal in >> such a way, you would need a sampling period that will never be a >> multiple of the repetition period. For example, for the 60 Hz example >> you could use a sample rate of 60 Hz / sqrt(2). But then, even if you >> sample at such a rate, it would take an INFINITE amount of time to >> fully sample this signal. It's equivalent to sampling an interval on >> the real line a point at a time; real analysis tells us that there are >> an uncountably infinite number of points in such an interval! > >That would be true for signals with infinite bandwidth. At least >for the AC power meter, you won't have that. Harmonics from SCR >(or triac) based light dimmers likely get into the MHz range, so >one should be able to see that far. The usual computer power >supply is a voltage double off the AC line, which shouldn't be >as bad as the SCR, but still has significant harmonics. > >But as was previously said, the goal is not to sample the 60Hz >waveform, but, as used in describing modulated signals, the envelope. > >> So, I'm afraid I cannot agree that an accurate sampling of a repetitive >> waveform can be made in this manner. If you disagree, please show me >> where my reasoning is wrong. > >If one sample 60Hz power usage at 60Hz, one would lose much important >information. At 27Hz, where do the aliases end up? > >60Hz --> 6Hz >120Hz --> 12Hz >180Hz --> -9Hz >240Hz --> -3Hz >300Hz --> 3Hz >360Hz --> 9Hz >420Hz --> -12Hz >480Hz --> -6Hz >540Hz --> 0Hz > >It seems that you don't want exactly 27Hz, maybe that is >what he said previously.
I used 26.99947. I wrote a horrible Basic program that explored the possible selections of available crystals, divided IRQ rates, divided channel rates (16 channels), and possible aliases of the sample rate against line harmonics. All against a guess about avaliable compute power. It was one of those ill-posed problems with no hard quality metric, just a guess as to which solution felt better.
> >What you want to measure, though, is the RMS power over some >period of time, taking into account the significant harmonics.
The current harmonics have no real power, at least as long as the voltage waveform is sinusoidal, which it usually sort of is.
> >Now, say you have a signal with harmonics up to a few MHz, >and say, for example, that one of those aliases to 0Hz, and >so you don't see. How much of a problem is that? If you have >all the floor(1000000/60) harmonics up to that point, then you >are likely pretty close.
Most power people are only concerned with the 10th or maybe 15th harmonic.
> >Floor(1000000/60) is 16666, so if you sample at 1000000/16666, >for a sampling rate of 60.0024... Hz. If you want something >near 27Hz that doesn't have harmonics that are multiples of 60 >until 1000020, then it looks like 27.000027Hz is about right. > >It seems to me that you pick the harmonic that you can afford >not to see, and plan the sampling rate accordingly. > >However, as that is getting close to crystal tolerance, I might >suggest that phase locking to a multple of 60Hz, and then dividing >down would be a good way to generate the sampling clock.
Fun, but overkill. The line voltage and currents are constantly jumping around anyhow. John
In comp.dsp John Larkin <jjlarkin@highnotlandthistechnologypart.com> wrote:
(snip)

> It records rms volts, amps, power, but doesn't try to reconstruct the > raw waveforms; so the Sampling Theorem doesn't apply. That didn't stop > all sorts of people from arguing that the sample rate had to be twice > that of the highest reasonable AC line harmonic. As Tim says, lots of > people fling "Nyquist Rate" around without really thinking about it.
I remember a story in an undergrad quantum mechanics class about some radar designers that believe that Heisenberg uncertainty applied to the returning radar reflection.
> If the voltage waveform is a sine wave (which it pretty much is) then > there's no energy in the current harmonics anyhow.
Unless the source impedance is too high, such as it might be at the end of a long extension cord with small wire. If you have 1/n harmonic distribution, as from a square wave or from an SCR light dimmer, then you can figure how many harmonics you need from the error tolerance. I might have wanted to go to 1MHz, but 256*60 isn't so far off. -- glen
In comp.dsp John Larkin <jjlarkin@highnotlandthistechnologypart.com> wrote:
(snip, I wrote harmonics up to...)

>>480Hz --> -6Hz >>540Hz --> 0Hz
>>It seems that you don't want exactly 27Hz, maybe that is >>what he said previously.
> I used 26.99947. I wrote a horrible Basic program that explored the > possible selections of available crystals, divided IRQ rates, divided > channel rates (16 channels), and possible aliases of the sample rate > against line harmonics. All against a guess about avaliable compute > power. It was one of those ill-posed problems with no hard quality > metric, just a guess as to which solution felt better.
It is supposed to be that the most popular crystal is 3579545Hz, as needed for NTSC color TV demodulation. That isn't likely to be a nice multiple of other common frequencies. (Maybe now that analog broadcasting has ceased, the crystals will be harder to find.)
>>What you want to measure, though, is the RMS power over some >>period of time, taking into account the significant harmonics.
> The current harmonics have no real power, at least as long as the > voltage waveform is sinusoidal, which it usually sort of is.
That sounds right. Though I do remember an undergrad physics lab where we looked at the power line with an oscilloscope. It seems that they had a voltage regulating transformer with a large third harmonic. Not so common, though.
>>Now, say you have a signal with harmonics up to a few MHz, >>and say, for example, that one of those aliases to 0Hz, and >>so you don't see. How much of a problem is that? If you have >>all the floor(1000000/60) harmonics up to that point, then you >>are likely pretty close.
> Most power people are only concerned with the 10th or maybe 15th > harmonic.
I suppose that sound right. The reason to be concerned with the higher ones is the effect on AM radios, but the actual power is pretty low. (snip)
>>However, as that is getting close to crystal tolerance, I might >>suggest that phase locking to a multple of 60Hz, and then dividing >>down would be a good way to generate the sampling clock.
> Fun, but overkill. The line voltage and currents are constantly > jumping around anyhow.
I was thinking that the PLL might be cheaper than a crystal, but maybe not, and maybe it doesn't matter much. 27Hz is far enough that you don't have to worry about low harmonics even if the crystal is a little off. -- glen
On Mon, 20 Dec 2010 13:02:30 -0500, Randy Yates <yates@ieee.org> wrote:

>On 12/20/2010 12:48 PM, Eric Jacobsen wrote: >> [...] >> I'm using Adobe Reader 9 and it looks fine here, even blown way up. > >Ha! Interesting... > >What may be happening is that some font is not embedded, and that if >you don't have the TeX fonts installed, the reader is substituting a >postscript font, which is vector, so it looks fine. But if you do >have TeX fonts on your system, you get them rendered as bitmaps.
Nope, looks like it's a Lyx problem (1.6.7 here). A quickie foo.tex with a minimal header (just \documentclass{article}, \usepackage{amsmath}, and \begin{document}) produces peachy (vector) output when run from the command line through "latex foo.tex" then "dvipdfm foo.dvi" or straight to pdf with "pdflatex foo.tex". However, the Lyx output, when exported with any of its three pdf options, produces the blocky bitmap-style typefaces. TeXnic Center's GUI did okay (more peachy output). Didn't try any of the other GUI wrappers. -- Rich Webb Norfolk, VA
On 2010-12-20, D Yuniskis <not.going.to.be@seen.com> wrote:

>> I don't see anything at all wrong with the font. The one thing that I >> would change is the line length. It looks like a typical line is >> upwards of 110 characters. That's a bit too much to read comfortably. >> If you want to use a font that small, and don't want wide margins, I'd >> recommend going to a two-column format. > ><frown> I agree with your point re: line length. But, I adopted > a two column format (3/8" gutter) years ago when I started my > "notes" series. It *really* complicates layout.
Unfortunately, that's true. If you have a lot of full-width diagrams or listings, you sort of end up picking your pain. Either the layout is choppy and difficult to manage, lines are too long, or you end up wasting a lot of paper using wider margins and a larger font.
> You end up having to create lots of "page width" boxes anchored to > your text. This ends up breaking up the text columns A LOT. > Especially if you have lots of illustrations, tables, etc. > > For example, putting code snippets in-line constrains the length of > each code line severely (unless you go to the page wide boxes). > ><shrug> So far, I've not had to resort to "rotated pages" but that's > only because I've been aggressive at keeping tables, illustrations, > etc. tightly bound. :-/
I know what you mean. -- Grant
On 2010-12-20, David Brown <david.brown@removethis.hesbynett.no> wrote:
> On 20/12/10 17:57, Grant Edwards wrote: >> On 2010-12-20, Cesar Rabak<csrabak@bol.com.br> wrote: >>> Em 20/12/2010 05:34, Tim Wescott escreveu: >>>> I know there's a few people out there who actually read the papers that I >>>> post on my web site. >>>> >>>> I also know that the papers have gotten a bit ragged, and that I haven't >>>> been maintaining them. >>>> >>>> So here: I've made a start. >>>> >>>> http://www.wescottdesign.com/articles/Sampling/sampling.pdf >>>> >>>> My intent (with apologies to all of you with dial-up), is to convert the >>>> ratty HTML documents to pdf as time permits, and in a way that leaves the >>>> documents easily maintainable and in a form that is easy to look at from >>>> the web or to print out, as you desire. >>> >>> I gave a diagonal look at the paper, as I got curious about the >>> complaints on the font. They look OK to me :-) I'm used to read math's >>> articles written in CMR fonts so perhaps I'm not a good judge on this. >> >> I don't see anything at all wrong with the font. The one thing that I >> would change is the line length. It looks like a typical line is >> upwards of 110 characters. That's a bit too much to read comfortably. >> If you want to use a font that small, and don't want wide margins, I'd >> recommend going to a two-column format. > > I agree that the line width is /slightly/ too wide for comfort, but I'd > avoid two-column format unless I were trying to save the last few trees > on the planet.
[...]
> If we are going to nit-pick on the typography (which seems a little > unfair, given that it is vastly better than in most papers),
Oh, I agree. The typography is certainly better than 99+ percent of what's out there, so we are indeed picking nits.
> I still haven't got round to reading the document itself - I hope the > contents are worth the effort in the presentation!
I've read parts of it, but the only thing I felt qualified to comment on was the typesetting. :)
Hi Grant,

On 12/20/2010 7:25 PM, Grant Edwards wrote:
> On 2010-12-20, D Yuniskis<not.going.to.be@seen.com> wrote: > >>> I don't see anything at all wrong with the font. The one thing that I >>> would change is the line length. It looks like a typical line is >>> upwards of 110 characters. That's a bit too much to read comfortably. >>> If you want to use a font that small, and don't want wide margins, I'd >>> recommend going to a two-column format. >> >> <frown> I agree with your point re: line length. But, I adopted >> a two column format (3/8" gutter) years ago when I started my >> "notes" series. It *really* complicates layout. > > Unfortunately, that's true. If you have a lot of full-width diagrams > or listings, you sort of end up picking your pain. Either the layout > is choppy and difficult to manage, lines are too long, or you end up > wasting a lot of paper using wider margins and a larger font.
I think there is some magic ratio of text to graphics (treating tables as graphics) that you must exceed in order for there to be enough text to flow around the graphics. I think you can probably cheat -- a little -- by using 3/4 wide tables/graphics. I.e., break one column and let the other column flow around it. But, that presumes you won't have a graphic sitting in that "other" column, too. :< Or, resort to tiny text, etc. in any inserts. <frown>
On Mon, 20 Dec 2010 22:41:25 +0200, Anton Erasmus
<nobody@spam.prevent.net> wrote:

>On Mon, 20 Dec 2010 08:14:31 -0800, Tim Wescott <tim@seemywebsite.com> >wrote: > >>On 12/20/2010 03:30 AM, Anton Erasmus wrote: >>> On Mon, 20 Dec 2010 01:34:44 -0600, Tim Wescott<tim@seemywebsite.com> >>> wrote: >>> >>>> I know there's a few people out there who actually read the papers that I >>>> post on my web site. >>>> >>>> I also know that the papers have gotten a bit ragged, and that I haven't >>>> been maintaining them. >>>> >>>> So here: I've made a start. >>>> >>>> http://www.wescottdesign.com/articles/Sampling/sampling.pdf >>>> >>>> My intent (with apologies to all of you with dial-up), is to convert the >>>> ratty HTML documents to pdf as time permits, and in a way that leaves the >>>> documents easily maintainable and in a form that is easy to look at from >>>> the web or to print out, as you desire. >>> >>> The fonts are terrible. They seem to be bitmap fonts and not vector. >>> It looks like you used TeX to generate the document. Go to >>> http://www.truetex.com/ for links to quite number of articles on >>> how to use truetype fonts in TeX. >> >>What reader were you using? I'm trying to figure out (a) why some >>people think it looks peachy and some think it looks terrible (it looks >>great on Evince), and (b) make sure I test it on enough different >>readers that I get a true picture of what it looks like to the world at >>large. > >I used Acrobat Pro 9 on Windows XP. Acroreader 9 on OpenSuse >also looks terrible. Looks fine in Evince on the same machine. >So it looks like it is Acrobat. Unfortunately that is one PDF Viewer >it has to look nice on. >
Hi, Your new updated version looks MUCH better now. Fonts are all vector, and it displays correctly in all the viewers I tried. Regards Anton Erasmus