audio_dspy package¶
Submodules¶
audio_dspy.eq_design module¶
-
audio_dspy.eq_design.
add_to_sos
(sos, b, a)¶ Add a new filter to a set of second order sections
Parameters: - sos (array-like) – Set of second order sections
- b (array-like) – feed-forward coefficients of filter to add
- a (array-like) – feed-back coefficients of filter to add
Returns: sos – New set of second order sections
Return type: array-like
-
audio_dspy.eq_design.
bilinear_biquad
(b_s, a_s, fs, matchPole=False)¶
-
audio_dspy.eq_design.
butter_Qs
(n)¶ Generate Q-values for an n-th order Butterworth filter
Parameters: n : int
order of filter to generate Q values forReturns: q_values – Set of Q-values for this order filter Return type: array-like
-
audio_dspy.eq_design.
design_HPF1
(fc, fs)¶ Calculates filter coefficients for a 1st-order highpass filter
Parameters: - fc (float) – Cutoff frequency of the filter in Hz
- fs (float) – Sample rate in Hz
Returns: - b (ndarray) – “b” (feedforward) coefficients of the filter
- a (ndarray) – “a” (feedback) coefficients of the filter
-
audio_dspy.eq_design.
design_HPF2
(fc, Q, fs)¶ Calculates filter coefficients for a 2nd-order highpass filter
Parameters: - fc (float) – Cutoff frequency of the filter in Hz
- Q (float) – Quality factor of the filter
- fs (float) – Sample rate in Hz
Returns: - b (ndarray) – “b” (feedforward) coefficients of the filter
- a (ndarray) – “a” (feedback) coefficients of the filter
-
audio_dspy.eq_design.
design_HPFN
(fc, Q, N, fs)¶ Calculates filter coefficients for a Nth-order highpass filter
Parameters: - fc (float) – Cutoff frequency of the filter in Hz
- Q (float) – Quality factor of the filter
- N (int) – Desired filter order
- fs (float) – Sample rate in Hz
Returns: sos – Filter coefficients as a set of second-order sections
Return type: ndarray
-
audio_dspy.eq_design.
design_LPF1
(fc, fs)¶ Calculates filter coefficients for a 1st-order lowpass filter
Parameters: - fc (float) – Cutoff frequency of the filter in Hz
- fs (float) – Sample rate in Hz
Returns: - b (ndarray) – “b” (feedforward) coefficients of the filter
- a (ndarray) – “a” (feedback) coefficients of the filter
-
audio_dspy.eq_design.
design_LPF2
(fc, Q, fs)¶ Calculates filter coefficients for a 2nd-order lowpass filter
Parameters: - fc (float) – Cutoff frequency of the filter in Hz
- Q (float) – Quality factor of the filter
- fs (float) – Sample rate in Hz
Returns: - b (ndarray) – “b” (feedforward) coefficients of the filter
- a (ndarray) – “a” (feedback) coefficients of the filter
-
audio_dspy.eq_design.
design_LPFN
(fc, Q, N, fs)¶ Calculates filter coefficients for a Nth-order lowpass filter
Parameters: - fc (float) – Cutoff frequency of the filter in Hz
- Q (float) – Quality factor of the filter
- N (int) – Desired filter order
- fs (float) – Sample rate in Hz
Returns: sos – Filter coefficients as a set of second-order sections
Return type: ndarray
-
audio_dspy.eq_design.
design_bell
(fc, Q, gain, fs)¶ Calculates filter coefficients for a bell filter.
Parameters: - fc (float) – Center frequency of the filter in Hz
- Q (float) – Quality factor of the filter
- gain (float) – Linear gain for the center frequency of the filter
- fs (float) – Sample rate in Hz
Returns: - b (ndarray) – “b” (feedforward) coefficients of the filter
- a (ndarray) – “a” (feedback) coefficients of the filter
-
audio_dspy.eq_design.
design_highshelf
(fc, Q, gain, fs)¶ Calculates filter coefficients for a High Shelf filter.
Parameters: - fc (float) – Center frequency of the filter in Hz
- Q (float) – Quality factor of the filter
- gain (float) – Linear gain for the shelved frequencies
- fs (float) – Sample rate in Hz
Returns: - b (ndarray) – “b” (feedforward) coefficients of the filter
- a (ndarray) – “a” (feedback) coefficients of the filter
-
audio_dspy.eq_design.
design_lowshelf
(fc, Q, gain, fs)¶ Calculates filter coefficients for a Low Shelf filter.
Parameters: - fc (float) – Center frequency of the filter in Hz
- Q (float) – Quality factor of the filter
- gain (float) – Linear gain for the shelved frequencies
- fs (float) – Sample rate in Hz
Returns: - b (ndarray) – “b” (feedforward) coefficients of the filter
- a (ndarray) – “a” (feedback) coefficients of the filter
-
audio_dspy.eq_design.
design_notch
(fc, Q, fs)¶ Calculates filter coefficients for a notch filter.
Parameters: - fc (float) – Center frequency of the filter in Hz
- Q (float) – Quality factor of the filter
- fs (float) – Sample rate in Hz
Returns: - b (ndarray) – “b” (feedforward) coefficients of the filter
- a (ndarray) – “a” (feedback) coefficients of the filter
audio_dspy.nonlinearities module¶
-
audio_dspy.nonlinearities.
hard_clipper
(x)¶ Implementation of a hard clipper
Parameters: x ({float, ndarray}) – input to the hard clipper Returns: y – output of the hard clipper Return type: {float, ndarray}
-
audio_dspy.nonlinearities.
soft_clipper
(x, deg=3)¶ Implementation of a cubic soft clipper
Parameters: - x ({float, ndarray}) – input to the soft clipper
- deg (int, optional) – polynomial degree of the soft clipper
Returns: y – output of the soft clipper
Return type: {float, ndarray}
audio_dspy.plotting module¶
-
audio_dspy.plotting.
plot_dynamic_curve
(function, freq=100, fs=44100, gain=10, num=1000)¶ Plots the dynamic curve of a nonlinear function at a specific frequency
Parameters: - function (lambda (float) : float) – function to plot the dynamic curve for
- freq (float, optional) – frequency [Hz] to plot the dynamic curve for, defaults to 100 Hz
- fs (float, optional) – sample rate [Hz] to use for the simulation, defaults to 44.1 kHz
- gain (float, optional) – range of gains on which to plot the dynamic curve [-gain, gain]
- num (int, optional) – number of points to plot
-
audio_dspy.plotting.
plot_freqz_angle
(w, H, log=True)¶ Plots the phase output of the scipy.signal.freqz function
Parameters: - w (ndarray) – w output of freqz
- H (ndarray) – H output of freqz
- log (bool, optional) – Should plot log scale
-
audio_dspy.plotting.
plot_freqz_mag
(w, H, norm=False)¶ Plots the magnitude output of the scipy.signal.freqz function
Parameters: - w (ndarray) – w output of freqz
- H (ndarray) – H output of freqz
- norm (bool, optional) – Should normalize the magnitude response
-
audio_dspy.plotting.
plot_harmonic_response
(function, freq=100, fs=44100, gain=0.1, num=10000)¶ Plots the harmonic response of a nonlinear function at a specific frequency
Parameters: - function (lambda (float) : float) – function to plot the harmonic response for
- freq (float, optional) – frequency [Hz] to plot the harmonic response for, defaults to 100 Hz
- fs (float, optional) – sample rate [Hz] to use for the simulation, defaults to 44.1 kHz
- gain (float, optional) – gain to use for the input signal, defaults to 0.1
- num (int, optional) – number of points to plot
-
audio_dspy.plotting.
plot_magnitude_response
(b, a, worN=512, fs=6.283185307179586, norm=False)¶ Plots the magnitude response of a digital filter in dB, using second order sections
Parameters: - b (ndarray) – numerator (feed-forward) coefficients of the filter
- a (ndarray) – denominator (feed-backward) coefficients of the filter
- worN ({None, int, array_like}, optional) – If a single integer, then compute at that many frequencies (default is N=512). If an array_like, compute the response at the frequencies given. These are in the same units as fs.
- fs (float, optional) – sample rate of the filter
- norm (bool, optional) – Should normalize the magnitude response
-
audio_dspy.plotting.
plot_magnitude_response_sos
(sos, worN=512, fs=6.283185307179586)¶ Plots the magnitude response of a digital filter in dB
Parameters: - sos (array-like) – Filter to plot as a series of second-order sections
- worN ({None, int, array_like}, optional) – If a single integer, then compute at that many frequencies (default is N=512). If an array_like, compute the response at the frequencies given. These are in the same units as fs.
- fs (float, optional) – sample rate of the filter
- norm (bool, optional) – Should normalize the magnitude response
-
audio_dspy.plotting.
plot_phase_response
(b, a, worN=512, fs=6.283185307179586, log=True)¶ Plots the phase response of a digital filter in radians
Parameters: - b (ndarray) – numerator (feed-forward) coefficients of the filter
- a (ndarray) – denominator (feed-backward) coefficients of the filter
- worN ({None, int, array_like}, optional) – If a single integer, then compute at that many frequencies (default is N=512). If an array_like, compute the response at the frequencies given. These are in the same units as fs.
- fs (float, optional) – sample rate of the filter
- log (bool, optional) – Should plot log scale
-
audio_dspy.plotting.
plot_phase_response_sos
(sos, worN=512, fs=6.283185307179586, log=True)¶ Plots the phase response of a digital filter in radians, using second order sections
Parameters: - sos (array-like) – Filter to plot as a series of second-order sections
- worN ({None, int, array_like}, optional) – If a single integer, then compute at that many frequencies (default is N=512). If an array_like, compute the response at the frequencies given. These are in the same units as fs.
- fs (float, optional) – sample rate of the filter
- log (bool, optional) – Should plot log scale
-
audio_dspy.plotting.
plot_spectrogram
(x, fs, win_size=1024, dbRange=180, title='')¶ Plots a dB spectrogram of the input signal and takes care of most of the formatting to get a standard log frequency scale spectrogram.
Parameters: - x (array-like) – Signal to plot the spectrogram of
- fs (float) – Sample rate of the signal
- win_size (int, optional) – Window size to use (default 1024)
- dbRange (float, optional) – The range of Decibels to include in the spectrogram (default 180)
- title (string, optional) – The title to use for the figure
-
audio_dspy.plotting.
plot_static_curve
(function, gain=10, num=1000)¶ Plots the static curve of a nonlinear function
Parameters: - function (lambda (float) : float) – function to plot the static curve for
- gain (float, optional) – range of gains on which to plot the static curve [-gain, gain]
- num (int, optional) – number of points to plot
-
audio_dspy.plotting.
zplane
(b, a, radius=1.5)¶ Plots the pole-zero response of a digital filter
Parameters: - b (array-like) – feed-forward coefficients
- a (array-like) – feed-back coefficients
- radius (float) – The radius to plot for (default 1.5)
audio_dspy.prony module¶
-
audio_dspy.prony.
allpass_warp
(rho, h)¶ Performs allpass warping on a transfer function
Parameters: - rho (float) – Amount of warping to perform. On the range (-1, 1). Positive warping “expands” the spectrum, negative warping “shrinks”
- h (ndarray) – The transfer function to warp
Returns: h_warped – The warped transfer function
Return type: ndarray
-
audio_dspy.prony.
allpass_warp_roots
(rho, b)¶ Performs allpass warping on a filter coefficients
Parameters: - rho (float) – Amount of warping to perform. On the range (-1, 1). Positive warping “expands” the spectrum, negative warping “shrinks”
- b (ndarray) – The filter coefficients
Returns: b_warped – The warped filter coefficients
Return type: ndarray
-
audio_dspy.prony.
prony
(x, nb, na)¶ Uses Prony’s method to generate IIR filter coefficients that optimally match a given transfer function
Parameters: - x (ndarray) – Numpy array containing the transfer function
- nb (int) – Number of feedforward coefficients in the resulting filter
- na (int) – Number of feedback coefficients in the resulting filter
Returns: - b (ndarray) – Feedforward coefficients
- a (ndarray) – Feedback coefficients
-
audio_dspy.prony.
prony_warped
(x, nb, na, rho)¶ Uses Prony’s method with frequency warping to generate IIR filter coefficients that optimally match a given transfer function
Parameters: - x (ndarray) – Numpy array containing the transfer function
- nb (int) – Number of feedforward coefficients in the resulting filter
- na (int) – Number of feedback coefficients in the resulting filter
- rho (float) – Amount of warping to perform. On the range (-1, 1). Positive warping “expands” the spectrum, negative warping “shrinks”
Returns: - b (ndarray) – Feedforward coefficients
- a (ndarray) – Feedback coefficients
audio_dspy.sweeps module¶
-
audio_dspy.sweeps.
sweep2ir
(dry_sweep, wet_sweep)¶ Converts a pair of input/output sine sweeps into an impulse response
Parameters: - dry_sweep (ndarray) – The dry sine sweep used as input to the system
- wet_sweep (ndarray) – The wet sine sweep, output of the system
Returns: h – The impulse response of the system
Return type: ndarray
-
audio_dspy.sweeps.
sweep_lin
(duration, fs)¶ Generates a linear sine sweep
Parameters: - duration (float) – The length of time [seconds] over which to sweep the signal
- fs (float) – The sample rate [Hz]
Returns: x – A numpy array containing the sine sweep signal
Return type: ndarray
-
audio_dspy.sweeps.
sweep_log
(f0, f1, duration, fs)¶ Generates a logarithmic sine sweep
Parameters: - f0 (float) – The frequency [Hz] at which to begin the sine sweep
- f1 (float) – The frequency [Hz] at which to stop the sine sweep
- duration (float) – The length of time [seconds] over which to sweep the signal
- fs (float) – The sample rate [Hz]
Returns: x – A numpy array containing the sine sweep signal
Return type: ndarray
audio_dspy.transfer_function_tools module¶
-
audio_dspy.transfer_function_tools.
tf2linphase
(h)¶ Converts a transfer function to linear phase
Parameters: h (ndarray) – Numpy array containing the original transfer function Returns: h_min – Numpy array containing the linear phase transfer function Return type: ndarray
-
audio_dspy.transfer_function_tools.
tf2minphase
(h)¶ Converts a transfer function to minimum phase
Parameters: h (ndarray) – Numpy array containing the original transfer function Returns: h_min – Numpy array containing the minimum phase transfer function Return type: ndarray
Module contents¶
-
audio_dspy.
impulse
(N)¶ Create an impulse of length N
Parameters: N (int) – Length of the impulse Returns: h – Generated impulse response Return type: array-like
-
audio_dspy.
normalize
(x)¶ Normalize an array of data (real or complex)
Parameters: x (array-like) – Data to be normalized Returns: y – Normalized data Return type: array-like