Bird
Raised Fist0
SciPydata~20 mins

IIR filter design (butter, cheby1) in SciPy - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
IIR Filter Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of Butterworth filter coefficients
What is the output of the following code that designs a 3rd order Butterworth lowpass filter with cutoff frequency 0.4 (normalized) and prints the numerator coefficients?
SciPy
from scipy.signal import butter
b, a = butter(3, 0.4, btype='low')
print(b)
A[0.01809893 0.05429679 0.05429679 0.01809893]
B[ 0.09763107 0.29289322 0.29289322 0.09763107]
C[0.00482434 0.01447302 0.01447302 0.00482434]
D[0.25 0.25 0.25 0.25]
Attempts:
2 left
💡 Hint
Recall that butter() returns numerator and denominator coefficients of the filter.
❓ data_output
intermediate
2:00remaining
Number of zeros in Chebyshev Type I filter numerator
After designing a 4th order Chebyshev Type I highpass filter with 1 dB ripple and cutoff frequency 0.3 (normalized), how many zeros does the numerator polynomial have?
SciPy
from scipy.signal import cheby1
b, a = cheby1(4, 1, 0.3, btype='high')
print(len(b) - 1)
A3
B4
C5
D1
Attempts:
2 left
💡 Hint
The numerator polynomial degree equals the filter order for IIR filters.
🔧 Debug
advanced
2:00remaining
Identify the error in filter design code
What error does the following code raise when trying to design a Butterworth bandpass filter with cutoff frequencies 0.2 and 0.5?
SciPy
from scipy.signal import butter
b, a = butter(3, [0.2, 0.5], btype='bandpass')
ANo error, returns filter coefficients
BTypeError: 'bandpass' is not a valid filter type
CValueError: Digital filter critical frequencies must be strictly increasing and 0 < Wn < 1
DSyntaxError: invalid syntax
Attempts:
2 left
💡 Hint
Check the valid filter types and cutoff frequency ranges for butter().
❓ visualization
advanced
2:00remaining
Frequency response plot of Chebyshev Type I filter
Which option correctly plots the frequency response magnitude (in dB) of a 5th order Chebyshev Type I lowpass filter with 0.5 normalized cutoff and 0.5 dB ripple?
SciPy
import matplotlib.pyplot as plt
import numpy as np
from scipy.signal import cheby1, freqz
b, a = cheby1(5, 0.5, 0.5, btype='low')
w, h = freqz(b, a)
plt.plot(w / 3.1415, 20 * np.log10(abs(h)))
plt.xlabel('Normalized Frequency')
plt.ylabel('Magnitude (dB)')
plt.title('Frequency Response')
plt.grid(True)
plt.show()
APlots frequency response with x-axis from 0 to 1 and y-axis showing magnitude in dB
BPlots frequency response with x-axis in Hz (0 to 5000) and y-axis linear magnitude
CPlots phase response instead of magnitude
DRaises NameError due to missing numpy import
Attempts:
2 left
💡 Hint
Check if all required libraries are imported before plotting.
🚀 Application
expert
3:00remaining
Choosing filter type for sharp cutoff with minimal ripple
You need to design a digital IIR filter with a very sharp cutoff and minimal passband ripple for a biomedical signal sampled at 1000 Hz. Which filter design and parameters below best meet this requirement?
AUse a 6th order Chebyshev Type I lowpass filter with 0.5 dB ripple and cutoff 100 Hz
BUse a 6th order Butterworth lowpass filter with cutoff 100 Hz
CUse a 6th order Chebyshev Type II lowpass filter with 40 dB stopband attenuation and cutoff 100 Hz
DUse a 6th order Elliptic lowpass filter with 0.5 dB ripple and 40 dB stopband attenuation
Attempts:
2 left
💡 Hint
Chebyshev Type II filters have flat passband and sharp cutoff with stopband ripple.

Practice

(1/5)
1. What is the main difference between a Butterworth and a Chebyshev IIR filter in scipy.signal?
easy
A. Butterworth filters are FIR, Chebyshev filters are IIR.
B. Butterworth filters have ripples, Chebyshev filters have a smooth response.
C. Butterworth filters are only for high-pass, Chebyshev only for low-pass.
D. Butterworth filters have a smooth frequency response, Chebyshev filters have ripples in the passband.

Solution

  1. Step 1: Understand Butterworth filter characteristics

    Butterworth filters are designed to have a maximally flat frequency response in the passband, meaning no ripples.
  2. Step 2: Understand Chebyshev filter characteristics

    Chebyshev filters allow ripples in the passband to achieve a sharper cutoff compared to Butterworth filters.
  3. Final Answer:

    Butterworth filters have a smooth frequency response, Chebyshev filters have ripples in the passband. -> Option D
  4. Quick Check:

    Butterworth smooth, Chebyshev ripples = D [OK]
Hint: Butterworth = smooth, Chebyshev = ripples [OK]
Common Mistakes:
  • Confusing which filter has ripples
  • Thinking Butterworth is FIR
  • Assuming filter types are limited to passband types
2. Which of the following is the correct way to design a 4th order Butterworth lowpass filter with cutoff frequency 0.3 (normalized) using scipy.signal.butter?
easy
A. b, a = butter(0.3, 4, btype='low')
B. b, a = butter(4, 0.3, btype='low')
C. b, a = butter(4, 0.3, type='lowpass')
D. b, a = butter(order=4, cutoff=0.3, kind='low')

Solution

  1. Step 1: Recall butter function signature

    The function signature is butter(N, Wn, btype='low', analog=False, output='ba'), where N is order and Wn is cutoff frequency.
  2. Step 2: Check correct parameter usage

    b, a = butter(4, 0.3, btype='low') uses butter(4, 0.3, btype='low'), which matches the signature correctly.
  3. Final Answer:

    b, a = butter(4, 0.3, btype='low') -> Option B
  4. Quick Check:

    Order first, cutoff second, btype='low' = A [OK]
Hint: Order first, cutoff second, btype='low' in butter() [OK]
Common Mistakes:
  • Swapping order and cutoff parameters
  • Using wrong keyword names like 'type' or 'kind'
  • Passing cutoff frequency as first argument
3. What will be the output shape of the coefficients when running this code?
from scipy.signal import cheby1
b, a = cheby1(3, 1, 0.4, btype='high')
medium
A. (3,), (3,)
B. (3, 3), (3, 3)
C. (4,), (4,)
D. (2,), (2,)

Solution

  1. Step 1: Understand cheby1 output

    The function returns numerator (b) and denominator (a) coefficients arrays each of length N+1, where N is filter order.
  2. Step 2: Calculate length for order 3

    For order 3, length is 3+1 = 4, so both b and a have shape (4,).
  3. Final Answer:

    (4,), (4,) -> Option C
  4. Quick Check:

    Length = order + 1 = 4 [OK]
Hint: Coefficients length = order + 1 [OK]
Common Mistakes:
  • Assuming length equals order
  • Expecting 2D arrays instead of 1D
  • Confusing numerator and denominator shapes
4. Identify the error in this code snippet for designing a Chebyshev type I filter:
from scipy.signal import cheby1
b, a = cheby1(5, 0.5, 0.2, btype='bandpass')
medium
A. The cutoff frequency should be a list or tuple for bandpass, not a single float.
B. The ripple parameter is missing and required.
C. The order parameter should be a float, not integer.
D. The btype 'bandpass' is not supported by cheby1.

Solution

  1. Step 1: Check bandpass cutoff frequency format

    For bandpass filters, cutoff frequency must be a sequence (list or tuple) of two frequencies, not a single float.
  2. Step 2: Verify other parameters

    Order as integer and ripple (second parameter) are correctly provided; btype 'bandpass' is valid.
  3. Final Answer:

    The cutoff frequency should be a list or tuple for bandpass, not a single float. -> Option A
  4. Quick Check:

    Bandpass cutoff needs two frequencies = C [OK]
Hint: Bandpass cutoff must be two frequencies in a list/tuple [OK]
Common Mistakes:
  • Passing single float for bandpass cutoff
  • Confusing ripple parameter position
  • Using unsupported btype values
5. You want to design a Chebyshev type I lowpass filter with order 6, 0.5 dB ripple, and cutoff frequency 0.25. Which code snippet correctly creates the filter and applies it to a signal x using scipy.signal.lfilter?
hard
A. from scipy.signal import cheby1, lfilter b, a = cheby1(6, 0.5, 0.25, btype='low') y = lfilter(b, a, x)
B. from scipy.signal import cheby1, lfilter b, a = cheby1(6, 0.5, 0.25, btype='high') y = lfilter(a, b, x)
C. from scipy.signal import butter, lfilter b, a = butter(6, 0.25, btype='low') y = lfilter(b, a, x)
D. from scipy.signal import cheby1, lfilter b, a = cheby1(0.5, 6, 0.25, btype='low') y = lfilter(b, a, x)

Solution

  1. Step 1: Verify cheby1 parameters order

    Order is first parameter (6), ripple second (0.5), cutoff third (0.25), and btype='low' for lowpass.
  2. Step 2: Check lfilter usage

    lfilter takes numerator coefficients (b), denominator coefficients (a), and signal (x) in that order.
  3. Final Answer:

    from scipy.signal import cheby1, lfilter b, a = cheby1(6, 0.5, 0.25, btype='low') y = lfilter(b, a, x) -> Option A
  4. Quick Check:

    Correct order and lfilter usage = A [OK]
Hint: Order, ripple, cutoff in cheby1; lfilter(b, a, x) [OK]
Common Mistakes:
  • Swapping order and ripple parameters
  • Using butter instead of cheby1
  • Swapping b and a in lfilter
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard