zcross#

class diffsptk.ZeroCrossingAnalysis(frame_length: int, norm: bool = False, softness: float = 0.001)[source]#

See this page for details.

Parameters:
frame_lengthint >= 1

The frame length in samples, \(L\).

normbool

If True, divide the zero-crossing rate by the frame length.

softnessfloat > 0

A smoothing parameter. The smaller value makes the output closer to the true zero-crossing rate, but the gradient vanishes.

forward(x: Tensor) Tensor[source]#

Compute zero-crossing rate.

Parameters:
xTensor [shape=(…, T)]

The input waveform.

Returns:
outTensor [shape=(…, T/L)]

The zero-crossing rate.

Examples

>>> import diffsptk
>>> import torch
>>> zcross = diffsptk.ZeroCrossingAnalysis(3)
>>> x = torch.tensor([-0.2, 0.3, -0.5, -0.7, 0.4, 0.2])
>>> z = zcross(x)
>>> z
tensor([2., 1.])
diffsptk.functional.zcross(x: Tensor, frame_length: int, norm: bool = False, softness: float = 0.001) Tensor[source]#

Compute zero-crossing rate.

Parameters:
xTensor [shape=(…, T)]

The input waveform.

frame_lengthint >= 1

The frame length in samples, \(L\).

normbool

If True, divide the zero-crossing rate by the frame length.

softnessfloat > 0

A smoothing parameter. The smaller value makes the output closer to the true zero-crossing rate, but the gradient vanishes.

Returns:
outTensor [shape=(…, T/L)]

The zero-crossing rate.