The purpose of this blog is to design an own filter with a specific cutoff frequency by choosing one of the filter types among Butterworth, Bessel, Cheby1, and Cheby2, Elliptical filter, and its order with ideal OPAMP. Also, the implementation of the filter is given by Direct Form 1(DF1), DF2, Parallel, and other implementations. The filter characteristics are roughly divided into the Butterworth, Bessel, Cheby1, and Cheby2, Elliptical filter, and each filter has some unique characteristics.
- Butterworth – The Butterworth filter has no ripple in both the passband and stopband and the frequency response is as flat as possible in the passband. (Maximally flat magnitude filter)
- Bessel – The filter has amplitude characteristics similar to Butterworth characteristics but is approximated to optimize to obtain better transient response characteristics in the passband. Therefore, the amount of overshoot is small, and the rise speed is the fastest as compared with the filter having the other characteristics of the same order.
- Cheby1 (Chebyshev) – The Cheby1 filter is a low pass filter with equiripple in the passband. A steep cutoff characteristic can be obtained by allowing ripples.
- Cheby2 (Inverse Chebyshev) – The Cheby1 filter is a low pass filter with equiripple in the passband. A steep cutoff characteristic can be obtained by allowing ripples.
- Elliptical – The Cheby1 filter and the Cheby2 filter have a steeper cutoff characteristic than the Butterworth filter by providing equiripples in either the passband or the stopband. On the other hand, the elliptical filter is created based on obtaining steeper cutoff characteristics by generating equiripples in both the passband and stopband.
Implementation of Python
Out of these 5 filter types, I chose 7th order Butterworth low pass filter targeting 10kHz cutoff frequency for this project because the Butterworth filter is easier to implement with no ripples in both the passband and the stopband. The 7th order Butterworth low pass filter has seven filter coefficients in the denominator and a filter coefficient in the numerator. Then, the Python code below can generate these coefficients and its Bode Plot from the obtained transfer function.
from scipy import signal
import matplotlib.pyplot as plt
import numpy as np
f1 = 24
f2 = 10000
order = 7
w1 = 2*np.pi*f1
w2 = 2*np.pi*f2
B, A = signal.iirfilter(order, w2, btype='low', analog=True, ftype='butter', output='ba')
w, h = signal.freqs(B,A) # w: Angunlar frequency, h: Frequency response
# Plot the magnitude
fig, ax1 = plt.subplots()
mag = 20 * np.log10(abs(h))
ax1.plot(w/2/np.pi, mag, color='red', linewidth=2)
ax1.set_title('Butterworth low pass filter frequency response', fontsize=20)
ax1.set_xlabel('Frequency [Hz]', fontsize=20)
ax1.set_ylabel('Amplitude [dB]', fontsize=20)
ax1.axvline(f2, color='blue', linewidth=2) # cutoff frequency
#Plot the phase
ax2 = ax1.twinx() # A twin axes sharing the x axis
rad = np.unwrap(np.angle(h))
degree = np.rad2deg(rad)
ax2.plot(w/2/np.pi, degree, color='green', linewidth=2)
ax2.set_ylabel('Phase [rad]', fontsize=20)
print "a=", A
print "b=", B
a= [1.00000000e+00+0.00000000e+00j 2.82363785e+05-4.18544220e-11j
When executing the Python code, the ideal Bode Plot will be observed like the image below. As you can see, this simulation of 7th order Butterworth low pass filter in Python has 10kHz cutoff frequency, and the attenuation slope is -140dB/dec.
Implementation using a Behavioral Voltage Source
The following transfer function is generated from the filter coefficients obtained by executing Python.
Then, open the LTSpice and the Bode plot of the 7th order Butterworth low pass filter can be simulated by using an ideal behavioral voltage source based on the coefficients from the transfer function obtained in Python.
When starting to simulate the ideal behavioral voltage source using Laplace Transform function in LTSpice, the Bode plot below was observed.
Implementation using a Direct Form 2
Next, I choose the direct form 2 implementation for the 7th order Butterworth low pass filter out of these implementations. In order to design the 7th order Butterworth lowpass filter by using DF2, there are some resistors that should be determined by each coefficient in the transfer function and the resistance of Rf determined by own. This table represents all values you need for the circuit by DF2.
|Stage||Coefficients||Stage Gain||Gain provided by Summer||Rf (Ω)||Ra (N)||Gain + side Summer|
|2||3.986E+10||6.283E+04||10.0976||1.0E+05||9.903E+03||Gain - side Summer|
Also, this is the signal flow graph for the direct form 2 realization of the 7th order Butterworth low pass filter.
Based on the values determined and the realization, the circuit of the 7th order Butterworth low pass filter by DF2 can be finally designed like this!
When observing the voltage output in LTSpice, the Bode plot below was simulated. The magnitude of the 7th order Butterworth low pass filter is pretty close to the magnitude generated by Python implementation and by the ideal behavioral voltage source.
The cutoff frequency and phase change of the 7th order Butterworth low pass filter using ideal OPAMPs generated by Python and by the simulation in LTSpice was matched at 10kHz and -630°. In addition, the attenuation slope was -140dB/dec. It would be more fun if I have simulated my own filter with different orders and different methods of implementation on LTSpice by comparing the ideal Bode plot simulated by Python. See you for the next project!