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
>>> from mindspore.dataset.audio import BorderType
>>>
>>> waveform = np.random.random([1, 400 // 2 + 1, 30])
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data=waveform, column_names=["audio"])
>>> transforms = [audio.ComputeDeltas(win_length=7, pad_mode=BorderType.EDGE)]
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms, input_columns=["audio"])