0

Comparing the output of two MAX4466's
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Comparing the output of two MAX4466's

by zheng3 on Thu Aug 25, 2016 11:47 am

Hi all:

The goal of my project is to answer: is sound louder on the left side or the right side of my Arduino?

I've got two MAX4466's spaced roughly 10cm apart, wired to an Arduino with inputs on analog 0 and analog 1. Using modified sample code for the MAX4466 I'm able to get voltage values for both mics, but the values always seem to be identical. Loud noise == high values, quiet==low values, no matter from where in space the sound originates.

Are these mics sensitive enough to differentiate at this distance?

Code: Select all | TOGGLE FULL SIZE
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
    unsigned int sample;
     
    void setup()
    {
       Serial.begin(9600);
    }
     
     
    void loop()
    {
       unsigned long startMillis= millis();  // Start of sample window
       unsigned int peakToPeak = 0;   // peak-to-peak level
     
       unsigned int signalMax = 0;
       unsigned int signalMin = 1024;
     
       // collect data for 50 mS
       while (millis() - startMillis < sampleWindow)
       {
          sample = analogRead(0);
          if (sample < 1024)  // toss out spurious readings
          {
             if (sample > signalMax)
             {
                signalMax = sample;  // save just the max levels
             }
             else if (sample < signalMin)
             {
                signalMin = sample;  // save just the min levels
             }
          }
       }
       peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
       double volts0 = (peakToPeak * 3.3) / 1024;  // convert to volts

       Serial.print("0:");
       Serial.println(volts0);

       startMillis= millis();

        while (millis() - startMillis < sampleWindow)
       {
          sample = analogRead(1);
          if (sample < 1024)  // toss out spurious readings
          {
             if (sample > signalMax)
             {
                signalMax = sample;  // save just the max levels
             }
             else if (sample < signalMin)
             {
                signalMin = sample;  // save just the min levels
             }
          }
       }
       peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
       double volts1 = (peakToPeak * 3.3) / 1024;  // convert to volts

       Serial.print("1:");
       Serial.println(volts1);


if (volts0!=volts1){

          if (volts0>volts1){
            Serial.print("left");
           
          }
          else{
            Serial.print("right");
          }

         
        }

    }

zheng3
 
Posts: 20
Joined: Sun Jul 19, 2015 1:42 pm

Re: Comparing the output of two MAX4466's

by adafruit_support_bill on Thu Aug 25, 2016 12:09 pm

In a free field (i.e. no surfaces to block or reflect the sound) the sound pressure level will fall off proportional to the distance. But unless you have access to an anechoic chamber, your conditions are not likely to resemble a free-field.. One thing you can try is to add a baffle between the left and right microphones.

adafruit_support_bill
 
Posts: 62248
Joined: Sat Feb 07, 2009 10:11 am

Re: Comparing the output of two MAX4466's

by zheng3 on Thu Aug 25, 2016 12:42 pm

Thanks Bill. I've tried putting one microphone under a pillow but I'm still getting identical readings on both mics.

This makes me think either I'm accidentally reading the same value twice or the mics have a coarser resolution than I expected.

The code's just a copy/paste with slight modifications-- I can't see where it might be going wrong.

zheng3
 
Posts: 20
Joined: Sun Jul 19, 2015 1:42 pm

Re: Comparing the output of two MAX4466's

by adafruit_support_bill on Thu Aug 25, 2016 12:45 pm

Please post a photo of your circuit showing how everything is connected.
Also please post a sample of the serial output.

adafruit_support_bill
 
Posts: 62248
Joined: Sat Feb 07, 2009 10:11 am

Re: Comparing the output of two MAX4466's

by zheng3 on Thu Aug 25, 2016 1:04 pm

Black is ground, red is power, yellow is signal. As far as I can tell all the soldering looks OK.

circuit.jpg
circuit.jpg (307.75 KiB) Viewed 200 times


Serial monitor output looks like this:

Code: Select all | TOGGLE FULL SIZE
0:0.03
1:0.03
0:0.04
1:0.04
0:0.04
1:0.04
0:0.05
1:0.05
0:0.03
1:0.03
0:0.04
1:0.04
0:0.03
1:0.03
0:0.05
1:0.05
0:0.04
1:0.04
0:0.05
1:0.05
0:0.04
1:0.04
0:0.05
1:0.05
0:0.04
1:0.04
0:0.04
1:0.04
0:0.05
1:0.05
0:0.05
1:0.05
0:0.04
1:0.04
0:0.04
1:0.04
0:0.04
1:0.04

zheng3
 
Posts: 20
Joined: Sun Jul 19, 2015 1:42 pm

Re: Comparing the output of two MAX4466's

by adafruit_support_bill on Thu Aug 25, 2016 1:20 pm

A couple of things:
The code is assuming a 3.3v analog reference, but you are using the default 5v analog reference, so the math is wrong.

The numbers overall are very low, so it is hard to draw any meaningful conclusions about relative levels between them. Try adjusting the gain on the back of the boards.

Be very gentle with the pot and do not turn it past the stop. I believe that max gain is fully counter-clockwise.

adafruit_support_bill
 
Posts: 62248
Joined: Sat Feb 07, 2009 10:11 am

Re: Comparing the output of two MAX4466's

by zheng3 on Thu Aug 25, 2016 2:03 pm

Thanks for your patience. I've done the following:

connected the circuit to the 5V pin on the arduino instead of the 3.3V pin.
changed the math to reflect 5V input: double volts1 = (peakToPeak * 5) / 1024; // convert to volts
turned the pots to max gain (I've also tried this at min gain)

Unfortunately, no change in results, my mic0 and mic1 values are either identical, or mic1 is higher whenever there's a sound.

mic0 never seems to register. I have swapped the inputs and it get the same results whichever hardware is connected to pins 0 and 1.

zheng3
 
Posts: 20
Joined: Sun Jul 19, 2015 1:42 pm

Re: Comparing the output of two MAX4466's

by adafruit_support_bill on Thu Aug 25, 2016 2:54 pm

Strange. Try printing out the signalMin and signalMax values, so we can get an idea of the raw range coming from the microphones.

adafruit_support_bill
 
Posts: 62248
Joined: Sat Feb 07, 2009 10:11 am

Re: Comparing the output of two MAX4466's

by zheng3 on Thu Aug 25, 2016 3:16 pm

These readings are with ambient background noise, no intentional loud sounds.

Code: Select all | TOGGLE FULL SIZE
=-=-=-=-=
mic 1 signal min:376
signal max:621
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
right
mic 0 signal min:322
signal max:636
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:317
signal max:646
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0=-=-=-=-=-=
right
mic 0 signal min:321
signal max:603
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:321
signal max:630
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:379
signal max:648
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:379
signal max:648
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:318
signal max:630
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:318
signal max:632
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:347
signal max:651
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:347
signal max:651
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:373
signal max:651
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:373
signal max:651
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:411
signal max:640
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:350
signal max:643
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:390
signal max:639
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:338
signal max:662
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:301
signal max:655
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:288
signal max:655
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:328
signal max:634
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:307
signal max:638
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:331
signal max:642
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:316
signal max:642
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:337
signal max:665
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:337
signal max:665
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:361
signal max:646
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:301
signal max:646
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:324
signal max:647
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:324
signal max:660
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:343
signal max:648
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:323
signal max:648
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:318
signal max:637
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:318
signal max:639
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:337
signal max:640
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:337
signal max:640
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:424
signal max:635
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:331
signal max:648
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:333
signal max:672
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:333
signal max:672
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:342
signal max:622
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:342
signal max:635
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:383
signal max:645
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:335
signal max:645
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:403
signal max:646
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:329
signal max:646
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:330
signal max:620
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:330
signal max:637
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:310
signal max:670
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:310
signal max:670
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:401
signal max:629
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:401
signal max:632
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:372
signal max:621
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:372
signal max:625
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:317
signal max:639
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:317
signal max:647
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:311
signal max:633
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:294
signal max:651
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:372
signal max:639
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:335
signal max:639
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:288
signal max:629
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:288
signal max:648
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:297
signal max:624
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:297
signal max:632
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:275
signal max:637
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:275
signal max:637
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:278
signal max:636
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:278
signal max:644
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:356
signal max:641
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:336
signal max:641
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:377
signal max:645
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:334
signal max:663
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:415
signal max:637
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:360
signal max:637
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:338
signal max:634
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:322
signal max:634
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:400
signal max:626
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:308
signal max:650
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:331
signal max:637
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:331
signal max:637
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:320
signal max:650
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 1 signal min:320
signal max:650
Volts:1.00
=-=-=-=-=-=-=-=-=-=-=-=
mic 0 signal min:333
signal max:630
Volts:1

zheng3
 
Posts: 20
Joined: Sun Jul 19, 2015 1:42 pm

Re: Comparing the output of two MAX4466's

by adafruit_support_bill on Thu Aug 25, 2016 3:58 pm

So you are seeing a peak-to-peak range of roughly 300 raw-counts. That is roughly 1.3 of full-scae. Not sure where the low numbers you were getting before came from.

Still, the math seems off:
Code: Select all | TOGGLE FULL SIZE
mic 0 signal min:322
signal max:636
Volts:1.00
=-=-=-=-=-=-=-=-


636 - 322 = 314
(314 * 5) / 1023 = 1.53 volts.

adafruit_support_bill
 
Posts: 62248
Joined: Sat Feb 07, 2009 10:11 am

Re: Comparing the output of two MAX4466's

by zheng3 on Thu Aug 25, 2016 4:32 pm

That is really odd. What could be clipping the voltage values to 1.0? The code's really simple:

double volts1 = (peakToPeak * 5) / 1024


Another strange thing: I thought maybe I could get away with just using the max values instead of doing the voltage math. So covering mic1 with a hand I hummed directly into mic0. Both mic maximums jump up by the same amount. Baseline maximums without the hum fluctuate around 628. So it's hearing *something* at least, but still no distingushing between them.

Code: Select all | TOGGLE FULL SIZE
mic 0 signal max:704
mic 1 signal max:704
mic 0 signal max:692
mic 1 signal max:692
mic 0 signal max:781
mic 1 signal max:781
mic 0 signal max:787
mic 1 signal max:787
mic 0 signal max:797
mic 1 signal max:797
mic 0 signal max:759
mic 1 signal max:759
mic 0 signal max:757
mic 1 signal max:757
mic 0 signal max:755
mic 1 signal max:755
mic 0 signal max:743
mic 1 signal max:743
mic 0 signal max:727
mic 1 signal max:727
mic 0 signal max:747
mic 1 signal max:747
mic 0 signal max:732
mic 1 signal max:732

zheng3
 
Posts: 20
Joined: Sun Jul 19, 2015 1:42 pm

Re: Comparing the output of two MAX4466's

by adafruit_support_bill on Thu Aug 25, 2016 4:55 pm

double volts1 = (peakToPeak * 5) / 1024

Since all of those numbers are integers, it is doing all integer math. Any fractional part will get truncated.
Try:
double volts1 = (peakToPeak * 5.0) / 1024.0

adafruit_support_bill
 
Posts: 62248
Joined: Sat Feb 07, 2009 10:11 am

Re: Comparing the output of two MAX4466's

by zheng3 on Sat Aug 27, 2016 9:13 am

Ok, so the math problem is fixed by changing those constants to floats (thanks!) but the original problem remains. I got the Serial Plotter working (the older Arduino IDE build I was using couldn't do multi-plots.) Check this out.

When I tap mic0 with a pencil, both mics register peaks. When I tap mic1, only mic1 peaks.

0_1.png
0_1.png (64.35 KiB) Viewed 119 times


So I changed the code to read from pin 5 instead of pin 1 and did the same tap test. There's no mic connected to pin 5, it's still in pin 1. You'd expect to see no peaks when I tap on mic1, and that's what the plot shows. Strangely tapping on mic0 still creates peaks for both microphones.

0_5.png
0_5.png (63.3 KiB) Viewed 119 times


...and then I disconnected mic1 entirely and tapped on mic0.

no_mic_1.png
no_mic_1.png (58.5 KiB) Viewed 119 times


I'm still getting readings off a microphone that's disconnected in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign on the door saying ‘Beware of the Leopard." Whaaaa?

I've tried this on a Duemilanove and an UNO with the same results.

zheng3
 
Posts: 20
Joined: Sun Jul 19, 2015 1:42 pm

Re: Comparing the output of two MAX4466's

by zheng3 on Sat Aug 27, 2016 9:20 am

...and here's the current code, just in case I'm doing something stupid. Occasionally I'm changing sample = analogRead(1); to sample = analogRead(5); for testing.

Code: Select all | TOGGLE FULL SIZE
    /****************************************
    Example Sound Level Sketch for the
    Adafruit Microphone Amplifier
    ****************************************/
     
    const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
    unsigned int sample;

    void setup()
    {
       Serial.begin(9600);
       pinMode(A0, INPUT);
       pinMode(A1, INPUT);
    }
     
     
    void loop()
    {

   
       unsigned long startMillis= millis();  // Start of sample window
       double peakToPeak = 0;   // peak-to-peak level

       
       unsigned int signalMax = 0.0;
       unsigned int signalMin = 1024.0;
     
       // collect data for 50 mS
       while (millis() - startMillis < sampleWindow)
       {
          sample = analogRead(0);
          if (sample < 1024)  // toss out spurious readings
          {
             if (sample > signalMax)
             {
                signalMax = sample;  // save just the max levels
             }
             else if (sample < signalMin)
             {
                signalMin = sample;  // save just the min levels
             }
          }
       }
       
       peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
       double volts0 = (peakToPeak * 5.0) / 1024.0;  // convert to volts
           
       startMillis= millis();

        while (millis() - startMillis < sampleWindow)
       {
          sample = analogRead(1);
          if (sample < 1024)  // toss out spurious readings
          {
             if (sample > signalMax)
             {
                signalMax = sample;  // save just the max levels
             }
             else if (sample < signalMin)
             {
                signalMin = sample;  // save just the min levels
             }
          }
       }
       peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
       double volts1 = (peakToPeak * 5.0) / 1024.0;  // convert to volts

        Serial.print(volts0);
        Serial.print(",");
        Serial.println(volts1);
       
 
    }

zheng3
 
Posts: 20
Joined: Sun Jul 19, 2015 1:42 pm

Re: Comparing the output of two MAX4466's

by adafruit_support_bill on Sat Aug 27, 2016 9:34 am

It is not unusual to see crosstalk like that on a disconnected 'floating' analog pin. If you were to tie it via a resistor to ground, the output would be steady.

What is strange is that you are seeing crosstalk from mic 1 when mic 2 is connected. What happens if you swap the microphone boards?

adafruit_support_bill
 
Posts: 62248
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.