0
0
Signal Processingdata~5 mins

FIR filter structure in Signal Processing

Choose your learning style9 modes available
Introduction

An FIR filter helps clean or change signals by mixing past input values with fixed weights.

To remove noise from a recorded sound or sensor data.
To smooth out sudden jumps in temperature readings.
To shape the frequency of a music signal for better sound.
To delay a signal without changing its shape.
To create simple digital effects in audio processing.
Syntax
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.

Examples
This is a simple 5-point moving average filter that smooths the input signal.
Signal Processing
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]
A 3-point FIR filter with different weights to emphasize recent inputs more.
Signal Processing
y[n] = 0.5*x[n] + 0.3*x[n-1] + 0.2*x[n-2]
Sample Program

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.

Signal Processing
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()
OutputSuccess
Important Notes

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.

Summary

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.