What is a Biquad Filter: Definition and Usage Explained
biquad filter is a type of digital filter that uses two poles and two zeros to shape signals. It is commonly used for audio and signal processing because it can implement many filter types like low-pass, high-pass, and band-pass with simple equations.How It Works
A biquad filter works like a smart signal shaper that changes the sound or data by emphasizing or reducing certain frequencies. Imagine it as a water faucet with two knobs: one controls how much water flows out (gain), and the other controls how the water pressure changes (frequency response). These two knobs correspond to the filter's poles and zeros, which define how the filter reacts to different frequencies.
In simple terms, the biquad filter uses a small set of numbers (coefficients) to calculate each output point based on current and past inputs and outputs. This makes it efficient and flexible, allowing it to create many common filter effects by just changing these numbers.
Example
import numpy as np import matplotlib.pyplot as plt from scipy.signal import lfilter # Sample rate and desired cutoff frequency (Hz) sample_rate = 48000 cutoff_freq = 1000 # Calculate normalized frequency omega = 2 * np.pi * cutoff_freq / sample_rate # Biquad low-pass filter coefficients (Butterworth) b = [omega**2, 2*omega**2, omega**2] a = [1 + np.sqrt(2)*omega + omega**2, -2 + 2*omega**2, 1 - np.sqrt(2)*omega + omega**2] # Normalize coefficients a = np.array(a) / a[0] b = np.array(b) / a[0] # Create a noisy signal T = 0.01 t = np.linspace(0, T, int(sample_rate*T), endpoint=False) signal = np.sin(2*np.pi*300*t) + 0.5*np.sin(2*np.pi*3000*t) # Apply the biquad filter filtered_signal = lfilter(b, a, signal) # Plot original and filtered signals plt.plot(t, signal, label='Original Signal') plt.plot(t, filtered_signal, label='Filtered Signal') plt.legend() plt.xlabel('Time [s]') plt.ylabel('Amplitude') plt.title('Biquad Low-Pass Filter Example') plt.show()
When to Use
Use a biquad filter when you need a simple, efficient way to shape or clean signals in real time. They are perfect for audio equalizers, noise reduction, and sensor data smoothing because they require few calculations and can be tuned easily.
For example, in music apps, biquad filters help adjust bass or treble. In electronics, they clean sensor signals to remove unwanted noise. Their flexibility makes them a go-to choice for many digital signal processing tasks.
Key Points
- A biquad filter uses two poles and two zeros to control frequency response.
- It can implement many filter types like low-pass, high-pass, band-pass, and notch.
- It is efficient and suitable for real-time digital signal processing.
- Filter behavior is controlled by a small set of coefficients.