Teensy3 - fast multichannel adc

Status
Not open for further replies.

swarfrat

Active member
Most microcontrollers with multiple analog inputs mux a single adc. How fast can i sample if I need to switch between inputs?

I'm not certain exactly how much precision I need. The source is audio, but I'm only doing pitch detection on it, so 10 or maybe even 8 bits might be enough with proper analog processing. 6 channels, input spectral content is up to 10khz, And two or three channels at a hundred hertz or so..

Since input is up to 10khz, and I'm trying to do pitch detection via autocorrelation, some hefty oversampling is probably in order.

Can I get close to 6 channels at 96khz with a Teensy3 , or is this a candidate for a parallel ramp converter? (Which might leave a lot more time for processing)
 
I don't know the numbers but if you need "hefty oversampling" with input Fmax=10 kHz, and you need six channels, I suspect it will be a challenge with only one Teensy3. It would be a lot easier with only one channel per Teensy.
 
Might have some luck with Interrupt sampling with DMA. My guess, based on little knowledge, is you would not have resources (memory cause of your buffers for sampling, and cpu cycles) left over to do your signal processing.
 
Ah drat. I actually bought it for more mundane project, but the idea of way more power than an AVR based Arduino sorta got to my head, and I started having delusions of grandeur. Especially when I noticed it would fit in the bottom of a Stratocaster's jack route. Autocorrelation seems a little simpler at first, but it's n^2 brute force, and NlogN if you do it via FFT. Still.. I have an idea for a multi-tiered auto-correlation that might actually reduce N enough to make brute force doable.
 
Yes having it as a dongle on your 1/4" jack would be pretty sweet. Are you trying to use it as a guitar tuner? If so, you only need it up to the fundamental frequency I believe, which I think is fairly low.
edit: Oh, and why would you need so many audio channels? There's not a jack for each string.
 
Last edited:
No - but I do have hex pickups (piezo). Actually, in an effort to get pitch tracking latency down, I was thinking something like
96khz sample rate
96khz [BUFF] ... rollover shifts average into --->
48khz [BUFF]...
...
...
down to say 375 Hz (pick a number). Min frequency detected only needs to be say 50 Hz (dive bombs or low tuning if I ever get the bug). So now you're running N tiers of autocorrelation on M sized buffers, which only need to be able to hold the lowest frequency detected at the lowest downsampled rate. So now instead of trying to run autocorrelation on (96kHz / 50 Hz) samples, its NxM, and its' really really low compared to the brute force on all samples approach. Like maybe 10 or 20 samples? So - assuming this works, what was requiring NlogN or N^2 on N=480 per string is perhaps now N=10, M=7 per string, or a lot lot smaller. (1.6 orders of magnitude smaller)

Whats more, we now have a guestimate of P harmonics per string, and by golly we can now say "Yep lukey, that thar note is an E2 (82.4 Hz) in way way less than 12 ms. Because we saw strong correlation at 824 Hz, 742 Hz, 659 Hz, 577 Hz, 494Hz, and 412 Hz, and whats more, we don't need to go all the way down to the bottom, because we span multiple prime numbered harmonics. (Although it could make pinch harmonics register as the note sounded - but "What are pinch harmonics" is the answer to the Jeapordy question "How could you best try to fool a pitch tracking algorithm".

I'm not sure exactly how many samples you need to discriminate well, (at the other end of the spectrum - if we took a crude nyquist 2*F - it's not going to help our correlation discriminate well with only 2 samples. Hence the hefty oversampling.) I arrived at 10khz as it still gives a 7th harmonic on the high E. But now that I consider this, the need to track partials goes down as a function of the fundamental frequency (simply because the buffer spans less time) So maybe 24khz is plenty (18 samples at 1.32 kHz). The spectra also tends to be more fundamental heavy on the upper notes anyway - at least for mags. That may not be true for piezos (crazy wide bandwidth + lack of relative pickup position change as the string length shortens).

And oh yeah, I forgot. MIDI conversion is the goal. I had initially planned to do this another way (My Yamaha G-50 converter doesn't like Piezos. At all) - I just sort of realized hey this thing might be able to tackle that project once I got it.
 
Last edited:
Ah drat. I actually bought it for more mundane project, but the idea of way more power than an AVR based Arduino sorta got to my head, and I started having delusions of grandeur. Especially when I noticed it would fit in the bottom of a Stratocaster's jack route. Autocorrelation seems a little simpler at first, but it's n^2 brute force, and NlogN if you do it via FFT. Still.. I have an idea for a multi-tiered auto-correlation that might actually reduce N enough to make brute force doable.
Remember, if you are doing floating point FFT's, that the floating point operations on the Teensy 3.0 are simulated. It sounds like the ADC speed right now is your bottleneck, but if you attempt to reduce the number of ADC's by using FFT's, the floating point speed might become an issue.

<edit>
On the other hand, the chip does have DSP extensions if you are doing integer FFT's: single cycle 16/32-bit MAC (multiply accumulate), single cycle dual 16-bit MAC, 8,16-bit SIMD arithmetic, hardware divide (2-12 Cycles).
 
Last edited:
Do you have pickups on each string? Were you planning on connecting directly to those?
If so, based on volume, or a spike with the pluck, you could narrow it down to a single string, which is about 16 possible notes. That might not need much sophisticated pitch detection.
Have you considered using a hardware filter, and just doing zero-crosses and computing frequency from that?
 
Yes. They're buffered and go out the 13 pin jack. The number of frets doesn't really help unless you're doing something like a capacitive or resistive input sensor, and that doesn't get you velocity or pitch bend. (Not a bad way to do it at all though, just doesn't work well as a retrofit.) Zero crossing isn't very reliable with complex harmonically related waveforms. (You're not guaranteed a single zero crossing during one period - particularly if the 2nd harmonic swamps the fundamental, which is actually pretty common in many instruments.)

Yes, I am planning some spiffy hardware filtering after this current project. Piezo pickups are capacitive in nature - so it needs either a charge amplifier or a really high input impedance buffer, and some steep HPF to keep mechanical noise out. The piezos are also summed and mixed in with the magnetic pickups, but they're voiced for fake acoustic sound, and I have more devious plans for voicing them. Then the plan was to do my MIDI conversion in software. The Teensy3 just started to look like a hammer in search of nails, and I thought maybe I could relax the fidelity a bit (for more speed) if I did it internally (since it's not being used as an audio signal after conversion).
 
On more reflection... The oversampling is way over. Even if i did attempt the extraction of harmonics... The higher the frequency goes, the less important it becomes. In standard tuning, a 24 fret guitar has a fundamental range of 82.4 hz to 1318 Hz. Right now I'm strung lighter than normal, tuned F#2 to G4. Still, at 1.3khz, it takes less than 1 ms to actually complete one period. So I'm now thinking 12 bits and 10 khz per channel is sufficient. And certainly more doable. Also each string essentially only has two octaves to search, not the four that the entire instrument spans.
 
This is an ambitious project. Your reflexes for the signal processing are good. The devil is in the details. More than one Ph. D. student has gone
down this path. Amazingly (I started 35 years ago) we still can't do robust pitch detection for the guitar even with the fanciest hex pickups and lots of DSP.
To avoid you having to invent too much of this, I can recommend you poke around at the source of the fiddle~ - it does maximum likelihood on harmonics extracted from an
FFT. The improved code in sigmund~ was developed with the guitar in mind. There are discussions of these here: http://www.mail-archive.com/pd-list@iem.at/msg30590.html
Why not experiment with these on a rasberry PI (with PD) and then decide if it worth the considerable effort to port them to the fixed point arithmetic of the Teensy?
Teensy 3.0 might be fast enough but it will be quite an effort.
 
Status
Not open for further replies.
Back
Top