fast peak detection

Status
Not open for further replies.

swarfrat

Active member
I'm doing an SPL meter stoplight, and using analogRead() with a Teensy 3.0, I'm only getting about 390Hz sample rate. I've got analogReadResolution(6) and analogReadAveraging(0), running open loop for 50ms.
I'm not trying to do FFT or anything super fancy - I just need to make sure I don't miss high frequency peaks due to sample rate. I could rectify and filter, but I was hoping to be able to work directly off the mic preamp signal (using an Adafruit MAX4466 electret board). I really only need about 20db dynamic range (85 to 105db SPL). Can I run lower than 8 bits for faster conversion? Does analogReadAveraging(0) actually disable it?

I thought open loop was more like 10khz sample rate - which should be enough for my application.
 
analogRead should be able to run much faster. If you want help with specific code, please see the "Forum Rule" which appears at the top of every page on this forum!

The other approach would be to use the Teensy Audio library.

http://www.pjrc.com/teensy/td_libs_Audio.html

I highly recommend watching the tutorial video. If you don't have 48 minutes for the whole thing, perhaps skip to 31:16 where peak detection is demonstrated.

All the audio library examples use the audio shield, but it's pretty easy to modify them to get input from the ADC object instead or I2S. Watch the stuff about the design tool, and use the design tool yourself to see what your other choices are.
 
Thanks - that's sufficient for the audio analysis portion of my project. But .. I looked at the AudioAnalyzePrint class, and besides verbage saying not to use it - I couldn't seem to get it to tell how many samples had been read. (I'd still like to have a sanity check of the resulting sampling rate.)
 
Ok, still getting poor sample rates (about 345 Hz on a 96 Mhz Teensy 3.0) Here's my code:


#include <Audio.h>
#include <Wire.h>

AudioInputAnalog microphone(A9);
AudioRecordQueue rq;
AudioConnection patchCord2(microphone, rq);

void setup()
{
AudioMemory(32);
Serial.begin(9600);
}

void loop()
{
unsigned int samples = 0;
elapsedMillis elapsed = 0;
unsigned long duration = 0;

rq.clear();
rq.begin();

while (samples < 1000)
{
int thisread = rq.available();
if (thisread)
{
samples += thisread;
rq.clear();
}
}
duration = elapsed;
Serial.print(samples);
Serial.print(" samples in ");
Serial.print(duration);
Serial.print(" ms = ");
Serial.print((float)samples * 1000 / duration);
Serial.println(" Hz");
}


Something's not quite right still.
 
Last edited:
AudioRecordQueue returns 128 sample block, doing the math 345*128=44160 which is aprox the sample rate of the audio library.
 
Status
Not open for further replies.
Back
Top