amplitude_warp
Amplitude Warp Layer
Classes:
-
AmplitudeWarp
–Amplitude warping layer
Classes
AmplitudeWarp
AmplitudeWarp(sample_rate: float = 1, frequency: float | tuple[float, float] = 100, amplitude: float | tuple[float, float] = 0.1, **kwargs)
Apply amplitude warping to the 1D input. Time points are first generated at given frequency resolution with amplitude picked from uniform distribution. These points are then interpolated to match the input duration and multiplied to the input.
Parameters:
-
sample_rate
(float
, default:1
) –Sample rate of the input.
-
frequency
(float | tuple[float, float]
, default:100
) –Frequency of the warping in Hz. If tuple, frequency is randomly picked between the values.
-
amplitude
(float | tuple[float, float]
, default:0.1
) –Amplitude of the warping. If tuple, amplitude is randomly picked between the values.
Example:
sample_rate = 100 # Hz
duration = 3*sample_rate # 3 seconds
sig_freq = 10 # Hz
sig_amp = 1 # Signal amplitude
noise_freq = (1, 2) # Noise frequency range
amplitude = (0.5, 2) # Noise amplitude range
x = sig_amp*np.sin(2*np.pi*sig_freq*np.arange(duration)/sample_rate).reshape(-1, 1).astype(np.float32)
x = keras.ops.convert_to_tensor(x)
lyr = nse.layers.preprocessing.AmplitudeWarp(sample_rate=sample_rate, frequency=noise_freq, amplitude=amplitude)
y = lyr(x)
plt.plot(x.numpy())
plt.plot(y.numpy())
plt.show()
Source code in neuralspot_edge/layers/preprocessing/amplitude_warp.py
Functions
get_random_transformations
Generate noise distortion tensor
Parameters:
Returns:
-
dict
(dict
) –Dictionary containing the noise tensor.
Source code in neuralspot_edge/layers/preprocessing/amplitude_warp.py
augment_samples
Augment all samples in the batch as it's faster.
Source code in neuralspot_edge/layers/preprocessing/amplitude_warp.py
get_config
Serialize the layer configuration to a JSON-compatible dictionary.