python-acoustics icon indicating copy to clipboard operation
python-acoustics copied to clipboard

[SIGNAL] Added peak calibration

Open adrian-stepien opened this issue 7 years ago • 9 comments

Knowing what is the SPL corresponding to 0 dBFS its possible to calibrate the signal.

adrian-stepien avatar Dec 07 '18 19:12 adrian-stepien

@adrian-stepien I don't understand the logic here. How do you know the SPL corresponding to 0 dBFS? The typical way to calibrate dBFS to dB SPL would be to send in a calibrated signal (typically 94 or 114 dB from an acoustical calibrator/pistonphone) and then compare the current dB reading with the reference value. You can then offset the current reading by whatever difference is found.

Where does the assumption of "We know that peak value equals 1. 1 Pa" come from? 0 dBFS can correspond to any dB SPL depending on the gain structure of the equipment/software you are using. I don't think there is any way of hardcoding it like you have to just offset the gain by a fixed value.

Also, I'm not so familiar with the whole package, but your line 146 is just multiplying all decibel values by -92.98979. Assuming decibel is actually a logarithmic value, I don't think you'd want to do any calibration/adjustments via multiplication on log values.

topherbuckley avatar Dec 08 '18 06:12 topherbuckley

As far as I can see, the existing calibrate_to(...) and calibrate_with(...) sets the mean power of the signal to a certain dB SPL, but sometimes (with tones and a known input chain) you just know that 0 dBFS corresponds 27.3 dB SPL. In that case, it's nice to be able to say calibrate_peak(27.3).

Adrian's implementation adds 27.3 dB re 20uPa/MSB to the dBFS value, where MSB stands for a digital 1. So if you've measured -10 dB FS, your "calibrated" sound pressure level is 17.3 dB SPL.

Perhaps the "calibrated" terminology between the calibrate_ functions needs to be clearer.

tcanders avatar Dec 09 '18 00:12 tcanders

Thanks for the explanation, that clarifies it. I never used it myself like that, but it makes sense.

FRidh avatar Dec 09 '18 08:12 FRidh

@topherbuckley Certain devices offer you the calibration based on a peak amplitude. For example NTi XL2 embeds it in the filename, which allows for post-processing (see page 47). Obviously @tcanders nailed the explanation ;)

adrian-stepien avatar Dec 09 '18 19:12 adrian-stepien

@adrian-stepien thanks for the link. Hadn't seen that before.

@tcanders It still wasn't make sense to me how setting the gain by inputting a decibel value and then subtracting 93.979 dB from it does anything of value, so allow me to walk myself through it and maybe help others understand later on.

If you had some signal that you measured on this NTi XL2, and it had a marked 27.3 dB SPL peak (ignoring the fact that this is absurdly quiet for any peak :D) signal and you wanted to set the gain such that the entire signal levels were now converted from dBFS to dB SPL. This is the goal right?

Lets start with Adrian's assignment of the gain:

gain = decibel * np.ones(self.shape) - 20*np.log10(1/2e-5)

And then just simplify this argument to only look at the single value in the array which represents the peak value (27.3 in this case), since I don't know a way to render equations in markdown and this is getting messy already. You could then redefine the gain assignment as:

gain = decibel * - 20*np.log10(1/2e-5)

The actual gain factor from gain() is defined as:

factor = 10.0**(decibel/20.0)

Fully evaluating the return from gain() would get you the equation below. .

self * 10.0**( (decibel - 20*np.log10(1/2e-5) ) / 20.0)

I would expect this to evaluate to the pressure equivalent of 27.3 dB, i.e. 20*np.log10(return/2e-5) = 27.3, and it does! I wanted to continue this derivation to show it analytically, but plugging it in to python and seeing it work is enough for me before bedtime.

I'm satisfied with my walk-through, and hopefully this helps someone in my shoes later.

topherbuckley avatar Dec 11 '18 13:12 topherbuckley

Hi @FRidh, any chance for merging that change?

adrian-stepien avatar Feb 17 '20 15:02 adrian-stepien

This needs a rebase first.

FRidh avatar Feb 17 '20 15:02 FRidh

@FRidh I see. From what I can see, my branch is 4 commits ahead of the master. Thank you for your reply.

adrian-stepien avatar Feb 17 '20 15:02 adrian-stepien

Hi @adrian-stepien and @FRidh, will there be any more progress merging this PR?

jftsang avatar Aug 15 '22 11:08 jftsang