Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit c7bc939

Browse files
adrian-stepienAdrian Stepien
authored andcommitted
[SIGNAL] Added peak calibration
Knowing what is the SPL corresponding to 0 dBFS its possible to calibrate the signal.
1 parent 03aacc0 commit c7bc939

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎acoustics/_signal.pyx‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from scipy.signal import detrend, lfilter, bilinear, spectrogram, filtfilt, resa
77
import acoustics
88
import itertools
99

10-
from acoustics.standards.iso_tr_25417_2007 import REFERENCE_PRESSURE
10+
from acoustics.standards.iso_tr_25417_2007 import REFERENCE_PRESSURE, sound_pressure_level
1111
from acoustics.standards.iec_61672_1_2013 import WEIGHTING_SYSTEMS
1212
from acoustics.standards.iec_61672_1_2013 import (NOMINAL_OCTAVE_CENTER_FREQUENCIES,
1313
NOMINAL_THIRD_OCTAVE_CENTER_FREQUENCIES)
@@ -130,6 +130,22 @@ class Signal(numpy.ndarray):
130130
gain = decibel - other.leq()
131131
return self.gain(gain, inplace=inplace)
132132

133+
def calibrate_peak(self, decibel, inplace=False):
134+
"""Calibrate signal knowing its SPL for peak FS.
135+
136+
:param decibel: Peak FS value to calibrate to.
137+
:param inplace: Whether to perform inplace or not.
138+
:returns: Calibrated signal.
139+
:rtype: :class:`Signal`
140+
141+
Values of `decibel` are broadcasted. To set a value per channel, use `decibel[...,None]`.
142+
"""
143+
# Calculate the gain so that samples represent the pressure values
144+
# We know that peak value equals 1. 1 Pa is roughly 94 dB SPL.
145+
# In that case, we have to boost the signal by decibel - ~94.
146+
gain = decibel * np.ones(self.shape) - sound_pressure_level(1)
147+
return self.gain(gain, inplace=inplace)
148+
133149
def decimate(self, factor, zero_phase=False, ftype='iir', order=None):
134150
"""Decimate signal by integer `factor`. Before downsampling a low-pass filter is applied.
135151

0 commit comments

Comments
 (0)