An FIR filter helps clean or change signals by mixing past input values with fixed weights.
FIR filter structure in Signal Processing
y[n] = b0*x[n] + b1*x[n-1] + b2*x[n-2] + ... + bM*x[n-M]
y[n] is the output at time n.
x[n] is the input at time n, and b0, b1, ..., bM are fixed filter weights called coefficients.
y[n] = 0.2*x[n] + 0.2*x[n-1] + 0.2*x[n-2] + 0.2*x[n-3] + 0.2*x[n-4]
y[n] = 0.5*x[n] + 0.3*x[n-1] + 0.2*x[n-2]
This code creates a noisy sine wave and smooths it using a 5-point FIR filter (moving average). The plot shows how the filter cleans the noise.
import numpy as np import matplotlib.pyplot as plt # Input signal: noisy sine wave fs = 100 # samples per second T = 1 # seconds x = np.linspace(0, T, fs*T, endpoint=False) signal = np.sin(2 * np.pi * 5 * x) + 0.5 * np.random.randn(len(x)) # FIR filter coefficients (simple moving average of length 5) coeffs = np.ones(5) / 5 # Apply FIR filter using convolution filtered_signal = np.convolve(signal, coeffs, mode='same') # Plot input and filtered signals plt.figure(figsize=(8,4)) plt.plot(x, signal, label='Noisy input') plt.plot(x, filtered_signal, label='Filtered output', linewidth=2) plt.xlabel('Time [s]') plt.ylabel('Amplitude') plt.title('FIR Filter Structure Example') plt.legend() plt.tight_layout() plt.show()
The FIR filter output depends only on current and past input values, never on past outputs.
FIR filters are always stable and have a linear phase, meaning they do not distort signal timing.
The length of the filter (number of coefficients) controls how much smoothing or shaping happens.
An FIR filter mixes past input values with fixed weights to change a signal.
It is useful for noise removal, smoothing, and shaping signals.
The filter output is a weighted sum of current and past inputs only.