mindspore.dataset.audio.BandpassBiquad

View Source On Gitee
class mindspore.dataset.audio.BandpassBiquad(sample_rate, central_freq, Q=0.707, const_skirt_gain=False)[source]

Design two-pole Butterworth band-pass filter for audio waveform.

The frequency response of the Butterworth filter is maximally flat (i.e. has no ripples) in the passband and rolls off towards zero in the stopband.

The system function of Butterworth band-pass filter is:

\[H(s) = \begin{cases} \frac{s}{s^2 + \frac{s}{Q} + 1}, &\text{if const_skirt_gain=True}; \cr \frac{\frac{s}{Q}}{s^2 + \frac{s}{Q} + 1}, &\text{if const_skirt_gain=False}. \end{cases}\]

Similar to SoX implementation.

Note

The shape of the audio waveform to be processed needs to be <…, time>.

Parameters
  • sample_rate (int) – Sampling rate (in Hz), which can't be zero.

  • central_freq (float) – Central frequency (in Hz).

  • Q (float, optional) – Quality factor , in range of (0, 1]. Default: 0.707.

  • const_skirt_gain (bool, optional) – If True, uses a constant skirt gain (peak gain = Q); If False, uses a constant 0dB peak gain. Default: False.

Raises
  • TypeError – If sample_rate is not of type int.

  • ValueError – If sample_rate is 0.

  • TypeError – If central_freq is not of type float.

  • TypeError – If Q is not of type float.

  • ValueError – If Q is not in range of (0, 1].

  • TypeError – If const_skirt_gain is not of type bool.

  • RuntimeError – If input tensor is not in shape of <…, time>.

Supported Platforms:

CPU

Examples

>>> import numpy as np
>>> import mindspore.dataset as ds
>>> import mindspore.dataset.audio as audio
>>>
>>> # Use the transform in dataset pipeline mode
>>> waveform = np.random.random([5, 16])  # 5 samples
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data=waveform, column_names=["audio"])
>>> transforms = [audio.BandpassBiquad(44100, 200.0)]
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms, input_columns=["audio"])
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
...     print(item["audio"].shape, item["audio"].dtype)
...     break
(16,) float64
>>>
>>> # Use the transform in eager mode
>>> waveform = np.random.random([16])  # 1 sample
>>> output = audio.BandpassBiquad(44100, 200.0)(waveform)
>>> print(output.shape, output.dtype)
(16,) float64
Tutorial Examples: