madmom.audio.comb_filters¶
This module contains comb-filter and comb-filterbank functionality.
-
class
madmom.audio.comb_filters.
CombFilterbankProcessor
¶ CombFilterbankProcessor class.
Parameters: filter_function : filter function or str
Filter function to use {feed_forward_comb_filter, feed_backward_comb_filter} or a string literal {‘forward’, ‘backward’}.
tau : list or numpy array, shape (N,)
Delay length(s) [frames].
alpha : list or numpy array, shape (N,)
Corresponding scaling factor(s).
Notes
tau and alpha must have the same length.
Examples
Create a processor and then filter the given signal with it. The direction of the comb filter function can be given as a literal:
>>> x = np.array([0, 0, 1, 0, 0, 1, 0, 0, 1]) >>> proc = CombFilterbankProcessor('forward', [2, 3], [0.5, 0.5]) >>> proc(x) array([[ 0. , 0. ], [ 0. , 0. ], [ 1. , 1. ], [ 0. , 0. ], [ 0.5, 0. ], [ 1. , 1.5], [ 0. , 0. ], [ 0.5, 0. ], [ 1. , 1.5]])
>>> proc = CombFilterbankProcessor('backward', [2, 3], [0.5, 0.5]) >>> proc(x) array([[ 0. , 0. ], [ 0. , 0. ], [ 1. , 1. ], [ 0. , 0. ], [ 0.5 , 0. ], [ 1. , 1.5 ], [ 0.25 , 0. ], [ 0.5 , 0. ], [ 1.125, 1.75 ]])
-
process
(self, data)¶ Process the given data with the comb filter.
Parameters: data : numpy array
Data to be filtered/processed.
Returns: comb_filtered_data : numpy array
Comb filtered data with the different taus aligned along the (new) last dimension.
-
-
madmom.audio.comb_filters.
comb_filter
(signal, filter_function, tau, alpha)¶ Filter the signal with a bank of either feed forward or backward comb filters.
Parameters: signal : numpy array
Signal.
filter_function : {feed_forward_comb_filter, feed_backward_comb_filter}
Filter function to use (feed forward or backward).
tau : list or numpy array, shape (N,)
Delay length(s) [frames].
alpha : list or numpy array, shape (N,)
Corresponding scaling factor(s).
Returns: comb_filtered_signal : numpy array
Comb filtered signal with the different taus aligned along the (new) last dimension.
Notes
tau and alpha must be of same length.
Examples
Filter the given signal with a bank of resonating comb filters.
>>> x = np.array([0, 0, 1, 0, 0, 1, 0, 0, 1]) >>> comb_filter(x, feed_forward_comb_filter, [2, 3], [0.5, 0.5]) array([[ 0. , 0. ], [ 0. , 0. ], [ 1. , 1. ], [ 0. , 0. ], [ 0.5, 0. ], [ 1. , 1.5], [ 0. , 0. ], [ 0.5, 0. ], [ 1. , 1.5]])
Same for a backward filter:
>>> comb_filter(x, feed_backward_comb_filter, [2, 3], [0.5, 0.5]) array([[ 0. , 0. ], [ 0. , 0. ], [ 1. , 1. ], [ 0. , 0. ], [ 0.5 , 0. ], [ 1. , 1.5 ], [ 0.25 , 0. ], [ 0.5 , 0. ], [ 1.125, 1.75 ]])
-
madmom.audio.comb_filters.
feed_backward_comb_filter
(signal, tau, alpha)¶ Filter the signal with a feed backward comb filter.
Parameters: signal : numpy array
Signal.
tau : int
Delay length.
alpha : float
Scaling factor.
Returns: comb_filtered_signal : numpy array
Comb filtered signal, float dtype.
Notes
y[n] = x[n] + α * y[n - τ] is used as a filter function.
Examples
Comb filter the given signal:
>>> x = np.array([0, 0, 1, 0, 0, 1, 0, 0, 1]) >>> feed_backward_comb_filter(x, tau=3, alpha=0.5) array([ 0. , 0. , 1. , 0. , 0. , 1.5 , 0. , 0. , 1.75])
-
madmom.audio.comb_filters.
feed_backward_comb_filter_1d
(signal, tau, alpha)¶ feed_backward_comb_filter_1d is deprecated as of version 0.14 and will be removed in version 0.15. Use feed_backward_comb_filter instead.
-
madmom.audio.comb_filters.
feed_backward_comb_filter_2d
(signal, tau, alpha)¶ feed_backward_comb_filter_2d is deprecated as of version 0.14 and will be removed in version 0.15. Use feed_backward_comb_filter instead.
-
madmom.audio.comb_filters.
feed_forward_comb_filter
(signal, tau, alpha)¶ Filter the signal with a feed forward comb filter.
Parameters: signal : numpy array
Signal.
tau : int
Delay length.
alpha : float
Scaling factor.
Returns: comb_filtered_signal : numpy array
Comb filtered signal, float dtype
Notes
y[n] = x[n] + α * x[n - τ] is used as a filter function.
Examples
Comb filter the given signal:
>>> x = np.array([0, 0, 1, 0, 0, 1, 0, 0, 1]) >>> feed_forward_comb_filter(x, tau=3, alpha=0.5) array([ 0. , 0. , 1. , 0. , 0. , 1.5, 0. , 0. , 1.5])