mightypy.signal_processing package#
Module contents#
mightypy.signal_processing#
- class PSDDenoiser(threshold: int | float | str | None = 'auto-mean')[source]#
Bases:
object
PSD (Power Spectral Density) Based Denoiser
This method takes the FFT transform of the signal to calculate PSD based on the PSD results and cutoff threshold the signal is filtered and a FFT inverse is applied to regenerate denoised signal.
- Parameters:
threshold (Optional[Union[int, float, str]], optional) – threshold to create cutoff mask, but any threshold can be applied, if it is precalculated by any method chosen by the process, by default auto-mean { auto-mean, auto-max }
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from mightypy.preprocessing import PSDDenoiser >>> rng = np.random.default_rng() >>> fs = 10e3 >>> N = 100 >>> amp = 2 * np.sqrt(2) >>> freq = 1234.0 >>> noise_power = 0.001 * fs / 2 >>> time = np.arange(N) / fs >>> X = amp * np.sin(2 * np.pi * freq * time) >>> X += rng.normal(scale=np.sqrt(noise_power), size=time.shape)
>>> denoiser = PSDDenoiser() >>> cleaned_signal = denoiser.transform(X) >>> plt.plot(X, label="noisy") >>> plt.plot(cleaned_signal, label="cleaned") >>> plt.title(f"Threshold : {denoiser.threshold}") >>> plt.legend(loc="best") >>> plt.show()
>>> denoiser = PSDDenoiser(10) >>> cleaned_signal = denoiser.transform(X) >>> plt.plot(X, label='noisy') >>> plt.plot(cleaned_signal, label='cleaned') >>> plt.title(f"Threshold : {denoiser.threshold}") >>> plt.legend(loc='best') >>> plt.show()
- psd(f_hat: ndarray, tau: int) ndarray [source]#
Power Spectral Density
- Parameters:
f_hat (np.ndarray) – Signal in Frequency Domain
tau (int) – Interval
- Returns:
Power spectrum
- Return type:
np.ndarray