fir_filter
FIR Filter Layer API
This module provides classes to build FIR filter layers.
Classes:
-
FirFilter
–FIR filter layer
Classes
FirFilter
FirFilter(b: npt.NDArray[np.float32], a: npt.NDArray[np.float32] | None = None, forward_backward: bool = False, **kwargs)
Apply FIR filter to the input.
Parameters:
-
b
(ndarray
) –Numerator coefficients.
-
a
(ndarray | None
, default:None
) –Denominator coefficients. Defaults to None.
-
forward_backward
(bool
, default:False
) –Apply filter forward and backward. Defaults to False.
Example:
# Create sine wave at 10 Hz with 1000 Hz sampling rate
t = np.linspace(0, 1, 1000, endpoint=False)
x = np.sin(2 * np.pi * 10 * t)
# Add noise at 100 Hz and 2 Hz
x_noise = x + 0.5 * np.sin(2 * np.pi * 100 * t) + 0.5 * np.sin(2 * np.pi * 2 * t)
x_noise = x_noise.reshape(-1, 1).astype(np.float32)
x_noise = keras.ops.convert_to_tensor(x_noise)
# Create bandpass FIR taps
b = scipy.signal.firwin(101, [5, 15], fs=1000, pass_zero=False)
lyr = nse.layers.preprocessing.FirFilter(b, forward_backward=True)
y = lyr(x_noise).numpy().squeeze()
x_noise = x_noise.numpy().squeeze()
plt.plot(x, label="Original")
plt.plot(x_noise, label="Noisy")
plt.plot(y, label="Filtered")
plt.legend()
plt.show()
Source code in neuralspot_edge/layers/preprocessing/fir_filter.py
Functions
augment_samples
Augment a batch of samples during training.
Source code in neuralspot_edge/layers/preprocessing/fir_filter.py
get_config
Serialize the layer configuration.