SciPy — Signal Processing
Filter design
from scipy.signal import butter, filtfilt
import numpy as np
# Design lowpass filter
b, a = butter(4, 0.1, btype='low')
# Apply filter
signal = np.random.randn(1000)
filtered = filtfilt(b, a, signal)
FIR filter
from scipy.signal import firwin, lfilter
# Design FIR filter
numtaps = 51
cutoff = 0.2
taps = firwin(numtaps, cutoff)
# Apply filter
filtered = lfilter(taps, 1.0, signal)
Frequency response
from scipy.signal import freqz
w, h = freqz(b, a)
Spectrogram
from scipy.signal import spectrogram
import numpy as np
fs = 1000 # Sample frequency
t = np.linspace(0, 1, fs)
signal = np.sin(2 * np.pi * 100 * t)
f, t_spec, Sxx = spectrogram(signal, fs)
Peak finding
from scipy.signal import find_peaks
signal = np.sin(np.linspace(0, 10, 1000))
peaks, _ = find_peaks(signal, height=0.5)
print(f"Found {len(peaks)} peaks")
Convolution
from scipy.signal import convolve
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = convolve(a, b)
print(f"Convolution: {c}")
Applications
- Audio filtering
- Noise removal
- Feature extraction
- Communication systems
Mini Practice
- Design a lowpass filter
- Filter a noisy signal
- Create a spectrogram
- Find peaks in data
Up Next
Continue with Statistics - Statistical functions.
Related Topics
Frequently Asked Questions about Signal Processing
What is Signal Processing in SciPy?
Signal Processing is a fundamental concept in SciPy. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Signal Processing?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Signal Processing.
Why is Signal Processing important in SciPy?
Signal Processing is essential for SciPy development. Understanding this concept will help you write better code and solve real-world problems more effectively.