Shop OBEX P1 Docs P2 Docs Learn Events
Sampling, Aliasing, Nyquist. How fast is fast enough? — Parallax Forums

Sampling, Aliasing, Nyquist. How fast is fast enough?

yarisboyyarisboy Posts: 245
edited 2009-07-28 07:03 in Propeller 1
Hi,
I'd like to be able to sample at 20 kHz. The rub is I'll have six channels to monitor. Can the Propeller handle 120 ksps with a simple I2C interface? I've found a DSP grade muxed A/D chip rated for 400 ksps in Austria but I haven't found a US distributor for it yet.

Comments

  • KyeKye Posts: 2,200
    edited 2009-07-26 14:41
    Well I2c is limited to 400khZ max. Unless you have some of the new fancy I2c devices that go at 1Mhz you will not be able to reach your goal.

    So I'm think you'll most likely be stuck at 400Khz.

    That said, I would reconmend using an SPI chip instead of an I2C chip since they have no protocol overhead and are generally able to go faster than I2C.

    I can't say what sampling rate would be fast enough but you won't be able to do what you want easily with an I2C chip.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-26 14:45
    The Propeller can handle the data rate, but I2C is not the best choice for speed. You will need an I/O driver written in Propeller assembly language and probably written specifically for your A/D chip. An SPI driver would be much simpler and inherently much faster.
  • yarisboyyarisboy Posts: 245
    edited 2009-07-26 16:42
    Thanks a bunch. The chip I haven't been able to source yet is by austriamicrosystems. The spec sheet says "Data accesses are made via the high-speed, 4-wire, SPI, QSPI-, and Microwire-compatible serial interface. AS1521 has a supply voltage the same as the Propeller.

    Post Edited (yarisboy) : 7/26/2009 4:57:00 PM GMT
  • LeonLeon Posts: 7,620
    edited 2009-07-26 16:50
    What is the bandwidth of the signal? You only need to sample at twice the bandwidth according to Nyquist, not at twice the frequency.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-07-26 17:11
    Just be careful what you interpret to mean by "bandwidth". In some applications, the bandwidth of a pure sine wave is considered to be 0. But that's not what's meant here. Quoting Wikipedia:

    ····The Nyquist rate is the minimum sampling rate required to avoid aliasing, equal to twice the highest frequency contained within the signal.

    ········43ca8a718fa6790a857f4484f860bb99.png

    ····where is the highest frequency at which the signal can have nonzero energy.

    ····To avoid aliasing, the sampling rate must exceed the Nyquist rate:

    ········0033c388a6410c24a469ec2cbcdc9c51.png.

    ····To avoid aliasing, the bandwidth must be considered to be the upper frequency limit of a baseband signal
    [noparse][[/noparse]emphasis mine].

    So, at 20KHz, you should be able to sample a signal whose components are all less than 10KHz.

    -Phil
  • yarisboyyarisboy Posts: 245
    edited 2009-07-26 17:15
    Reviewing my data sheet I see that my current sensors have a stated bandwidth of 120 kHz. My gate drivers can rise or fall in 500 ns. The fall time on the IGBTs is listed as 600 ns. Looks like the hall effect current sensors would filter out any signal content above 120 kHz. If I'm reading all this right I need an A/D chip that can sample at 240 kHz/channel or better to avoid aliasing from a sensor with a 120 kHz upper limit. If the Allegro chip is handling 400 ksps MUXed eight ways thats 50 ksps per channel. That would limit usable reliable current samples to 25 khz according to the Nyquist rule. The track and hold time for this chip is listed as 390 ns (25.6 kHz). 20 % of the time my sample would be off-by-one carrier frequency cycle. Passive filters designed for a 26kHz corner may be in order. An error of 0.5 micro seconds may be shorter than other errors such as the propeller hub data access cycle for global variables. On the bench I'll be testing with a standard 3-phase fractional horse motor in a wood lathe. On a bicycle I'd may never go over 90 hz drive frequency before I ran out of battery pack. With a current sensor on each IGBT ,compared and normalized to the sine look-up table, I should be able to avoid introducing even harmonics inherent with drive saturation.

    Post Edited (yarisboy) : 7/26/2009 11:55:54 PM GMT
  • TreeLabTreeLab Posts: 138
    edited 2009-07-26 21:44
    @Phil : I am not an EE, but I always thought that the definition was always, exclusively, in terms of bandwidth. If your application involves frequencies down to DC, of course bandwidth and highest frequency coincide, as wikipedia suggests. But, if (and only if) you know that there is no energy below a certain frequency, then the Nyquist frequency can be moved up as a consequence : if you FT such a signal and find low-frequency components (which you somehow know to be false), then you can reflect these up into the higher frequency span which is more physically reasonable.

    Most such situations are in radio type systems where the pertinent information is narrowly concentrated in a relatively narrow bandpass, at a relatively high frequency.

    At least, that is how I was taught .... Am I wrong here?
    Cheers!
    Paul Rowntree
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-07-26 23:16
    Paul,

    In situations such as the ones you cite, you can shift the spectrum lower by heterodyning and filtering, then sampling at a lower frequency. There's also a technique called "undersampling" wherein you sample at a rate lower than the Nyquist rate and analyze the aliased signals reflected about the sampling frequency from the input frequencies. This may be what you're referring to.

    But, to avoid aliasing altogether, you need to sample above the Nyquist rate on signals whose highest frequency components are below half that.

    -Phil
  • cessnapilotcessnapilot Posts: 182
    edited 2009-07-27 08:11
    yarisboy,

    I have read in some Tetronix manual, as a rule of thumb, that sampling at 5 times the input frequency is good for windowing and FFT in signal processing of slightly distorted sine like signals, without spikes. Twice is the minimum. For transient signals, as Phil Pilgim said, "To avoid aliasing, the bandwidth must be considered to be the upper frequency limit of a baseband signal". In practical terms, when the rise time of your signal is deltaT, 10/detaT sampling frequency covers most (>90%) signal energy.

    If you just want to sample at 20 KHz, 6-channels, Propeller with 6 COGs, PASM I2C driver in each, can do it. When you multiplex your channels into one, 4-wire high speed SPI, will handle it. Yor HUB RAM will be filled up with data very fast, though.



    Istvan
  • yarisboyyarisboy Posts: 245
    edited 2009-07-28 02:59
    To everyone who has had input, Thanks. It has helped me clear my thinking and nail down what and how much A/D sampling I need to support my project. I ordered the new A/D kit from ucontroller.com along with their Propeller board. I down loaded the trial version of Viewport and have been checking out the demo downloaded into my current desktop propeller bread board. WOW!
  • HannoHanno Posts: 1,130
    edited 2009-07-28 07:03
    Hi yarisboy,
    As you seem to have discovered, ViewPort is ideal for your application. You "share" some variables with ViewPort and let the Propeller do what it's best at- getting data from different devices. ViewPort transfers the data to the pc (at up to 2mbps, enough for 200,000 samples/sec at 32bit/sample) and gives you all sorts of tools to analyze your data. It's very extensible right now, but will be even more so with the inclusion of a DDE server and client. Let me know if you need anything. Please keep us updated on your application!
    Hanno

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Download a free trial of ViewPort- the premier visual debugger for the Propeller
    Includes full debugger, simulated instruments, fuzzy logic, and OpenCV for computer vision. Now a Parallax Product!
Sign In or Register to comment.