nnAudio2.features.cfp.CFP

class nnAudio2.features.cfp.CFP(fr=2, fs=16000, hop_length=320, window_size=2049, fc=80, tc=0.001, g=[0.24, 0.6, 1], NumPerOct=48)

Bases: Module

This is the modified version of Combined_Frequency_Periodicity(). This version different from the original version by returnning only Z and the number of timesteps fits with other classes.

Parameters:
  • fr (int) – Frequency resolution. The higher the number, the lower the resolution is. Maximum frequency resolution occurs when fr=1. The default value is 2

  • fs (int) – Sample rate of the input audio clips. The default value is 16000

  • hop_length (int) – The hop (or stride) size. The default value is 320.

  • window_size (str) – It is same as n_fft in other Spectrogram classes. The default value is 2049

  • fc (int) – Starting frequency. For example, fc=80 means that Z starts at 80Hz. The default value is 80.

  • tc (int) – Inverse of ending frequency. For example tc=1/8000 means that Z ends at 8000Hz. The default value is 1/8000.

  • g (list) – Coefficients for non-linear activation function. len(g) should be the number of activation layers. Each element in g is the activation coefficient, for example [0.24, 0.6, 1].

  • device (str) – Choose which device to initialize this layer. Default value is ‘cpu’

Returns:

  • Z (torch.tensor) – The Combined Frequency and Period Feature. It is equivalent to tfrLF * tfrLQ

  • tfrL0 (torch.tensor) – STFT output

  • tfrLF (torch.tensor) – Frequency Feature

  • tfrLQ (torch.tensor) – Period Feature

Examples

>>> spec_layer = Spectrogram.Combined_Frequency_Periodicity()
>>> Z, tfrL0, tfrLF, tfrLQ = spec_layer(x)

Methods

__init__

Initialize internal Module state, shared by both nn.Module and ScriptModule.

create_logfreq_matrix

forward

Define the computation performed at every call.

nonlinear_func

forward(x)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.