Skip to content

Delta Max Preprocessor Transform

The Delta Max Preprocessor Transform shifts the input signal by the max of the signal. The is defined as:

\[ x_{shifted_{i}} = x_{i} - \max({x}), \quad \forall i \in \{1, \dots, N\} \]

For shifting signals by a custom \(\delta\), see the Delta Transform Preprocessor. For more on how we compute the max of a signal, check out max function.

Bases: Preprocess

Preprocess the signal by shifting the signal down by the maximum value.

__call__(signal, where=lambda : not np.isnan(x), initial=-np.inf)

Compute the difference between the values in signal and max where where is True.

Parameters:

Name Type Description Default
signal ndarray

The array to compute the delta with.

required
where Callable[[Union[int, float, int_, float_]], Union[bool, bool_]]

A function that takes a value and returns True or False. Default is lambda x: not np.isnan(x) i.e. a measurement is valid if it is not a NaN value.

lambda : not numpy.isnan(x)
initial Union[int, float, int_, float_]

The initial value for the maximum. Default is -np.inf.

-inf

Returns:

Type Description
ndarray

The shifted signal.

Examples

Consider the following example. We generate a sound wave with a frequencey of 500Hz. The sound wave may contain magnitudes that are not safe for the human ear. We can apply the delta max transform to shift the signal such that it falls within a safe range.

Transform Signal

import numpy as np
import autonfeat as aft

# Create a random signal
time = np.linspace(0, 10, 1000)
frequency = 500  # Frequency of the signal in Hz
sound_wave = np.sin(2 * np.pi * frequency * time) + 0.5 * np.sin(2 * np.pi * 2 * frequency * time) + 0.25 * np.sin(2 * np.pi * 3 * frequency * time)

# Create Preprocessor
preprocessor = aft.preprocess.DeltaMaxPreprocessor()

# Shift the sound wave by the peak value to ensure safe listening levels
# if we define a safe listening level as 0.5
safe_level = 0.5
safe_sound = preprocessor(sound_wave) + safe_level

Visualize Transform

import matplotlib.pyplot as plt

# Plot the original signal and the shifted signal
fig, ax = plt.subplots(figsize=(10, 5))
ax.plot(time, sound_wave, label='Original Signal')
ax.plot(time, safe_sound, label='Shifted Signal')
ax.axhline(y=safe_level, color='red', linestyle='--', linewidth=2)
ax.annotate('Safe Listening Level', xy=(0, safe_level), xytext=(0.5, safe_level + 0.1), arrowprops=dict(facecolor='black', shrink=0.05))
ax.set_xlabel('Time (s)')
ax.set_ylabel('Amplitude')
ax.set_title('Sound Wave')
ax.legend()
plt.tight_layout()
plt.show()

This can be seen in the figure below.

DeltaMax

If you enjoy using AutonFeat, please consider starring the repository ⭐️.