A high-pass FIR filter lets high frequencies pass and blocks low frequencies. It helps remove slow changes or noise from signals.
High-pass FIR filter design in 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.
from scipy.signal import firwin coeffs = firwin(31, 0.4, pass_zero=False)
coeffs = firwin(21, 0.2, pass_zero=False)
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.
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])
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.
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.