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.
Practice
Solution
Step 1: Understand FIR filter basics
An FIR filter uses a fixed number of past input values combined with fixed weights (coefficients) to produce the output.Step 2: Compare options with FIR definition
A fixed set of past input values and weights correctly describes this process. Options B and C describe other filter types or incorrect concepts. Only the current input value without memory ignores the memory aspect.Final Answer:
A fixed set of past input values and weights -> Option CQuick Check:
FIR = past inputs + fixed weights [OK]
- Confusing FIR with IIR filters that use feedback
- Thinking FIR uses only current input
- Assuming FIR filters add noise intentionally
y[n] of an FIR filter with coefficients h[k] and input x[n]?Solution
Step 1: Recall FIR filter formula
The output y[n] is the sum of products of filter coefficients h[k] and past inputs x[n-k] from k=0 to N-1.Step 2: Check each option
y[n] = sum(h[k] * x[n-k]) for k=0 to N-1 matches the FIR formula. y[n] = sum(h[k] * y[n-k]) for k=0 to N-1 uses past outputs, which is IIR. y[n] = h[n] * x[n] is just a single multiplication, not a sum. y[n] = sum(x[k] * y[n-k]) for k=0 to N-1 mixes inputs and outputs incorrectly.Final Answer:
y[n] = sum(h[k] * x[n-k]) for k=0 to N-1 -> Option DQuick Check:
FIR output = weighted sum of past inputs [OK]
- Using past outputs instead of inputs
- Forgetting to sum over all coefficients
- Confusing multiplication with convolution
h = [0.2, 0.5, 0.3] and input signal x = [1, 2, 3, 4], what is the output y[2] (third output value)?Solution
Step 1: Write the formula for y[2]
y[2] = h[0]*x[2] + h[1]*x[1] + h[2]*x[0] = 0.2*3 + 0.5*2 + 0.3*1Step 2: Perform the calculation
0.2*3 = 0.6, 0.5*2 = 1.0, 0.3*1 = 0.3; sum = 1.9Final Answer:
1.9 -> Option BQuick Check:
0.2*3 + 0.5*2 + 0.3*1 = 1.9 [OK]
- Mixing coefficient order
- Wrong indexing of input signal
- Ignoring zero padding for early outputs
h = [0.1, 0.2, 0.3]
x = [1, 2, 3, 4]
y = []
for n in range(len(x)):
s = 0
for k in range(len(h)):
s += h[k] * x[n+k]
y.append(s)Solution
Step 1: Analyze indexing in inner loop
The code uses x[n+k], but when n is near the end of x, n+k can exceed x's length causing an error.Step 2: Confirm correct indexing for FIR
FIR uses x[n-k], not x[n+k]. Using n+k moves forward, causing out-of-range and wrong filtering.Final Answer:
Indexing x with n+k causes out-of-range error -> Option AQuick Check:
Index x with n-k, not n+k [OK]
- Using forward indexing n+k instead of backward n-k
- Not handling boundary conditions
- Confusing coefficient order
h should you use?Solution
Step 1: Understand smoothing by averaging
Smoothing by averaging means each of the last 4 inputs contributes equally to the output.Step 2: Choose equal coefficients summing to 1
Equal weights for 4 samples means each coefficient is 1/4 = 0.25, so h = [0.25, 0.25, 0.25, 0.25].Final Answer:
[0.25, 0.25, 0.25, 0.25] -> Option AQuick Check:
Equal weights sum to 1 for smoothing [OK]
- Using unequal weights for averaging
- Not normalizing coefficients to sum 1
- Choosing coefficients that emphasize recent inputs only
Ready to prove it?
Pass the test and this pattern moves unknown
