Bird
Raised Fist0
Signal Processingdata~5 mins

High-pass FIR filter design in Signal Processing

Choose your learning style10 modes available
Introduction

A high-pass FIR filter lets high frequencies pass and blocks low frequencies. It helps remove slow changes or noise from signals.

Removing slow background noise from audio recordings
Extracting fast changes in sensor data like heartbeats
Cleaning images by removing smooth color areas
Separating high-frequency parts in communication signals
Syntax
Signal Processing
from scipy.signal import firwin

numtaps = 51  # Number of filter taps (length)
cutoff = 0.3  # Normalized cutoff frequency (0 to 1, where 1 is Nyquist)

# Design high-pass FIR filter coefficients
coefficients = firwin(numtaps, cutoff, pass_zero=False)

numtaps controls filter length and sharpness.

cutoff is the cutoff frequency normalized by Nyquist frequency.

Examples
Designs a 31-tap high-pass FIR filter with cutoff at 0.4 (normalized frequency).
Signal Processing
from scipy.signal import firwin
coeffs = firwin(31, 0.4, pass_zero=False)
Designs a shorter 21-tap high-pass filter with cutoff at 0.2.
Signal Processing
coeffs = firwin(21, 0.2, pass_zero=False)
Sample Program

This code creates a high-pass FIR filter with 51 taps and cutoff at 0.3 normalized frequency. It then plots the filter's frequency response showing how it blocks low frequencies and passes high frequencies. Finally, it prints the first 5 filter coefficients.

Signal Processing
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import firwin, freqz

# Filter parameters
numtaps = 51
cutoff = 0.3  # Normalized cutoff frequency

# Design high-pass FIR filter
coefficients = firwin(numtaps, cutoff, pass_zero=False)

# Frequency response
w, h = freqz(coefficients, worN=8000)

# Plot frequency response
plt.plot(w / np.pi, 20 * np.log10(abs(h)))
plt.title('High-pass FIR Filter Frequency Response')
plt.xlabel('Normalized Frequency (×π rad/sample)')
plt.ylabel('Amplitude (dB)')
plt.grid(True)
plt.show()

# Print first 5 coefficients
print('First 5 filter coefficients:', coefficients[:5])
OutputSuccess
Important Notes

Longer filters (more taps) give sharper cutoff but use more computation.

Normalized frequency means 1 corresponds to half the sampling rate (Nyquist frequency).

Use pass_zero=False to specify a high-pass filter in firwin.

Summary

High-pass FIR filters block low frequencies and allow high frequencies.

Use firwin with pass_zero=False to design them.

Filter length and cutoff frequency control filter sharpness and range.

Practice

(1/5)
1. What is the main purpose of a high-pass FIR filter in signal processing?
easy
A. To block high frequencies and allow low frequencies to pass
B. To block low frequencies and allow high frequencies to pass
C. To amplify all frequencies equally
D. To convert analog signals to digital

Solution

  1. Step 1: Understand filter types

    High-pass filters are designed to block low frequencies and pass high frequencies.
  2. Step 2: Match definition to options

    To block low frequencies and allow high frequencies to pass correctly describes this behavior, while others describe different functions.
  3. Final Answer:

    To block low frequencies and allow high frequencies to pass -> Option B
  4. Quick Check:

    High-pass filter = block low, pass high [OK]
Hint: High-pass filters block lows, pass highs [OK]
Common Mistakes:
  • Confusing high-pass with low-pass filters
  • Thinking it amplifies all frequencies
  • Mixing filter function with signal conversion
2. Which of the following is the correct way to design a high-pass FIR filter using firwin in Python?
easy
A. firwin(numtaps=51, cutoff=0.3, pass_zero=False)
B. firwin(numtaps=51, cutoff=0.3)
C. firwin(numtaps=51, cutoff=0.3, pass_zero=True)
D. firwin(numtaps=51, cutoff=0.3, pass_zero='lowpass')

Solution

  1. Step 1: Recall firwin parameters for high-pass

    To design a high-pass filter, pass_zero must be set to False.
  2. Step 2: Check options for correct usage

    firwin(numtaps=51, cutoff=0.3, pass_zero=False) uses pass_zero=False, which is correct. firwin(numtaps=51, cutoff=0.3, pass_zero=True) uses pass_zero=True (low-pass), firwin(numtaps=51, cutoff=0.3) defaults to pass_zero=True (low-pass), and firwin(numtaps=51, cutoff=0.3, pass_zero='lowpass') also creates a low-pass filter.
  3. Final Answer:

    firwin(numtaps=51, cutoff=0.3, pass_zero=False) -> Option A
  4. Quick Check:

    High-pass firwin = pass_zero=False [OK]
Hint: Use pass_zero=False for high-pass firwin [OK]
Common Mistakes:
  • Using pass_zero=True which creates low-pass filter
  • Omitting pass_zero defaults to low-pass
  • Using pass_zero='lowpass' which creates low-pass filter
3. What will be the length of the filter coefficients array when running firwin(numtaps=31, cutoff=0.4, pass_zero=False)?
medium
A. 30
B. Depends on cutoff
C. 32
D. 31

Solution

  1. Step 1: Understand numtaps parameter

    The numtaps parameter defines the number of filter coefficients (length of the filter).
  2. Step 2: Apply to given code

    Since numtaps=31, the output array length will be exactly 31 regardless of cutoff or pass_zero.
  3. Final Answer:

    31 -> Option D
  4. Quick Check:

    numtaps = filter length = 31 [OK]
Hint: Filter length equals numtaps value [OK]
Common Mistakes:
  • Thinking length depends on cutoff frequency
  • Assuming length is numtaps - 1
  • Confusing pass_zero effect on length
4. Identify the error in this code snippet for designing a high-pass FIR filter:
from scipy.signal import firwin
coeffs = firwin(numtaps=40, cutoff=0.25, pass_zero=True)
medium
A. pass_zero should be False for high-pass filter
B. numtaps must be an odd number
C. cutoff frequency must be greater than 0.5
D. firwin does not accept pass_zero parameter

Solution

  1. Step 1: Check pass_zero parameter meaning

    For a high-pass filter, pass_zero must be set to False. Here it is True, which creates a low-pass filter.
  2. Step 2: Verify other parameters

    Numtaps can be even or odd, cutoff is valid (0.25 < 0.5), and firwin accepts pass_zero parameter.
  3. Final Answer:

    pass_zero should be False for high-pass filter -> Option A
  4. Quick Check:

    High-pass firwin needs pass_zero=False [OK]
Hint: High-pass needs pass_zero=False, not True [OK]
Common Mistakes:
  • Assuming numtaps must be odd
  • Thinking cutoff must be above 0.5
  • Ignoring pass_zero parameter role
5. You want to design a high-pass FIR filter with a sharp cutoff at 0.6 normalized frequency and minimal ripple. Which combination of parameters is best to achieve this using firwin?
hard
A. numtaps=100, cutoff=0.3, pass_zero=False
B. numtaps=10, cutoff=0.6, pass_zero=False
C. numtaps=100, cutoff=0.6, pass_zero=False
D. numtaps=10, cutoff=0.3, pass_zero=True

Solution

  1. Step 1: Understand filter sharpness and ripple

    Higher numtaps means a sharper cutoff and less ripple in the filter response.
  2. Step 2: Match cutoff and pass_zero for high-pass

    Cutoff at 0.6 and pass_zero=False correctly define a high-pass filter with cutoff at 0.6.
  3. Step 3: Evaluate options

    numtaps=100, cutoff=0.6, pass_zero=False has high numtaps (100) for sharpness, correct cutoff (0.6), and correct pass_zero (False). Others have low numtaps or wrong cutoff/pass_zero.
  4. Final Answer:

    numtaps=100, cutoff=0.6, pass_zero=False -> Option C
  5. Quick Check:

    Sharp high-pass = high numtaps + cutoff 0.6 + pass_zero=False [OK]
Hint: Use large numtaps and pass_zero=False for sharp high-pass [OK]
Common Mistakes:
  • Using low numtaps for sharp cutoff
  • Setting cutoff too low for desired frequency
  • Using pass_zero=True for high-pass filter
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