pytutorial/scipy.signal_butterworth
David Rotermund 4efda9ed5a
Add files via upload
Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
2023-11-16 18:35:01 +01:00
..
figure_1.png Add files via upload 2023-11-16 18:31:30 +01:00
figure_2.png Add files via upload 2023-11-16 18:33:37 +01:00
figure_3.png Add files via upload 2023-11-16 18:35:01 +01:00
README.md Update README.md 2023-11-16 18:30:46 +01:00

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()