Signal Smoothing with scipy (original) (raw)

Last Updated : 23 Jul, 2025

Signal smoothing is the process of reducing this noise to reveal the true behaviour of the signal. It acts like a lens that clarifies the picture helping highlight patterns, peaks or trends that might otherwise go unnoticed. Python’s SciPy library along with NumPy and Matplotlib offers powerful tools to apply various smoothing techniques efficiently. From simple moving averages to more advanced filters like Gaussian and Savitzky Golay which provide flexible options to clean up 1D signals with minimal effort.

Signal Smoothing techniques

1. Savitzky Golay Filter

from scipy.signal import savgol_filter

smoothed = savgol_filter(y, window_length=11, polyorder=3) plt.plot(x, y, label='Noisy Signal') plt.plot(x, smoothed, label='Savitzky-Golay', color='green') plt.legend() plt.show()

`

**Output:

output

Output Savitzky Golay Filter

2. Gaussian Filter

from scipy.ndimage import gaussian_filter1d

smoothed = gaussian_filter1d(y, sigma=2) plt.plot(x, y, label='Noisy Signal') plt.plot(x, smoothed, label='Gaussian Filter', color='orange') plt.legend() plt.show()

`

**Output:

output

Output of Gaussian Filter

3. Butterworth Low pass Filter

from scipy.signal import butter, filtfilt

def butter_lowpass_filter(data, cutoff, fs, order=4): nyq = 0.5 * fs normal_cutoff = cutoff / nyq b, a = butter(order, normal_cutoff, btype='low', analog=False) return filtfilt(b, a, data)

fs = 100
cutoff = 2.0

smoothed = butter_lowpass_filter(y, cutoff=cutoff, fs=fs)

plt.plot(x, y, label='Noisy Signal') plt.plot(x, smoothed, label='Butterworth Filter', color='purple') plt.legend() plt.show()

`

**Output:

output

Output of Butterworth Low pass Filter

Need of signal smoothing

  1. **Reduces Noise and Unwanted Fluctuations: Real world signals often contain random variations or noise due to sensor inaccuracies, environmental interference or measurement errors. Smoothing helps suppress these fluctuations making the signal cleaner.
  2. **Reveals Underlying Trends and Patterns: Raw signals can be erratic hiding the true behavior or trend. Smoothing highlights the fundamental structure helping to understand the core dynamics of the data.
  3. **Improves Accuracy of Signal Analysis: Many analysis techniques like peak detection, classification or forecasting perform better on smooth data since noise can cause false positives or misleading results.
  4. **Enhances Visualization Clarity: Smoothed signals are easier to interpret visually as noise and jagged edges are minimized allowing for clearer presentation and communication of findings.