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
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.
> 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
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. > > r b-j > >
I was reading "at least twice" and getting fs (is strictly) > f/2. But now that you've all smacked me upside the head, I'm not sure why I was thinking that. Habit, I suppose. -- 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


Jerry Avins wrote:
> >Philip Martel wrote: > >> Charlie Springer wrote... >> >>> Jerry Avins wrote: >>> >>>> 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. >>> >>> Jerry (don't get tired!), what if you sample a10 volt 1 KHz sine at 2 KHz >>> with all the samples falling at pi/8 and 9pi/8 ? What will you get for >>> amplitude? >> >> Jerry is saying that the sample rate has to be faster than twice the highest >> component. It's right there in black and white a few lines above. You come >> back and ask him to sample a 1 KHz sine wave at 2 KHz. That violates the >> "faster than". Stop beating a dead horse! > >What I sad was that if the sample rate is exactly twice the sampled >frequency, you get no aliasing, provided that DC doesn't matter. Charlie >pointed our that DC can arise in the case I described, so we're -- all >of us -- in effective agreement.
While it isn't "aliasing" according to the accepted definition of that term, I would consider a system that reproduces the original signal at full amplitude one time, but outputs zero volts (AC or DC) after cycling the power to be a failure to "capture the essence" of the original signal. That, of course, is what happens when the signal is a sine wave and the sample rate is exactly twice the sampled frequency; one time the samples hit the peaks, the next time they always hit the zero crossings. -- Guy Macon <http://www.GuyMacon.com/>
Guy Macon wrote:
> Jerry Avins wrote: >> Philip Martel wrote: >> >>> Charlie Springer wrote... >>> >>>> Jerry Avins wrote: >>>> >>>>> 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. >>>> Jerry (don't get tired!), what if you sample a10 volt 1 KHz sine at 2 KHz >>>> with all the samples falling at pi/8 and 9pi/8 ? What will you get for >>>> amplitude? >>> Jerry is saying that the sample rate has to be faster than twice the highest >>> component. It's right there in black and white a few lines above. You come >>> back and ask him to sample a 1 KHz sine wave at 2 KHz. That violates the >>> "faster than". Stop beating a dead horse! >> What I sad was that if the sample rate is exactly twice the sampled >> frequency, you get no aliasing, provided that DC doesn't matter. Charlie >> pointed our that DC can arise in the case I described, so we're -- all >> of us -- in effective agreement. > > While it isn't "aliasing" according to the accepted definition of > that term, I would consider a system that reproduces the original > signal at full amplitude one time, but outputs zero volts (AC or DC) > after cycling the power to be a failure to "capture the essence" of > the original signal.
Did I or anyone else talk about capturing an essence? Do you think that a signal's essence can be captured by sampling it at a millihertz above the theoretical 2x for ten seconds? Do you know any practical system that samples less than ten percent above? Even that pushes the edge.
> That, of course, is what happens when the signal > is a sine wave and the sample rate is exactly twice the sampled > frequency; one time the samples hit the peaks, the next time they > always hit the zero crossings.
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. 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;
On Oct 19, 1:39 pm, Charlie Springer <R...@regnirps.com> wrote:
> On Sun, 19 Oct 2008 06:07:01 -0700, Philip Martel wrote > (in article <3ZednQOig-WcrGbVnZ2dnUVZ_jSdn...@comcast.com>): > > > > > "Charlie Springer" <R...@regnirps.com> wrote in message > >news:0001HW.C5202B4900B66E61F02845B0@news.nw.centurytel.net... > >> On Sat, 18 Oct 2008 20:21:50 -0700, Jerry Avins wrote > >> (in article <iJxKk.1692$JT3....@newsfe03.iad>): > > >>> 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. > > >> Jerry (don't get tired!), what if you sample a10 volt 1 KHz sine at 2 KHz > >> with all the samples falling at pi/8 and 9pi/8 ? What will you get for > >> amplitude? > > Charlie, > > Jerry is saying that the sample rate has to be faster than twice the highest > > component. It's right there in black and white a few lines above. You come > > back and ask him to sample a 1 KHz sine wave at 2 KHz. That violates the > > "faster than". Stop beating a dead horse! > > ">>It can be as low as > > >> exactly twice if the aim is simply avoiding aliasing and DC doesn't > >> count."
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. you cannot know both the phase and the amplitude of any component at Nyquist. consider: x(t) = (1/cos(theta)) * cos(w0*t+theta) if w0 = 2*pi*(Fs/2) or Hyquist, then the samples are x[n] = x(n/Fs) = -(-1)^n doesn't matter what the phase (with the corresponding amplitude) is, you cannot tell from the samples because of aliasing. aliasing at higher frequencies results in frequency components (with determined phase and amplitude) below Nyquist masquerading as the originally there at that sub-Nyquist frequency. but it was originally above Nyquist, hence aliasing. in both cases of aliasing, it's just that you don't have sufficient information to discriminate between the different cases that happen to have identical samples. that's the only thing i think is wrong with sampling something with a component at the Nyquist frequency. r b-j
On Oct 20, 3:45&#4294967295;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) Rocky
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? 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;
Charlie Springer wrote:
> On Sat, 18 Oct 2008 20:21:50 -0700, Jerry Avins wrote > (in article <iJxKk.1692$JT3.575@newsfe03.iad>):
>>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.
> Jerry (don't get tired!), what if you sample a10 volt 1 KHz sine at 2 KHz > with all the samples falling at pi/8 and 9pi/8 ? What will you get for > amplitude?
Mathematically, the probability of any specific value in a continuous distribution is zero. In sampling an analog signal, one would need a PLL to keep the sampling frequency right on twice a sine input. In that case, it is up to the designer of the PLL to select the appropriate phase. For real sampling of real analog signals the spectrum should tend to zero approaching half the sampling frequency. Filters with infinitely sharp cutoff aren't physically realizable. Except for signals specifically hand generated to prove one way or the other, there are no cases where the difference should be visible. -- glen
Tim Wescott wrote:
(snip)

> 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.
or a perfectly periodic signal, such that the Fourier series is used instead of the continuous Fourier transform. Otherwise, yes. For a finite interval, it approximately works not too far from the end points, good enough for most of us. Otherwise, it seems to me that if you have N+1 points over an interval of N times the Nyquist rate you have enough. (Subtract a line with the slope of the line going through the first and last points that crosses the axis half way between the two end points. Now connect the first and last point (which are now equal) and use periodic boundary conditions. The +1 is for the slope of the needed line.) That tells how close you can come with a finite interval. -- glen
Jerry Avins wrote:
(snip)

> If they aren't synchronized or derived from a single source, how would a > precise 2:1 frequency ratio be maintained?
I was wondering about that, too. With a PLL it would on the average be right, but I believe that is close enough. Otherwise, see my previous post for the question of finite vs. infinite interval. -- glen