4efda9ed5a
Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com> |
||
---|---|---|
.. | ||
figure_1.png | ||
figure_2.png | ||
figure_3.png | ||
README.md |
scipy.signal -- Butterworth low, high and band-pass
Goal
Sometimes we need to remove of frequency range from a time series. For this we can use a Butterworth filter scipy.signal.butter and the scipy.signal.filtfilt command.
Questions to David Rotermund
scipy.signal.filtfilt | Apply a digital filter forward and backward to a signal. |
scipy.signal.butter | Butterworth digital and analog filter design. |
Example data
import numpy as np
import matplotlib.pyplot as plt
samples_per_second: int = 1000
dt: float = 1.0 / samples_per_second
# 10 secs
t: np.ndarray = np.arange(0, int(10 * samples_per_second)) * dt
f_low = 1 # Hz
f_mid = 10 # Hz
f_high = 100 # Hz
sin_low = np.sin(2 * np.pi * t * f_low)
sin_mid = np.sin(2 * np.pi * t * f_mid)
sin_high = np.sin(2 * np.pi * t * f_high)
plt.figure(1)
plt.plot(t, sin_low)
plt.plot(t, sin_mid + 3)
plt.plot(t, sin_high + 6)
plt.xlabel("Time [s]")
plt.ylabel("Waveform shifted")
plt.title("unfiltered data")
plt.show()