How to convert magnitude to dB

Hi there

to the point, Im looking for alternatives to convert magnitude(FreqVal[ ])array to dB [] array

Im using a df robot audio spectrum analyzer that features the MSGEQ7 graphic equalizer display filter.

with
1 sound sensor

and
with arduino mrk 1000
here is the code

#include <AudioAnalyzer.h>
//Version 1.3 for Spectrum analyzer
//Please download the latest library from the Product page!

Analyzer Audio = Analyzer(4,5,0);//Strobe pin ->4  RST pin ->5 Analog Pin ->0
//Analyzer Audio = Analyzer();//Strobe->4 RST->5 Analog->0

int FreqVal[7];//

void setup()
{
  Serial.begin(57600); //Init the baudrate
  Audio.Init();//Init module 
}

void loop()
{
  Audio.ReadFreq(FreqVal);//return 7 value of 7 bands pass filiter 
                          //Frequency(Hz):63  160  400  1K  2.5K  6.25K  16K
                          //FreqVal[]:      0    1    2    3    4    5    6  
  for(int i=0;i<7;i++)            
  {
    Serial.print(max((FreqVal[i]-100),0));//Transimit the DC value of the seven bands
    if(i<6)  Serial.print(",");
    else Serial.println();
  }
  delay(20);
}

and here is the shematics


any idea would be appreciated

Please fix your post so it makes some sense. You used code tags instead of links. Oh, and perhaps a proper schematic rather than a picture with Arduino Diecimila clone with connections to pins that don’t exsist on the MKR1000.

the wiring is the same like in the pic with Arduino Diecimila clone
Strobe pin ->4 RST pin ->5 Analog Pin ->0

My question is actually instead of converting all the analog input is rather just

How would be possible to read only always the highest,- in terms of magnitude,- freq band range
so the serial port would read depending of the magnitude just one the followings
63 160 400 1K 2.5K 6.25K 16K

in other words how to pick only the highest value from an array and we can still identify it with its label?

this how it works apart from the dB the conversion I assume isnt working according the results

/*
 This example reads audio data from an Invensense's ICS43432 I2S microphone
 breakout board, and uses the input to detect clapping sounds. An LED is
 togggled when a clapp is detected.

 Circuit:
 * Arduino/Genuino Zero, MKRZero or MKR1000 board
 * ICS43432:
   * GND connected GND
   * 3.3V connected 3.3V (Zero) or VCC (MKR1000, MKRZero)
   * WS connected to pin 0 (Zero) or pin 3 (MKR1000, MKRZero)
   * CLK connected to pin 1 (Zero) or pin 2 (MKR1000, MKRZero)
   * SD connected to pin 9 (Zero) or pin A6 (MKR1000, MKRZero)

 created 18 November 2016
 by Sandeep Mistry
 */

#include <ArduinoSound.h>

// the LED pin to use as output
const int ledPin = LED_BUILTIN;

// the amplitude threshold for a clap to be detected
const int amplitudeDeltaThreshold = 100000000;

// create an amplitude analyzer to be used with the I2S input
AmplitudeAnalyzer amplitudeAnalyzer;

// variable to keep track of last amplitude
int lastAmplitude = 0;

void setup() {
  // setup the serial
  Serial.begin(9600);

  // configure the LED pin as an output
  pinMode(ledPin, OUTPUT);

  // setup the I2S audio input for 44.1 kHz with 32-bits per sample
  if (!AudioInI2S.begin(44100, 32)) {
    Serial.println("Failed to initialize I2S input!");
    while (1); // do nothing
  }

  // configure the I2S input as the input for the amplitude analyzer
  if (!amplitudeAnalyzer.input(AudioInI2S)) {
    Serial.println("Failed to set amplitude analyzer input!");
    while (1); // do nothing
  }
}

void loop() {
  // check if a new analysis is available
  if (amplitudeAnalyzer.available()) {
    // read the new amplitude
    int amplitude = amplitudeAnalyzer.read();

    // find the difference between the new amplitude and the last
    int delta = amplitude - lastAmplitude;
  
    // check if the difference is larger than the threshold
    if (delta > amplitudeDeltaThreshold) {
      // a clap was detected
      Serial.println("clap detected");
  
      // toggle the LED
      digitalWrite(ledPin, !digitalRead(ledPin));
  
      // delay a bit to debounce
      delay(100);
    }
  
    // update the last amplitude with the new amplitude
    lastAmplitude = amplitude;
  }
}

so I was wondering if there are any MSGEQ7 related volume meter option

dB is the logarithm of a ratio. You must determine the zero dB level in order to calculate it.

now it seems that Volume works in both code

Apology to share this whole, but I dont know how else could I explain better.
In my test code it can id in realtime the peak of the frequenzy range ,

#include "ThingSpeak.h"
#include <SPI.h>
#include <Wire.h>
#include <WiFi101.h>
#include <FHT.h> //source http://wiki.openmusiclabs.com/wiki/ArduinoFHT?action=AttachFile&do=view&target=ArduinoFHT4.zipt&target=ArduinoFHT4.zip
#include <AudioAnalyzer.h>//source image.dfrobot.com/image/data/DFR0126/library/AudioAnalyzer%20v1.3.zip

//------------Initialize the variables for the AUDIO sensor

#define SoundSensorPin A0  //this pin read the analog voltage from the sound level meter
#define VREF  5.0 

//to identify which freq band range is the loudest,
// its need to be labelled by its peak num
// Always show the max magnitude from the sound signal

Analyzer Audio = Analyzer(4,5,0);//Strobe pin ->4  RST pin ->5 Analog Pin ->0
    //Analyzer Audio = Analyzer();//Strobe->4 RST->5 Analog->0 
int max_index = 0;//
String FreqNames[] = {"63", "160","400", "1K","2.5K", "6.25K","16K"};
int FreqVal[7];//
int hz = 0;
float voltageValue,dB;


//to identify the testperson
int testperson = 1;


// Create instance of WiFi client
WiFiClient client;
char ssid[] = SECRET_SSID;        //  your network SSID (name) //Weyland-Yutani Corp.
char pass[] = SECRET_PASSWORD;    // your network password (if needed)
//unsigned long myChannelNumber = SECRET_CH_ID;//channel ID
//const char * myWriteAPIKey = SECRET_WRITE_APIKEY;// write api key

// Add yourThingSpeak channel information here
unsigned long myChannelNumber = 630023;
const char * myWriteAPIKey = "8YTDWEWVV8V6JI08";


//---------------------------------------------------------------
void setup()
{
    //Serial.begin(9600);   // open serial over USB at 9600 baud
    Serial.begin(57600); //Init the baudrate
    
    
    Audio.Init();//Init module  ?

    // Initialise the I2C sensors and ping them
    //sensor.begin();
    
    // Initialise the ThingSpeak library
    ThingSpeak.begin(client);
}


//---------------------------------------------------------------
void loop()
{
  // Connects to the WiFi
  // If the network does not need a password: WiFi.begin(ssid);
  WiFi.begin(ssid, pass);
  delay(10000);   // Waits 10 seconds to confirm connection
  
  // Print WiFi strength information
  printCurrentNet();
  //Run the Sensors
  runAudioSensor();
  
  // Get the latest readings from the sensor
 // hz = sensor.getfreq();
  //dB = sensor.getdB();
  //testperson = sensor.getid();
  
  // Double-check if the field IDs are correct
  ThingSpeak.setField(1, hz);
  ThingSpeak.setField(2, dB);
  ThingSpeak.setField(3, testperson);
  // Upload sensor data to ThingSpeak
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 

  // Print sensor data to the Serial Monitor, so that we can
  // double-check the correct values are being uploaded to ThingSpeak
  printInfo();
  
  // Disconnects from the WiFi
  WiFi.disconnect();
  
  // ThingSpeak will only accept updates every 15 seconds
  delay(15000);
}



void runAudioSensor()
{
  
    Audio.ReadFreq(FreqVal);//return 7 value of 7 bands pass filiter 
                          //Frequency(Hz):63  160  400  1K  2.5K  6.25K  16K
                          //FreqVal[]:      0    1    2    3    4    5    6  magnitude
  
  
  
    for(int i=1; i<7; i++)   //         
  {
    if (FreqVal[max_index] < FreqVal[i]) max_index = i;
  }
   int hz = FreqVal[max_index];
   
   voltageValue = analogRead(SoundSensorPin) / 1024.0 * VREF;
   dB = voltageValue * 50.0;
   //float dB = (hz + 83.2073) / 11.003; //convert the bits to dB
  
}


//---------------------------------------------------------------
void printInfo()
{
  Serial.print("Time: ");
  Serial.print(millis());
  Serial.print("ms; ");
  
  //int hz = FreqVal[max_index];
  
  Serial.print("Frequenzy: ");
  Serial.print(FreqNames[max_index]);
  Serial.println("hz");

 
 //float dB = (hz + 83.2073) / 11.003; //convert the bits to dB
 
  Serial.print("Volume: ");
  Serial.print(dB,0);
  Serial.println("dB");
  Serial.println("");//?
  
  
  Serial.println("testperson1");
  
}


//---------------------------------------------------------------
void printCurrentNet() {
  // Print the WiFi signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("Signal strength (RSSI): ");
  Serial.print(rssi);
  Serial.println(" dBm");
}

but when Im using the thingspeak code the freq is always constant
both of the code works

#include "ThingSpeak.h"
#include <SPI.h>
#include <Wire.h>
#include <WiFi101.h>
#include <FHT.h> //source http://wiki.openmusiclabs.com/wiki/ArduinoFHT?action=AttachFile&do=view&target=ArduinoFHT4.zipt&target=ArduinoFHT4.zip

#include <AudioAnalyzer.h>//source image.dfrobot.com/image/data/DFR0126/library/AudioAnalyzer%20v1.3.zip

//------------Initialize the variables for the AUDIO sensor

#define SoundSensorPin A0  //this pin read the analog voltage from the sound level meter
#define VREF  5.0 

//to identify which freq band range is the loudest,
// its need to be labelled by its peak num
// Always show the max magnitude from the sound signal

Analyzer Audio = Analyzer(4,5,0);//Strobe pin ->4  RST pin ->5 Analog Pin ->0
//Analyzer Audio = Analyzer();//Strobe->4 RST->5 Analog->0 
int max_index = 0;//
int FreqNames[] = {63,160,400,1000,2500,6500,16000};//peak of the freq range
int FreqVal[7];//
int hz = 0;
float voltageValue,dB;


//to identify the testperson
int testperson = 1;


// Create instance of WiFi client
WiFiClient client;
char ssid[] = SECRET_SSID;        //  your network SSID (name) 
char pass[] = SECRET_PASSWORD;    // your network password (if needed)


// Add yourThingSpeak channel information here
unsigned long myChannelNumber = 630023;
const char * myWriteAPIKey = "8YTDWEWVV8V6JI08";


//---------------------------------------------------------------
void setup()
{

    Serial.begin(57600); //Init the baudrate
    
    
    Audio.Init();//Init module  ?

    // Initialise the I2C sensors and ping them
    //sensor.begin();
    
    // Initialise the ThingSpeak library
    ThingSpeak.begin(client);
}


//---------------------------------------------------------------
void loop()
{
  // Connects to the WiFi
  // If the network does not need a password: WiFi.begin(ssid);
  WiFi.begin(ssid, pass);
  delay(10000);   // Waits 10 seconds to confirm connection
  
  // Print WiFi strength information
  printCurrentNet();
  //Run the Sensors
  runAudioSensor();
  
  // Get the latest readings from the sensor
 // hz = sensor.getfreq();
  //dB = sensor.getdB();
  //testperson = sensor.getid();
  
  // Double-check if the field IDs are correct
  ThingSpeak.setField(1, hz);
  ThingSpeak.setField(2, dB);
  ThingSpeak.setField(3, testperson);
  // Upload sensor data to ThingSpeak
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 

  // Print sensor data to the Serial Monitor, so that we can
  // double-check the correct values are being uploaded to ThingSpeak
  printInfo();
  
  // Disconnects from the WiFi
  WiFi.disconnect();
  
  // ThingSpeak will only accept updates every 15 seconds
  delay(15000);
}



void runAudioSensor()
{
  
    Audio.ReadFreq(FreqVal);//return 7 value of 7 bands pass filiter 
                          //Frequency(Hz):63  160  400  1K  2.5K  6.25K  16K
                          //FreqVal[]:      0    1    2    3    4    5    6  magnitude
  
  
  
    for(int i=1; i<7; i++)   //         
  {
    if (FreqVal[max_index] < FreqVal[i]) max_index = i;
  }
   int hz = FreqVal[max_index];
   
   voltageValue = analogRead(SoundSensorPin) / 1024.0 * VREF;
   dB = voltageValue * 50.0;
   //float dB = (hz + 83.2073) / 11.003; //convert the bits to dB
  
}


//---------------------------------------------------------------
void printInfo()
{
  Serial.print("Time: ");
  Serial.print(millis());
  Serial.print("ms; ");
  
  //int hz = FreqVal[max_index];
  
  Serial.print("Frequenzy: ");
  Serial.print(FreqNames[max_index]);
  Serial.println("hz");

 
 //float dB = (hz + 83.2073) / 11.003; //convert the bits to dB
 
  Serial.print("Volume: ");
  Serial.print(dB,0);
  Serial.println("dB");
  Serial.println("");//?
  
  
  Serial.println("testperson1");
  
}


//---------------------------------------------------------------
void printCurrentNet() {
  // Print the WiFi signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("Signal strength (RSSI): ");
  Serial.print(rssi);
  Serial.println(" dBm");
}

the only difference is that i have separated the functions,
in if it might help to to understand better