1

I'm trying to convert an amplified microphone output (it is from 0-5v, biased at 2.5v) to a linear response that correlates with db SPL.

From my research, the output of the microphone directly correlates to the sound pressure, which is all fine, but I need to represent this in db. I am reading values from the mic with an arduino, which only has 10 bits of precision, meaning I cannot rely on converting the values into db on digital side because of the huge dynamic range that db covers which would mean very little of the db range would be represented inside the 10 bits since db is logarithmic to sound pressure.

So, how would I go about modifying the analog signal so that the output represents db SPL? I have read about logarithmic op amps but still don't fully understand how they could be used in this situation, or if they are what I'm looking for.

MarkU
  • 14,413
  • 1
  • 34
  • 53
Warrick
  • 127
  • 6
  • How much dynamic range are you trying to achieve. – Andy aka May 17 '16 at 11:36
  • Ideally 60-120 db. Precision is not so much of a worry (around 1db), and if I can map (linearly) the 60-100ish db to the 1024 digital range it would be perfect for what I'm trying to achieve. – Warrick May 17 '16 at 21:06
  • Given that you appear to be considering converting the analogue signal directly to an RMS value (and then to a dB value), what frequency range (and sampling rate) have you considered? – Andy aka May 18 '16 at 07:18
  • The reference is 1khz, currently I have been sampling at a rate of about 8khz on the digital side, but this may be moved to an analog envelope detector. – Warrick May 18 '16 at 23:26

2 Answers2

1

First, you could rectify and zero-reference your audio signal with an external circuit BEFORE feeding the DC signal voltage "envelope" into your Arduino. That would double your effective measurement range because you aren't throwing away half the dynamic range accommodating the 2.5V offset.

10 bits will give you around 60dB of dynamic range if you use the full scale. Converting the linear voltage measurement to logarithmic (for deciBels) is a simple mathematical function.

Richard Crowley
  • 14,382
  • 2
  • 20
  • 37
  • I'm not sure if I was very clear in my question, but this is the approach that won't work for me. I definitely understand your points about feeding the envelope, and I was always intending to do that, but I think it needs converted to a logarithmic scale before feeding into the arduino to gain the dynamic range I would like. – Warrick May 17 '16 at 21:08
  • When I use Google Image Search for **log converter circuit**, I see scores of circuits from theoretical concepts to practical examples. You are correct that you will achieve a better dynamic range by doing the log conversion first. – Richard Crowley May 17 '16 at 21:16
1

Using a log amp is the correct approach. Feed the output of your microphone into the log-amp. Then feed the log amp into your ADC.

One example is the TL-441 from Texas Instruments, about $10 from Mouser.

http://www.ti.com/product/TL441

http://www.mouser.sg/ProductDetail/Texas-Instruments/TL441CN/?qs=sGAEpiMZZMtOXy69nW9rM3%252bknWDosfXEqY%2fig3aTweg%3d

If $10 is too much you can create a cheap log-amp from two diodes a resistor and an op-amp. Wire the diodes in parallel each facing opposite ways between the op-amp output and negative input pin. Wire the resistor between your input voltage and the negative input pin. Attach the op-amp non-inverting input to your center reference (2.5V in your case)

Remember that the current through an ideal diode is...

Id = Is * (e^(Vd/n/Vt) - 1)

Vd is the voltage across the diode
Vt is the thermal voltage (26mV at 25C)
n is the diode ideality factor, typically somewhere between 1 and 2.
e is 2.71828...
Is is the diode reverse saturation current.
Id is the current through the diode.

Solving for Vd gives...
Vd = n * Vt * ln(Id/Is + 1)

Because of feedback the inverting input of the op-amp is held at the same voltage as the non-inverting input, which is 2.5V. With R wired between the input signal and the op-amp inverting input we have...

Id = (Vin - 2.5V) / R then...

So...

Vd = n * Vt * ln((Vin-2.5V)/R/Is + 1)

So the output of the amplifier is...

For Vin > 2.5 V...
Vout = 2.5V - Vd = 2.5V - n * Vt * ln(|Vin-2.5V|/R/Is + 1)

For Vin < 2.5 V...
Vout = 2.5V + Vd = 2.5V + n * Vt * ln(|Vin-2.5V|/R/Is + 1)

user4574
  • 11,816
  • 17
  • 30
  • Thank you for such a comprehensive answer! Regarding your suggestion on the TL441 I'm slightly confused as to how it would be setup with the 4 different stages. (Not a lot of experience with analog circuits) Also, how accurate would you say using diodes would be? – Warrick May 17 '16 at 21:59
  • The TL-441 is going to be more accurate than diodes overall because it is temperature compensated, but using diodes can be reasonably accurate if you plan to only use it at room temperature. The base-emitter junction of a BJT is a diode, and there are BJTs such as the MAT04 from Analog Devices that are made for use in log-amps. I once built an analog circuit that calculated 1/sqrt(x) to linearize a light sensor using the MAT04. The output was accurate to about 1% over three orders of magnitude. The first step in that circuit was calculating log(x). – user4574 May 18 '16 at 12:58
  • Also, decibels is normally calculated with a base 10 log, how does that work when diodes/log amps use a natural logarithm? – Warrick May 18 '16 at 23:25
  • Converting between log base 10 and natural log is just a constant scale factor that can be done in software later. Remember that in general log base y of x is ln(x)/ln(y). So log(x) = ln(x)/ln(10). – user4574 May 19 '16 at 20:09