DSPRelated.com
Forums
Online · Live + on demand
February 9-11, 2027
Price goes up Jan 1: register now to lock in today's rate
Register Now →

low pass digital filter on a fixed point microcontroller

Started by Johnny Chang ●August 5, 2008

Jerry Avins wrote:

>Did I or anyone else talk about capturing an essence?
Yes. First paragraph of the post you replied to and quoted: "in order to capture its essence". Right after "Jerry Avins wrote:". -- Guy Macon <http://www.GuyMacon.com/>


robert bristow-johnson wrote:

>okay, well independent of what Jerry said (dunno if i agree), i >thought the only problem with sampling something at Nyquist was phase >vs. amplitude is ambiguous.
>that's the only thing i think is wrong with sampling something with a >component at the Nyquist frequency.
You don't consider an output taht is a flat line after some powerups and not after otherpowerups to be a problem? With no output at all (which is what you get when you sample a sine wave at Nyquist and every sample hit a zero crossing) you lose both phase and amplitude information. -- Guy Macon <http://www.GuyMacon.com/>
Jerry Avins <jya@ieee.org> wrote:
> robert bristow-johnson wrote: > > On Oct 18, 3:50 pm, Tim Wescott <t...@justseemywebsite.com> wrote: > >> On Fri, 17 Oct 2008 23:05:42 -0700, Charlie Springer wrote: > >>> On Wed, 6 Aug 2008 14:25:22 -0700, dkel...@hotmail.com wrote (in article > >>> <838644c2-e573-48d6-9f44-f86719777...@27g2000hsf.googlegroups.com>): > >>>> If the frequencies that you are trying to get rid of are more than > >>>> half your sample frequency, once sampled, they are not separable from > >>>> any other signal in band. > >>> Just a common nit. That is greater than or equal to half the sampling > >>> rate. People (and DSP book authors among them) tend to say you have to > >>> sample at least twice as fast as your greatest frequency then call it > >>> the Nyquist frequency. They should say you need to sample at greater > >>> than twice the highest frequency. > > ... > >> In theory it needs to be at least twice the highest frequency component; > > ... > > > > no, Tim, i think the theory is that it needs to (strictly) exceed > > twice the highest frequency component. a frequency component at > > precisely Nyquist cannot get both phase and magnitude represented in > > the samples. there actually is aliasing at that frequency which > > doesn't create a new frequency component like the other aliasing does, > > but it potentially screws up the phase and/or amplitude of that > > frequency component at Nyquist.
> This argument is getting tired. Or maybe I'm just getting tired of it. > Assuming more-or-less steady state signal and plenty of sampling time. > the sample rate needs to be a little (how little?) faster than twice the > highest component* in order to capture its essence. It can be as low as > exactly twice if the aim is simply avoiding aliasing and DC doesn't count.
I'd call that a near miss: Imaginge a signal (for the sake of argument, a perfect sine wave will do just fine). Now, as we sample exactly at twice the frequency of that sine wave, you have too little information. That's because you don't know the phase of the signal relative to your sample points and thus don't know the amplitude of that signal. To further explain this: as you don't know the phase, you can't tell if the, say, 1mV you're measuring as amplitude is a peak value or some value near zero crossing of that sine wave. Worst case you'd be measuring exactly at zero crossings and thus deduct that there is no signal even though the line carries several Watts of RF. So, exactly twice the highest signal frequency clearly is not high enough for sampling, you'd definitely need more. DC is no problem there as the samples would change their sign anyways, with signal frequencies equal to sample frequenca one would get some constant DC value, but we already agree on twice the highest signal frequency anyways... HTH, Florian
Jerry Avins <jya@ieee.org> wrote:
> Rocky wrote: > > On Oct 20, 3:45 am, Jerry Avins <j...@ieee.org> wrote: > >> You can sample the cosine component, but not the sine. If there were a > >> way to sample at *precisely* 2x, it would also be possible to get the > >> phase right. Otherwise, margin is needed. > > > > I'm probably being a bit thick, but how? (Unless of course the signal > > generator and the sampling device are syncronised)
> If they aren't synchronized or derived from a single source, how would a > precise 2:1 frequency ratio be maintained?
Umm, well, maybe i'm thick as well, but wouldn't that basically limit the measurement to the device that's generating the signal as well? Apart from me seeing no point in measuring a signal i already know (as i created it here and now in the first place), even sampling at exactly twice the signal frequency (by using the same clock source as the generator) would do me no good in a two-devices-connected-and-synced-by- cabling setup as the phase correlation of sampling device and source would be highly dependent on the cabling used. Even swapping one cable for another could render the presentation of the highes signal frequency useless unless both cables have *exactly the same length*. So, in theory this would be possible, but in the real world, it won't. Just my 2 cents, Florian
"Tim Wescott" <tim@seemywebsite.com> wrote in message 
news:UKGdnW6LO8b6XmbVnZ2dnUVZ_rrinZ2d@web-ster.com...
> Charlie Springer wrote: >> On Sat, 18 Oct 2008 12:50:57 -0700, Tim Wescott wrote >> (in article <85ydnecbMfa8o2fVnZ2dnUVZ_oLinZ2d@web-ster.com>): >> >>>> Just a common nit. That is greater than or equal to half the sampling >>>> rate. People (and DSP book authors among them) tend to say you have to >>>> sample at least twice as fast as your greatest frequency then call it >>>> the Nyquist frequency. They should say you need to sample at greater >>>> than twice the highest frequency. (It is the Nyquist criterion but you >>>> have to sample > Nyquist). And it better be quite a bit greater if you >>>> don't want to be forced to use very long sample sets. >>>> >>>> I don't want to sound like I think anyone here is not up to speed, its >>>> just that these things become rules of thumb. Imagine sampling at >>>> exactly twice the highest freq. You will get a DC component instead, >>>> sampling at the same value every time, unless the amplitude is changing >>>> very rapidly. I used to teach this stuff and practically every book and >>>> article repeated this same error. I suppose they still do. >>>> Oversampling, >>>> as it is called, is a very good thing. >>>> >>>> -- Charlie Springer >>> In theory it needs to be at least twice the highest frequency component; >>> in reality it needs to be significantly greater than twice the highest >>> _significant_ frequency component, with some tolerance for the _actual_ >>> highest frequency component as long as there isn't much of it. >>> >>> Here's some more detail: >>> http://www.wescottdesign.com/articles/Sampling/ >>> sampling.html >> >> You state in your own paper that sampling at the Nyquist rate is >> meaningless without phase (and how can you have phase if you sample at >> the Nyquist rate?). So I respectfully submit that your premise is >> incorrect. In theory, you need to sample at least greater than twice the >> highest frequency component. >> >> Just change your into from >> >> "The Nyquist theorem states that if you have a signal that is perfectly >> band limited to a bandwidth of f0 then you can collect all the >> information there is in that signal by sampling, as long as your sample >> rate is 2f0 or more." >> >> to ---sample rate > 2f0 or more. >> >> The form of the theorem you are using is for analytical functions of >> infinite extent. Thus the misconception. If you can not sample for an >> infinite length of time (and who has the time for that?), you must >> exclude the equality. > > IIRC I make the point that the theorem, as stated, requires an infinite > observation interval. One of the main points of the paper is to get folks > to realize that the Nyquist limit isn't a wall that you can comfortably > lean against -- it's more like an electric fence that you want to distance > yourself from by a healthy margin.
Nicely put!
> >> Your intro should say function instead of signal and remove the other >> references to bandwidth and signals, then relate it to the Fourier >> Transform to define bandlimiting. Note the FT is also from -infinity to >> infinity. >> >> Or you can just say >2f0. >> >> -- Charlie Springer >> > > I intentionally avoided mention of the Fourier transform; the intended > audience for that article doesn't necessarily understand the FT, and I > didn't want to throw it at them. > > It does make for significantly more hand waving instead of hard math -- > but if someone can understand the hard math, they don't need a whole > article, they just need to think a bit. > > -- > > Tim Wescott > Wescott Design Services > http://www.wescottdesign.com > > Do you need to implement control loops in software? > "Applied Control Theory for Embedded Systems" gives you just what it says. > See details at http://www.wescottdesign.com/actfes/actfes.html
Florian E. Teply wrote:
> Jerry Avins <jya@ieee.org> wrote: >> Rocky wrote: >>> On Oct 20, 3:45 am, Jerry Avins <j...@ieee.org> wrote: >>>> You can sample the cosine component, but not the sine. If there were a >>>> way to sample at *precisely* 2x, it would also be possible to get the >>>> phase right. Otherwise, margin is needed. >>> I'm probably being a bit thick, but how? (Unless of course the signal >>> generator and the sampling device are syncronised) > >> If they aren't synchronized or derived from a single source, how would a >> precise 2:1 frequency ratio be maintained? > > Umm, well, maybe i'm thick as well, but wouldn't that basically limit > the measurement to the device that's generating the signal as well? > Apart from me seeing no point in measuring a signal i already know (as i > created it here and now in the first place), even sampling at exactly > twice the signal frequency (by using the same clock source as the > generator) would do me no good in a two-devices-connected-and-synced-by- > cabling setup as the phase correlation of sampling device and source > would be highly dependent on the cabling used. Even swapping one cable > for another could render the presentation of the highes signal frequency > useless unless both cables have *exactly the same length*. So, in theory > this would be possible, but in the real world, it won't. > > Just my 2 cents,
Here's a few more pennies: Signals travel on cables around 1.5 to 2 nanoseconds/ft. (1 ns/ft in free space.) Audio samplers generally have enough phase jitter and the signals themselves have small enough slope so that a couple of inches of cable won't affect matters much. (If a 100 KHz sine crosses zero at t=T, what fraction of its peak value occurs at t=(T+100 ns?) Sampling clocks synchronized to the sampled signal are used in testing labs. The aim there is characterizing the sampler, not the signal. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Guy Macon wrote:
> Jerry Avins wrote: > >> Did I or anyone else talk about capturing an essence? > > Yes. First paragraph of the post you replied to and > quoted: "in order to capture its essence". Right > after "Jerry Avins wrote:".
Oops*! I'm sure you're right, even though I can't track the thread back. Jerry _________________________________ * I actually prefer the dutch spelling: oeps. -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Florian E. Teply wrote:
> Jerry Avins <jya@ieee.org> wrote: >> robert bristow-johnson wrote: >>> On Oct 18, 3:50 pm, Tim Wescott <t...@justseemywebsite.com> wrote: >>>> On Fri, 17 Oct 2008 23:05:42 -0700, Charlie Springer wrote: >>>>> On Wed, 6 Aug 2008 14:25:22 -0700, dkel...@hotmail.com wrote (in article >>>>> <838644c2-e573-48d6-9f44-f86719777...@27g2000hsf.googlegroups.com>): >>>>>> If the frequencies that you are trying to get rid of are more than >>>>>> half your sample frequency, once sampled, they are not separable from >>>>>> any other signal in band. >>>>> Just a common nit. That is greater than or equal to half the sampling >>>>> rate. People (and DSP book authors among them) tend to say you have to >>>>> sample at least twice as fast as your greatest frequency then call it >>>>> the Nyquist frequency. They should say you need to sample at greater >>>>> than twice the highest frequency. >>> ... >>>> In theory it needs to be at least twice the highest frequency component; >>> ... >>> >>> no, Tim, i think the theory is that it needs to (strictly) exceed >>> twice the highest frequency component. a frequency component at >>> precisely Nyquist cannot get both phase and magnitude represented in >>> the samples. there actually is aliasing at that frequency which >>> doesn't create a new frequency component like the other aliasing does, >>> but it potentially screws up the phase and/or amplitude of that >>> frequency component at Nyquist. > >> This argument is getting tired. Or maybe I'm just getting tired of it. >> Assuming more-or-less steady state signal and plenty of sampling time. >> the sample rate needs to be a little (how little?) faster than twice the >> highest component* in order to capture its essence. It can be as low as >> exactly twice if the aim is simply avoiding aliasing and DC doesn't count. > > I'd call that a near miss: > Imaginge a signal (for the sake of argument, a perfect sine wave will do > just fine). Now, as we sample exactly at twice the frequency of that > sine wave, you have too little information. That's because you don't > know the phase of the signal relative to your sample points and thus > don't know the amplitude of that signal. To further explain this: as you > don't know the phase, you can't tell if the, say, 1mV you're measuring > as amplitude is a peak value or some value near zero crossing of that > sine wave. Worst case you'd be measuring exactly at zero crossings and > thus deduct that there is no signal even though the line carries several > Watts of RF. > So, exactly twice the highest signal frequency clearly is not high > enough for sampling, you'd definitely need more. DC is no problem there > as the samples would change their sign anyways, with signal frequencies > equal to sample frequenca one would get some constant DC value, but we > already agree on twice the highest signal frequency anyways...
I didn't claim it's high enough to capture the signal. I claimed it's high enough to avoid aliasing. Consider: a signal at fs/2 + delta aliases to fs/2 - delta. Where is the alias when delta is zero? However large delta is, you need to sample for a time in the order of 1/delta. How long is that when delta is zero? Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Jerry Avins <jya@ieee.org> wrote:
> Florian E. Teply wrote: > > Jerry Avins <jya@ieee.org> wrote: > >> Rocky wrote: > >>> On Oct 20, 3:45 am, Jerry Avins <j...@ieee.org> wrote: > >>>> You can sample the cosine component, but not the sine. If there were a > >>>> way to sample at *precisely* 2x, it would also be possible to get the > >>>> phase right. Otherwise, margin is needed. > >>> I'm probably being a bit thick, but how? (Unless of course the signal > >>> generator and the sampling device are syncronised) > > > >> If they aren't synchronized or derived from a single source, how would a > >> precise 2:1 frequency ratio be maintained? > > > > Umm, well, maybe i'm thick as well, but wouldn't that basically limit > > the measurement to the device that's generating the signal as well? > > Apart from me seeing no point in measuring a signal i already know (as i > > created it here and now in the first place), even sampling at exactly > > twice the signal frequency (by using the same clock source as the > > generator) would do me no good in a two-devices-connected-and-synced-by- > > cabling setup as the phase correlation of sampling device and source > > would be highly dependent on the cabling used. Even swapping one cable > > for another could render the presentation of the highes signal frequency > > useless unless both cables have *exactly the same length*. So, in theory > > this would be possible, but in the real world, it won't. > > > > Just my 2 cents,
> Here's a few more pennies:
> Signals travel on cables around 1.5 to 2 nanoseconds/ft. (1 ns/ft in > free space.) Audio samplers generally have enough phase jitter and the > signals themselves have small enough slope so that a couple of inches of > cable won't affect matters much. (If a 100 KHz sine crosses zero at t=T, > what fraction of its peak value occurs at t=(T+100 ns?)
Well, i was thinking a tad more like RF, say 30MHz, as that's my domain. But to elaborate on your example, 100 ns is 1/100 period of a 100kHz sine wave, sin(2*pi/100)=0.001 roughly, which is 1 LSB at 10 Bit A/D resolution. It would be worse at higher signal frequencies and/or resolutions of course.
> Sampling clocks synchronized to the sampled signal are used in testing > labs. The aim there is characterizing the sampler, not the signal.
Haven't thought of that. Thanks for your pocket change ;-) Florian
Guy Macon wrote:
> robert bristow-johnson wrote: > >> okay, well independent of what Jerry said (dunno if i agree), i >> thought the only problem with sampling something at Nyquist was phase >> vs. amplitude is ambiguous. > >> that's the only thing i think is wrong with sampling something with a >> component at the Nyquist frequency. > > You don't consider an output taht is a flat line after some > powerups and not after otherpowerups to be a problem? With > no output at all (which is what you get when you sample a > sine wave at Nyquist and every sample hit a zero crossing) > you lose both phase and amplitude information.
That case can't arise. the only ways to sample at exactly twice the frequency being sampled are on paper (where any conditions can be assumed) by phase locking the sampler to the signal with absolutely no residual FM, or by deriving signal and sampling clock from a common source. None of this has much do do with reality. Consider a system sampling at 8 KHz. According to purists, a signal at 3,999.999 Hz is well accommodated, while one at 4,000.001 (or even 4,000.000) is not. Math may work that way, but not real things. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;