Spectral Weighting Filters¶
Module name: splweighting
This module implements spectral weighting filters for the sound pressure level (SPL) in air according to [IEC61672]. Spectral weighting is part of aucoustic measurements. It is used by sound level meters for example. The weighting functions are derived from different equal loudness contours of human hearing. The weighted levels aim to provide a better correlation to the perception of loudness.
Implemented weighting functions¶
There are three weighting functions implemented:
 AWeighting: based on the 40phon equal loudness contour
 B and Cweighting: for sounds above 70 phon, (BWeighting is not used that often)
The filter coefficient design is based on the implementation of A and Cweighting in [R2].
The weighting functions are defined in [IEC61672] can be described by the following equations:
The frequency responses absolute values of all implemented weighting filters can be seen in the following figure:
(Source code, png, hires.png, pdf)
References¶
[IEC61672]  (1, 2) Electroacoustics  Sound Level Meters (http://www.iec.ch) 
[R2]  Christophe Couvreur, MATLAB(R) implementation of weightings, http://www.mathworks.com/matlabcentral/fileexchange/69octave, Faculte Polytechnique de Mons (Belgium) couvreur@thor.fpms.ac.be 
Functions¶

splweighting.
a_weighting_coeffs_design
(sample_rate)[source]¶ Returns b and a coeff of a Aweighting filter.
Parameters: sample_rate : scalar
Sample rate of the signals that well be filtered.
Returns: b, a : ndarray
Filter coefficients for a digital weighting filter.
See also
b_weighting_coeffs_design
 BWeighting coefficients.
c_weighting_coeffs_design
 CWeighting coefficients.
weight_signal
 Apply a weighting filter to a signal.
scipy.lfilter
 Filtering signal with b and a coefficients.
Examples
>>> b, a = a_weighting_coeff_design(sample_rate)
To Filter a signal use scipy lfilter:
>>> from scipy.signal import lfilter >>> y = lfilter(b, a, x)

splweighting.
b_weighting_coeffs_design
(sample_rate)[source]¶ Returns b and a coeff of a Bweighting filter.
BWeighting is no longer described in DIN61672.
Parameters: sample_rate : scalar
Sample rate of the signals that well be filtered.
Returns: b, a : ndarray
Filter coefficients for a digital weighting filter.
See also
a_weighting_coeffs_design
 AWeighting coefficients.
c_weighting_coeffs_design
 CWeighting coefficients.
weight_signal
 Apply a weighting filter to a signal.
Examples
>>> b, a = b_weighting_coeff_design(sample_rate)
To Filter a signal use :function: scipy.lfilter:
>>> from scipy.signal import lfilter >>> y = lfilter(b, a, x)

splweighting.
c_weighting_coeffs_design
(sample_rate)[source]¶ Returns b and a coeff of a Cweighting filter.
Parameters: sample_rate : scalar
Sample rate of the signals that well be filtered.
Returns: b, a : ndarray
Filter coefficients for a digital weighting filter.
See also
a_weighting_coeffs_design
 AWeighting coefficients.
b_weighting_coeffs_design
 BWeighting coefficients.
weight_signal
 Apply a weighting filter to a signal.
Examples
b, a = c_weighting_coeffs_design(sample_rate)
To Filter a signal use scipy lfilter:
from scipy.signal import lfilter y = lfilter(b, a, x)

splweighting.
plot_weightings
()[source]¶ Plots all weighting functions defined in :module: splweighting.

splweighting.
weight_signal
(data, sample_rate=44100, weighting='A')[source]¶ Returns filtered signal with a weighting filter.
Parameters: data : ndarray
Input signal to be filtered.
sample_rate : int
Sample rate of the signal.
weighting : {‘A’, ‘B’, ‘C’}
Specify the weighting function by a string.
Returns: outdata : ndarray
Filtered output signal. The output will be weighted by the specified filter function.