mindspore.dataset.audio.ComputeDeltas

class mindspore.dataset.audio.ComputeDeltas(win_length=5, pad_mode=BorderType.EDGE)[source]

Compute delta coefficients, also known as differential coefficients, of a spectrogram.

Delta coefficients help to understand the dynamics of the power spectrum. It can be computed using the following formula.

\[d_{t}=\frac{{\textstyle\sum_{n=1}^{N}}n(c_{t+n}-c_{t-n})}{2{\textstyle\sum_{n=1}^{N}}n^{2}}\]

where \(d_{t}\) is the deltas at time \(t\) , \(c_{t}\) is the spectrogram coefficients at time \(t\) , \(N\) is \((\text{win_length} - 1) // 2\) .

Parameters
  • win_length (int, optional) – The window length used for computing delta, must be no less than 3. Default: 5.

  • pad_mode (BorderType, optional) –

    Mode parameter passed to padding, can be BorderType.CONSTANT, BorderType.EDGE, BorderType.REFLECT or BorderType.SYMMETRIC. Default: BorderType.EDGE.

    • BorderType.CONSTANT, pad with a constant value.

    • BorderType.EDGE, pad with the last value on the edge.

    • BorderType.REFLECT, reflect the value on the edge while omitting the last one. For example, pad [1, 2, 3, 4] with 2 elements on both sides will result in [3, 2, 1, 2, 3, 4, 3, 2].

    • BorderType.SYMMETRIC, reflect the value on the edge while repeating the last one. For example, pad [1, 2, 3, 4] with 2 elements on both sides will result in [2, 1, 1, 2, 3, 4, 4, 3].

Raises
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, 400 // 2 + 1, 30])  # 5 samples
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data=waveform, column_names=["audio"])
>>> transforms = [audio.ComputeDeltas(win_length=7, pad_mode=audio.BorderType.EDGE)]
>>> 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
(201, 30) float64
>>>
>>> # Use the transform in eager mode
>>> waveform = np.random.random([400 // 2 + 1, 30])  # 1 sample
>>> output = audio.ComputeDeltas(win_length=7, pad_mode=audio.BorderType.EDGE)(waveform)
>>> print(output.shape, output.dtype)
(201, 30) float64
Tutorial Examples: