Teensy 3.6 mic > FreqMeasure

Status
Not open for further replies.

robbo

Member
Hi all,

Fairly new to this. Have successfully got Teensy 3.6 and audio shield and electret mic capsule working and can get FFT results to serial monitor. I'd like to use the mic signal to feed the FreqMeasure sketch but docs say it must use digital signal on pin3. Any idea how to send my mic signal from audio shield to pin3 internally? Apologies for dumb questions/lack of info etc. So far i'm only using example sketches from built-in audio library so have not included those bits of code yet. Please advise.
 
Hi all,

Fairly new to this. Have successfully got Teensy 3.6 and audio shield and electret mic capsule working and can get FFT results to serial monitor. I'd like to use the mic signal to feed the FreqMeasure sketch but docs say it must use digital signal on pin3. Any idea how to send my mic signal from audio shield to pin3 internally? Apologies for dumb questions/lack of info etc. So far i'm only using example sketches from built-in audio library so have not included those bits of code yet. Please advise.

Dumb question from my side: which FreqMeasure sketch? could not find such an example in the Audio Library.
 
Sorry - my mistake. It appears in Examples list as FreqMeasure...

/* FreqMeasure - Example with serial output
* http://www.pjrc.com/teensy/td_libs_FreqMeasure.html
*
* This example code is in the public domain.
*/
#include <FreqMeasure.h>

void setup() {
Serial.begin(57600);
FreqMeasure.begin();
}

double sum=0;
int count=0;

void loop() {
if (FreqMeasure.available()) {
// average several reading together
sum = sum + FreqMeasure.read();
count = count + 1;
if (count > 30) {
float frequency = FreqMeasure.countToFrequency(sum / count);
Serial.println(frequency);
sum = 0;
count = 0;
}
}
}
 
from the docu you see that the example is for digital signals not audio of a mic.
So you would need a digital function generator to be attached to pin 3 (see Teensy card for pin 3)
 
from the docu you see that the example is for digital signals not audio of a mic.
So you would need a digital function generator to be attached to pin 3 (see Teensy card for pin 3)

Is there any way to use onboard ADC and route output of that to pin3 ?
 
You could try
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthWaveformSine   sine1;          //xy=209,218
AudioOutputAnalogStereo  dacs1;          //xy=489,222
AudioConnection          patchCord1(sine1, 0, dacs1, 0);
// GUItool: end automatically generated code

#include <FreqMeasure.h>

void setup() {
  // put your setup code here, to run once:
  AudioMemory(2);
    
  sine1.amplitude(1.0);
  sine1.frequency(1000);

**FreqMeasure.begin();
}

double sum=0;
int count=0;


void loop() {
  // put your main code here, to run repeatedly:

**if (FreqMeasure.available()) {
****// average several reading together
****sum*=*sum*+*FreqMeasure.read();
****count*=*count*+*1;
****if (count > 30) {
******float frequency = FreqMeasure.countToFrequency(sum / count);
******Serial.println(frequency);
******sum*=*0;
******count*=*0;
****}
**}
}
}
and connecting dac0 to pin3 with a wite
(caveat: I have not tested program)
 
Last edited:
I modified the sketch and tested it on T3.6
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthWaveformSine   sine1;          //xy=209,218
AudioOutputAnalogStereo  dacs1;          //xy=489,222
AudioConnection          patchCord1(sine1, 0, dacs1, 0);
// GUItool: end automatically generated code

#include <FreqMeasure.h>

void setup() {
  // put your setup code here, to run once:
  AudioMemory(2);
    
  sine1.amplitude(1.0);
  sine1.frequency(923.45);

  dacs1.analogReference(EXTERNAL);
  
  FreqMeasure.begin();
}

double sum=0;
int count=0;


void loop() {
  // put your main code here, to run repeatedly:

  if (FreqMeasure.available()) {
    // average several reading together
    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 1000) {
      float frequency = FreqMeasure.countToFrequency(sum / count);
      Serial.println(frequency);
      sum = 0;
      count = 0;
    }
  }
}

It is the same with
- slightly different frequency,
- The required changes of reference to 3.3 V to have sufficient signal for FreqMeasure
- and one output every 1000 measurements
 
Measuring frequencies trough a mic is not a good idea - the signal is not as clean as you might think (or want)
Can you tell us, what extactly do you want to measure ?

For music instruments for example, AudioAnalyzeNoteFrequency (part of the audio-library) is far better!

from the documentation:
AudioAnalyzeNoteFrequency


The YIN algorithm (PDF) is used to detect frequencies, with many optimizations for frequencies between 29-400Hz. This algorithm can be somewhat memory and processor hungry but will allow you to detect with fairly good accuracy the fundamental frequencies from electric guitars and basses.Within the code, AUDIO_GUITARTUNER_BLOCKS may be edited to control low frequency range. The default (24) allows measurement down to 29.14 Hz, or B(flat)0.
TODO: The usable upper range of this object is not well known. Duff says "it should be good up to 1000Hz", but may have trouble at 4 kHz. Please post feedback here, ideally with audio clips for the NoteFrequency example.
This object was contributed by Collin Duffy from his AudioTuner project. Additional details and documentation may be found there.

There's an example-sketch : Audio->Analysis->NoteFrequency.
 
Last edited:
Agreed, you probably want to use notefreq.

https://www.pjrc.com/teensy/gui/?info=AudioAnalyzeNoteFrequency

FreqMeasure requires a digital signal, which is not what you have if you're processing audio from a microphone.

But that's "probably" because we really have no idea what you're really trying to accomplish. If you took a moment to explain what you're actually trying to do, we could give you much better help. Without actually understanding your real goals, all we can do is give answers to narrowly focused technical questions, without any idea if they are really what you need.
 
Hi All, Thanks for all the advice and apologies for late reply. ultimatlely I'm trying to see if I can measure low frequency room modes (frequencies supported by a rooms dimensions). I realise that there will be quality and noise issues but these are just first steps. I'm really just seeing what my options are at this point.
 
Hi All, Thanks for all the advice and apologies for late reply. ultimatlely I'm trying to see if I can measure low frequency room modes (frequencies supported by a rooms dimensions). I realise that there will be quality and noise issues but these are just first steps. I'm really just seeing what my options are at this point.

this is definitely an analog domain where pure analog audio methods are appropriate (FFT, reverb, notefreq, etc)
 
this is definitely an analog domain where pure analog audio methods are appropriate (FFT, reverb, notefreq, etc)

Thanks for the help. I'll have another go and post anything that's of any interest. Great forum. Cheers!
 
Status
Not open for further replies.
Back
Top