0
0
Signal Processingdata~5 mins

High-pass FIR filter design in Signal Processing

Choose your learning style9 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.