From ba46cda7f14bd364826cf325d69917175e67baf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20St=C4=99pie=C5=84?= <4030444+adrian-stepien@users.noreply.github.com> Date: Fri, 7 Dec 2018 19:02:45 +0000 Subject: [PATCH 1/2] [SIGNAL] Added peak calibration Knowing what is the SPL corresponding to 0 dBFS its possible to calibrate the signal. --- acoustics/_signal.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/acoustics/_signal.py b/acoustics/_signal.py index 429ad081..4bcdb57f 100644 --- a/acoustics/_signal.py +++ b/acoustics/_signal.py @@ -5,7 +5,7 @@ from scipy.signal import detrend, lfilter, bilinear, spectrogram, filtfilt, resample, fftconvolve import acoustics -from acoustics.standards.iso_tr_25417_2007 import REFERENCE_PRESSURE +from acoustics.standards.iso_tr_25417_2007 import REFERENCE_PRESSURE, sound_pressure_level from acoustics.standards.iec_61672_1_2013 import WEIGHTING_SYSTEMS from acoustics.standards.iec_61672_1_2013 import (NOMINAL_OCTAVE_CENTER_FREQUENCIES, NOMINAL_THIRD_OCTAVE_CENTER_FREQUENCIES) @@ -119,6 +119,22 @@ def calibrate_with(self, other, decibel, inplace=False): gain = decibel - other.leq() return self.gain(gain, inplace=inplace) + def calibrate_peak(self, decibel, inplace=False): + """Calibrate signal knowing its SPL for peak FS. + + :param decibel: Peak FS value to calibrate to. + :param inplace: Whether to perform inplace or not. + :returns: Calibrated signal. + :rtype: :class:`Signal` + + Values of `decibel` are broadcasted. To set a value per channel, use `decibel[...,None]`. + """ + # Calculate the gain so that samples represent the pressure values + # We know that peak value equals 1. 1 Pa is roughly 94 dB SPL. + # In that case, we have to boost the signal by decibel - ~94. + gain = decibel * np.ones(self.shape) - sound_pressure_level(1) + return self.gain(gain, inplace=inplace) + def decimate(self, factor, zero_phase=False, ftype='iir', order=None): """Decimate signal by integer `factor`. Before downsampling a low-pass filter is applied. From e9fabe9b20c64f6426d246ed92041bc20a9e56ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20St=C4=99pie=C5=84?= <4030444+adrian-stepien@users.noreply.github.com> Date: Mon, 17 Feb 2020 13:17:22 +0000 Subject: [PATCH 2/2] [SIGNAL] Renamed calibrate_peak to calibrate_with_peak Just to keep it more descriptive. --- acoustics/_signal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acoustics/_signal.py b/acoustics/_signal.py index 4bcdb57f..52abd16e 100644 --- a/acoustics/_signal.py +++ b/acoustics/_signal.py @@ -119,7 +119,7 @@ def calibrate_with(self, other, decibel, inplace=False): gain = decibel - other.leq() return self.gain(gain, inplace=inplace) - def calibrate_peak(self, decibel, inplace=False): + def calibrate_with_peak(self, decibel, inplace=False): """Calibrate signal knowing its SPL for peak FS. :param decibel: Peak FS value to calibrate to.