Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Teensy 4.1 Sample 40khz Sine wave

  1. #1
    Junior Member
    Join Date
    Oct 2020
    Posts
    10

    Teensy 4.1 Sample 40khz Sine wave

    Hi,

    I am using the Teensy 4.1 and would like to sample a 40khz sinewave which would require 80 kS/s. I have multiple 40 khz inputs that need to be sampled. How would I go about doing this? Any sample code? Any libraries? Also, can the audio library be modified to sample at 80khz instead of 44.1 khz?

    Thanks.

  2. #2
    Senior Member
    Join Date
    Feb 2018
    Location
    Corvallis, OR
    Posts
    243
    TLI (the opposite of Too Much Information)! Sampling 4 channels at 40KHz is no big issue--the T4.1 can easily sample at up to 1 million samples per second. The details in which the devil resides are things like: What do you want to do with the samples? Do you want to process them as collected, save a finite-length sample in RAM or PSRAM, or record continuously to SD card for later analysis?

  3. #3
    Senior Member
    Join Date
    Jul 2020
    Posts
    463
    If you know the signal is only a 40kHz signal you dont need to sample that fast - you can simply compensate for the
    aliasing.

    Perhaps the signal isn't really a pure tone at exactly 40kHz, but is band limited around that region (ultrasound transducer
    output maybe?). You could still under-sample and reconstruct for something like that too.

  4. #4
    Junior Member
    Join Date
    Oct 2020
    Posts
    10
    Quote Originally Posted by MarkT View Post
    If you know the signal is only a 40kHz signal you dont need to sample that fast - you can simply compensate for the
    aliasing.

    Perhaps the signal isn't really a pure tone at exactly 40kHz, but is band limited around that region (ultrasound transducer
    output maybe?). You could still under-sample and reconstruct for something like that too.
    Could you explain further what you mean by this?

  5. #5
    Junior Member
    Join Date
    Oct 2020
    Posts
    10
    Quote Originally Posted by mborgerson View Post
    TLI (the opposite of Too Much Information)! Sampling 4 channels at 40KHz is no big issue--the T4.1 can easily sample at up to 1 million samples per second. The details in which the devil resides are things like: What do you want to do with the samples? Do you want to process them as collected, save a finite-length sample in RAM or PSRAM, or record continuously to SD card for later analysis?
    I want to sample 8-12 channels. I would like to process them as collected by saving into ram. Also I would like to display the 40 khz sine wave to the serial plotter or even use DAC to write out the 40khz sine wave. Are there any examples of code for both.

  6. #6
    Senior Member
    Join Date
    Jul 2020
    Posts
    463
    Quote Originally Posted by pi123 View Post
    Could you explain further what you mean by this?
    Yes - if you know a signal is band-limited you can use the fact that sampling aliases at multiples of the sampling rate to
    allow a low rate of sampling - so long as the sampling rate is more than twice the bandwidth of the signal you can
    accurately reconstruct the waveform (Nyquist's theorem only talks about baseband, but its more general than that).

    So imagine a signal with components only in the 36kHz to 44kHz range. That's 8k of bandwidth, so sampling at 24kSPS
    would capture all the information (assuming the samples are at points of time, not averages over a period).

    In fact it would map 36kHz--44kHz down to 12kHz--20kHz as seen in the samples, which you could then process
    digitally by upsampling and heterodyning with 24kHz. However aliasing does the mirror image too so you get
    a reversed spectrum from 12k down to 4k as well (twice the sampling rate minus the signal frequencies).

    Its not the simplest approach, but can be useful when you want to use cheaper ADCs and handle less data. Care
    is required to ensure your assumptions are correct and no spurious aliased signals get in the way.

    In effect its a cheap way of mixing down in frequency using the sample/hold circuit of the ADC as the mixer.

    Thinking about my numbers above I think I've got it wrong as you need to keep the signal and its reflection
    both within the nyquist limit, so I'd only be able to handle upto 6k of signal bandwidth with a 24k sample rate,
    but that's the basic idea.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •