Open Astro-Pete opened 1 year ago
OK, after some more digging around I found the #98 thread with info on the bug in urban.py about the incorrect / 3.3 * 65535 line. Would still like to know how V relates to dB though??
I’ve also downloaded the newer firmware as I had the failed to connect to wifi issue too.
I didn’t see a thread specific to the noise sensor issue so that’s why I posted.
Hi @Astro-Pete. As you spotted, there was an error in the code, that was subsequently fixed in patch v0.0.9.
As for relating V to dB, that's something I looked into but did not find a definitive answer for how to do that conversion (since V is an absolute measurement, and dB is a relative measurement). I would happily accept a pull request from someone knowledgeable in the area.
Hi @ZodiusInfuser - I have spent a few days down this rabbit hole and there is a solution. I may get round to a pull, but now that my Urban is operational I'd have to take it down to hack it. I currently do the calculation post reading. This provides the solution.
https://electronics.stackexchange.com/questions/96205/how-to-convert-volts-to-db-spl
The one thing that is not in the specification is the gain on the operational amp, which the spec says is "user defined" - this would make sense as one may wish to use a variable resistor across the op amp to adjust the gain. You need to subtract this gain from your final reading because the reading has been amplified.
The specification states the gain is a ratio of two resistors, but no values are given. No schematic either. Since you guys put this together, would you know that gain?
Note we are just taking peak values and have no frequency or multiple samples to do a mean-square average. So its somewhat of a fudge, and some people may prefer the raw data to a fudged dB value.
Roughly, by comparing the to an app on my phone and adjusting the offset/gain to get a similar answer. I came up with (logs are base 10)
dB (SPL) = 20 * log( reading_in_volts / 0.0078125 ) + 94 - GAIN
GAIN was calibrated to 59dB
(I use the term "calibrated" very loosely), so the offset is +35dB
.
0.0078125
is the conversion of the "Typical" sensitivity -42 dBV/Pa
(from the spec) to volts, based on a 94dB wave @1kHz. This is your "reference" voltage. Basically, a voltage reading from the mic (before amplification) of a 1kHz signal at 94dB would give you 0.0078125 Volts: put that reading in the above formula and you get 94 dB (GAIN=0).
The 20*log(ratio)
is the standard calculation of volts to dB based on our reference voltage sensitivity.
Note the stack overflow formula mentions the offset from the log is +94-GAIN-42
(as 94dB is reference level, remove the gain, and remove the sensitivity.). Others later corrected this removing the sensitivity. Either way, its a constant, so it doesn't change once you know it.
@Astro-Pete - FYI
Will nudge this as I know there were issues with GitHub and my comments appearing when I posted the above.
The formula (and its derivation) is explained very long-windedly here:
This could be put in the enviro-urban code, but I object to doing so on the premise that a Scientific Instrument should return the raw data, what you do with that post-processing is your business.
Secondly, the formula is an approximation as the Specification sheet states the gain is determined by the ratio of two resistors that the installer would have provided. So the +35
offset was taken by calibrating against a smartphone app, if these resistors are known, one could get a more accurate formula.
So someone is welcome to change the code, as I probably am not motivated to do so myself for the above reasons. I'd suggest a config parameter that allows you to choose decibels or the raw voltage reading.
@ZodiusInfuser - I'm happy to make a more succinct writeup for the doco as a pull request.
Thanks, I hope this helps.
I seem to get a constant 1.5V reading. Is this sensor functional? Even if i shout at it while it takes a reading it only jumps to say 1.53V
Also is there any info on how to convert this reading to dB?