clarity.enhancer.multiband_compressor.crossover module¶
Class compute crossover filter for one crossover frequency.
- class clarity.enhancer.multiband_compressor.crossover.Crossover(freq_crossover: list | ndarray | int, sample_rate: float = 44100)[source]¶
Bases:
object
A class to compute crossover filter for two or more crossover frequencies. This is based on [1]
References: [1] D’Appolito, J. A. (1984, October). Active realization of multiway all-pass crossover systems. In Audio Engineering Society Convention 76. Audio Engineering Society.
Example: >>> xover_freqs = np.array( … [250, 500, 1000, 1500, 2000, 3000, 4000, 5000, 6000, 8000] …) * np.sqrt(2) >>> xover = Crossover(xover_freqs) >>> signal = np.random.randn(1000) >>> filtered_signal = xover(signal) >>> xover.plot_filter()
- FILTER_ORDER = 4¶
- plot_filter()[source]¶
Method to plot the frequency response of the filter. This can help to validate the Class is generating the expected filters
- xover_component(signal: ndarray, filter_idx: int, len_xover_freqs: int, axis: int = -1) ndarray [source]¶
Apply the crossover filter to the signal.
- Parameters:
signal (np.ndarray) – The input signal.
filter_idx (int) – The index of the filter to apply.
len_xover_freqs (int) – The number of crossover frequencies.
axis (int) – The axis along which to apply the filter. Default is -1.
`More information in scipy.signal.lfilter`
documentation.
- Returns:
The filtered signal.
- Return type:
np.ndarray
- clarity.enhancer.multiband_compressor.crossover.compute_coefficients(xover_freqs: ndarray, sample_rate: float = 44100, order: int = 4) tuple[ndarray, ndarray, ndarray, ndarray] [source]¶
Compute the filter coefficients. These are independent of the signal.
- Parameters:
xover_freqs (ndarray) – The crossover frequencies.
sample_rate (float) – The sample rate of the signal.
order (int) – The order of the filter.
- Returns:
The numerator of the filter. astore (ndarray): The denominator of the filter. bstore_phi (ndarray): The phase correction for the numerator of the
all pass filter.
- astore_phi (ndarray): The phase correction for the denominator of the
all pass filter.
- Return type:
bsotre (ndarray)
- clarity.enhancer.multiband_compressor.crossover.linkwitz_riley(xover_freqs: float, btype: str, order: int = 4) tuple[ndarray, ndarray] [source]¶
Compute the Linkwitz-Riley filter. Makes a filter that is equivalent to passing through butterworth twice to get linkwitz-riley
- Parameters:
xover_freqs – The crossover frequency.
btype – The type of filter.
order – The order of the filter.
- Returns:
The numerator and denominator of the filter.
- Return type:
np.ndarray
- clarity.enhancer.multiband_compressor.crossover.make_all_pass(b1: ndarray, a1: ndarray, b2: ndarray, a2: ndarray) tuple[ndarray, ndarray] [source]¶
Take two filters [b1,a1] and [b2,a2] and calculate the coefficient of a filter that is equivalent to passing the input through each filter in parallel and summing the result
- Parameters:
b1 – Numerator of the first filter
a1 – Denominator of the first filter
b2 – Numerator of the second filter
a2 – Denominator of the second filter
- Returns:
The numerator and denominator of the all pass filter.
- Return type:
np.ndarray