Nano RP2040 Connect Microphone Spike

Hello! :slight_smile:
I am playing with the onboard microphone of the Arduino Nano RP2040 Connect.
I loaded the PDM example sketch, and only modified the Serial print to:

// Print samples to the serial monitor or plotter
for (int i = 0; i < samplesRead; i++) {
  Serial.print(-20000);
  Serial.print(" ");
  Serial.print(20000);
  Serial.print(" ");
  Serial.println(sampleBuffer[i]);
}

This allow to keep a kind of fixed Y axis scale by always printing the same upper and lower value. You can personalize the upper and lower value to your liking. The green curve is the microphone read values. I am able to see spikes passing by, even if there is no noise going on:
16k-spike
Sometimes they are positive, sometime negative. Always the same absolute value, arround 10k.

I tried reducing the PDM frequency from 16kHz to 8kHz, and the output is now really clean. Does anybody have any idea of what is happening?

Thank you!

I tried to replicate your issue but my signal stays clean the whole time. A signal this short and such a large amplitude should be audible. On the other hand any naturally occurring acoustic signal would have a negative part and some ringing afterwards.

1 Like

Yeah i agree, and there were no audible noise at all when i saw those spikes, so i have no clue of what is happening unless a hardware issue? :thinking:

I had a look at the schematic and PCB. There is not really a lot that can be broken. The PDM interface is digital and the two wires between the microphone and the RP2040 are short.

Are the spikes remaining when you change the setup e.g., use another USB cable, USB port, create some sound signal (preferably a near sine wave)?

1 Like

I might test this tomorrow and report results, it will be good opportunity to use the bench function generator, thank you :slight_smile:

Hello!
I made some tests today and I think I might have a clue :face_with_monocle:
First, i played a sine wave using a function generator and a small speaker:
IMG_3214 (1)

For this first test, I was using my original setup which is a raspberry pi 400, to compile and upload the PDM example to the Arduino Nano RP2040 Connect. Here are the results:
pi400-01
pi400-02
We can see those strange spikes, they can be positive or negative, and there was no other noise appart from the sine wave in the room.

I then moved to a windows laptop, hooked the arduino in it (I did not recompile or anything) and had a look at the Serial Plotter, I saw exactly the same spikes. Just to try some random tests, I modified the frequency from 16000 to 16001 from windows laptop, and there was no spike, only a clean sine wave. I put the frequency back to 16000, and still no spike.

I moved back the Arduino to the pi 400 without recompiling: no spike. A soon as I recompiled from pi 400: spikes were back.

This lead me to think that indeed, it is not a hardware problem but a software issue. The PDM example seems to be exactly the same on pi 400 and windows laptop, so it could be that the PDM.h library that i have on pi 400 and on the windows laptop are not the same, or that something bad happen during compilation on pi 400. I found on pi 400 that PDM library version was 1.0 in library.properties. Wanted to compare with the windows laptop, but could not found the location of it!

Do my conclusion looks tangible? Where can i locate the PDM library properties file on the windows laptop?

  1. Select File > Preferences from the Arduino IDE's menus.
  2. Check the box next to "Show verbose output during: [] compilation".
  3. Click the OK button.
  4. Open any sketch that has an #include directive for PDM.h. This one will do:
    #include <PDM.h>
    void setup() {}
    void loop() {}
    
  5. Select Sketch > Verify/Compile from the Arduino IDE's menus.
  6. Wait for the compilation to finish.

Now check the contents of the Click on the black console pane at the bottom of the Arduino IDE window. Near the bottom, you should see something like this:

Using library PDM at version 1.0 in folder: C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\2.3.1\libraries\PDM 

That is the location of the library. It also shows the version value from library.properties right there.

Of just as much interest is the 2.3.1 part of the path. This is the version of the "Arduino Mbed OS Nano Boards" platform in use, which you can also find in the Arduino IDE's Boards Manager. It would be good to check whether you have different versions of "Arduino Mbed OS Nano Boards" installed on the different machines.

1 Like

It turns out i was using 2.2.0 on raspberry pi 400 and 2.1.0 on the windows laptop.
After updating both to 2.3.1, i have spikes on both :woozy_face: they are half the previous amplitude though.

Well, I think i will stop my inquiry here... thank you Klaus_K and pert. It seems my problem was not present on 2.1.0, but i prefer to stay on last version.

I can confirm, I see spikes when I use board package 2.3.1.

I had a look at the difference between the two board packages. There were three lines of code changed in the following file:

..\mbed_nano\2.3.1\libraries\PDM\src\rp2040\PDM.cpp

Line 27: int decimation = 128; // this was 64 in version 2.1.0

 // Open_PDM_Filter_64 in 2.1.0
Line 182: Open_PDM_Filter_128(rawBuffer[rawBufferIndex], finalBuffer, 1, &filter);

Line 78: filter.MaxVolume = 1; // added in 2.3.1, does not seem to cause issue

I am not sure yet, how this causes the issue. I believe it should be OK to use the old values.

2 Likes

Good catch! I admit i was tired yesterday and a little discouraged after updating everything, just to have spikes on both platform :laughing:
Do you know if we can make like a report or something, so that the issue is looked into, or is this just too little of a problem? I think that for some case it could cause unwanted behavior, for example if you want to monitor ambient noise and want to react on a small threshold change.

You can submit bug reports or feature requests related to the "Arduino Mbed OS Nano Boards" platform here:
https://github.com/arduino/ArduinoCore-mbed/issues

You can see the development history for the PDM library here:
https://github.com/arduino/ArduinoCore-mbed/commits/master/libraries/PDM
but a change in a dependency (e.g., Arduino core library, Arduino core API, Mbed OS) can also be a factor, so the PDM library code base may not tell the full story.

1 Like

Thank you pert, i submitted a bug report.

Thanks @galloups!
In order to make it easily accessible to anyone interested in this subject, I'll share a link to the issue:

1 Like

The PDM example is cool, any idea what it measures? Is it loudness? Is there a conversion
to decibels?

The output of the example is a sampled signal of the sound wave. Just the PDM used to transfer the signal from the microphone to the Arduino interface may seem a bit harder to understand.

With PDM the more HIGH bits/pulses you have the higher the signal value. The maximum is a continuous HIGH signal. The lower the signal value the fewer pulses you have until you have a continuous LOW signal.

The advantages of Pulse Density Modulation are

  • immune to interference because it is digital

  • can be converted to analog signal using a low pass filter (very cheap)

Most users do not need to worry. The library takes care of everything. From the applications point of view the PDM is invisible.

It’s an electrical signal from the microphone, But what characteristic of sound is it measuring?

The signal is the sampled amplitude of the sound signal. What else would you expect?

For information, new version of Arduino Mbed OS Nano Boards has fixed the issue!

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.