# 【Signal Processing】Butter Filter Exlpained

# 1. What is butter filter?

The Butterworth filter is a type of signal processing filter that is designed to have as flat a frequency response as possible in the passband. It works as a bandpass(or high pass, low pass) filter, and also known as a maximally flat magnitude filter.

The filter is named after the British engineer Stephen Butterworth, who first described this type of filter in his 1930 paper titled "On the Theory of Filter Amplifiers".

# 2. Feature

### 2.1 Maximally Flat Magnitude

The primary feature of the Butterworth filter is its maximally flat magnitude response in the passband. This means that the filter does not introduce any ripples in the amplitude of the frequencies it passes (within the passband), unlike other types of filters like Chebyshev or elliptical filters. This feature is crucial for applications where maintaining the integrity and quality of the original signal is important.

ripple:

In a passband of a filter, ripple would manifest as periodic variations in the amplitude of the signal within the passband frequency range.

### 2.2 Versatility

Butterworth filters can be designed for various orders. Higher order Butterworth filters provide sharper rolloff rates, meaning they can more effectively distinguish between the desired frequencies and those to be attenuated. This makes them adaptable to a wide range of applications, from audio processing to data communications.

And also, unlike some other filter types that have a sharp cutoff, the butter filter can have a gentle roll-off slope by adjusting different orders (or slopes), gradually attenuating frequencies above the cutoff point. This results in a smoother and more natural-sounding filter.

### 2.3 Good Phase Characteristics

Butterworth filters generally have good phase characteristics, with minimal phase distortion near the passband. This is important in applications where the phase relationship within a signal must be preserved, such as in audio and telecommunications.

# 3. Example

Here is a example code of butter filter by scipy.

・Butter Filter

```
import numpy as np
from scipy.signal import butter, filtfilt
import matplotlib.pyplot as plt
# Sample rate and time vector
sample_rate = 1000
t = np.linspace(0, 1, sample_rate, False)
# Generate a signal with a mix of frequencies
signal = np.sin(2 * np.pi * 3 * t) + np.sin(2 * np.pi * 15 * t) + np.sin(2 * np.pi * 150 * t)
# Butterworth filter parameters
order = 4
cutoff_freq = 20 # Cutoff frequency in Hz
# Low-pass filter
nyquist_freq = 0.5 * sample_rate
norm_cutoff = cutoff_freq / nyquist_freq
b, a = butter(order, norm_cutoff, btype='low', analog=False)
filtered_signal = filtfilt(b, a, signal)
# High-pass filter
norm_cutoff = cutoff_freq / nyquist_freq
b, a = butter(order, norm_cutoff, btype='high', analog=False)
filtered_signal_high = filtfilt(b, a, signal)
# Band-pass filter
low_cutoff = 10
high_cutoff = 30
norm_low = low_cutoff / nyquist_freq
norm_high = high_cutoff / nyquist_freq
b, a = butter(order, [norm_low, norm_high], btype='band', analog=False)
filtered_signal_band = filtfilt(b, a, signal)
# Plot the signals
plt.figure(figsize=(12, 6))
plt.subplot(2, 2, 1)
plt.plot(t, signal)
plt.title('Original Signal')
plt.subplot(2, 2, 2)
plt.plot(t, filtered_signal)
plt.title('Low-pass Filtered Signal')
plt.subplot(2, 2, 3)
plt.plot(t, filtered_signal_high)
plt.title('High-pass Filtered Signal')
plt.subplot(2, 2, 4)
plt.plot(t, filtered_signal_band)
plt.title('Band-pass Filtered Signal')
plt.tight_layout()
plt.show()
```

・Output

Scipy Butter filter can work as either of lowpass, highpass, bandpass filter.

# 3. Summary

In conclusion, the Butter filter provides a very useful pass filter in the field of signal processing. Due to these properties, it is used in a great many situations.

## Discussion