Go Down

Topic: Convert voltage to dB (Read 9306 times) previous topic - next topic

aarg

See reply #25 of the 3 month old thread that you brought back from the dead.
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

wahyu21

#31
Nov 03, 2015, 05:30 pm Last Edit: Nov 03, 2015, 05:48 pm by wahyu21
can you help me for creating the completly program of this...

this my proggram

#include <LiquidCrystal.h>             // 0

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // 1
int val;                               // 2
int dB;                                // 3
const int sensorPin = A0;              // 4

char in;                               // 5
int sensorVal = 0;                   // 6
int smoothedVal = 200;               // 7
int samples = 4;                     // 8
void setup() {                         // 9

pinMode(6, OUTPUT);                  // 10
pinMode(7, OUTPUT);                  // 11
pinMode(8, OUTPUT);                  // 12
pinMode(9, OUTPUT);                  // 13

lcd.begin(16, 2);                    // 14
lcd.setCursor(1,0);                  // 15
lcd.print("DESIBEL METER");          // 16
lcd.setCursor(5,1);                  // 17
lcd.print("W-Tech");                 // 18
delay(300);                          // 29
lcd.clear();                         // 20
// Print a message to the LCD.  
Serial.begin(9600);                  // 21

}

void loop() {                          // 22
//int val;
lcd.clear();                         // 23

val = analogRead(sensorPin);         // 24
smoothedVal = smoothedVal + ((val - smoothedVal)/samples); //25
val = smoothedVal*0.6779+32.755;      // 26
dB = val*0.5228 + 35.271;             // 27
Serial.println(dB);                  // 28

if(analogRead(sensorPin)<=0){        // 29
lcd.setCursor(0,0);                  // 30
lcd.print(" DESIBEL METER");         // 31
lcd.setCursor(0,1);                  // 32
lcd.print("press red button");}      // 33
else{                                // 34

lcd.setCursor(1,0);                  // 35
lcd.print("DESIBEL METER");          // 36
lcd.setCursor(0,1);                  // 37
lcd.print(dB+2);                       // 38
lcd.setCursor(5,1);                  // 39
lcd.print("dB");                     // 40
lcd.setCursor(8,1);                  // 41
lcd.print("W-Tech");}                // 42

delay(250);                          // 43

if (val>=45){ digitalWrite(6,1);}   // 44
else {digitalWrite(6,0);}           // 45
if (val>=55) {digitalWrite(7,1);}   // 46
else  {digitalWrite(7,0);}         // 47
if (val>=60) {digitalWrite(8,1);}  // 48
else {digitalWrite(8,0);}          // 49
if (val>=70) {digitalWrite(9,1);}  // 50
else {digitalWrite(9,0);}          // 51
 
}


i use linearity to convert my ADC......
help me for changes to 20log10....26 and 27 is my conversion of my ADC

aarg

Welcome to the Forum. Please read the two posts at the top of this Forum by Nick Gammon on guidelines for posting here, especially the use of code tags which make the code look
Code: [Select]
like thiswhen posting source code files. Also, before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read.

If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button.
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

wahyu21


PaulMurrayCbr

#34
Nov 04, 2015, 02:32 am Last Edit: Nov 04, 2015, 02:44 am by PaulMurrayCbr
Quote
(i.e. 0 would then equal approximately 20-30 dB).
Ok, that's weird. I would have thought that a reading of 0 comes to negative infinity db.

To make your calculation, we need two points on your scale - assuming that voltage corresponds linearly to SPL. And we can't use point 0 (no sound at all) because decibels are logarithmic. We'll do everything using floating point.

As always, I suffix everything with the unit of measure.

Code: [Select]

// When the analog in is 100, then the reading should be 40db
const double V0 = 100;
const double V0_dB = 40;

// When the analog in is 1020, then the reading should be 80db
const double V1 = 1020;
const double V1_dB = 80;

// pre-calculate the scaling constants
// convert units to bels rather than decibels
const double inV0_Bel = log10(V0);
const double inV1_Bel = log10(V1);
const double outV0_Bel = V0_dB / 10;
const double outV1_Bel = V1_dB / 10;
const double scalingConstant = (outV1_Bel-outV0_Bel) / (inV1_Bel-inV0_Bel);

float analog2db(int V) {
  double inV_Bel = log10(V);
 
  // scale to correct range
  double outV_Bel = (inV_Bel-inV0_Bel) * scalingConstant + outV0_Bel;
 
  return outV_Bel * 10; // deci-bels
}



http://paulmurraycbr.github.io/ArduinoTheOOWay.html

wahyu21

I still don't get it...can you create the program from begining until the end?i really need this...i still dont get it how to change the analog voltage to decibel....

MiFi

So, is there any formula that works to convert the voltage in dB SPL? I have tried many different ways, but I always get false results. There has to be something out there - or if could someone direct me to resources?

Again, I want to convert the voltage in db SPL (sound pressure level), with a minimum value of around 30dB, and a maximum at around 90dB.
Thanks!
And you are aware that  60 dB represents a dynamic range of one to one million?
You shoud not even try doing that in software.

You need analog hardware upfront with a logarithmic amplifier.

MiFi

After some time I returned to finish this project. So far, still, no answer to make it work as closely as possible to as a dB meter.

I'm reading this article (http://www.inmotion.pt/store/phidgets-sound-sensor) saying that there is a formula that can be used to get the dB conversion (for 1kHz sound for example).

SPL at 1kHz tone (dB) = 16.801 x ln(sensorValue/1023) + 9.872


I tried the formula but I got nothing. I don't know what the ln stands for  :smiley-roll:

Maybe someone could help?
If you want to to "make it work as closely as possible to as a dB meter", you have got a LOT to do!

You will need extreme low noise amplifiers, an (A) curve or a (C) curve filter, decoupling amplifiers again and finally a logarithmic demodulating amplifier. Not to mention a reliable microphone that has at least 60dB dynamic...
Good luck!

The phidget sound sensor does not appear to match these requirements.
Halas, since I am still seeking for a shield that does exactly that.



Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy