Filter design: FIR and IIR high, low, band-pass filter implementation and Matlab code

Filter design: FIR and IIR high, low, band-pass filter implementation and Matlab code

Introduction:
As a very important part of signal processing, filters are widely used in digital signal processing, audio processing, image processing and other fields. This article mainly discusses the design and implementation of two common filters, FIR (finite impulse response) and IIR (infinite impulse response).

  1. FIR filter
    FIR filter has the advantages of stability, linear phase characteristics, etc., but its computational complexity is relatively high. The design and implementation of the high-pass, low-pass, and band-pass filters of the FIR filter are introduced below through examples.

1.1 Implementation process

  1. Determine the type of filter (high pass, low pass, band pass)
  2. Determine parameters such as cutoff frequency or passband, stopband range and attenuation coefficient
  3. Calculate the coefficients of the filter
  4. Using Matlab to Realize Filter

1.2 Example code
% High pass filter
fs = 1000; % Sampling frequency
fc = 100; % Cutoff frequency
N = 50; % Filter order
wn = fc/(fs/2);
b = fir1(N,wn,'high ');
freqz(b,1);

% low pass filter
fs = 1000; % sampling frequency
fc = 100; % cutoff frequency
N = 50; % filter order
wn = fc/(fs/2);
b = fir1(N,wn,'low') ;
freqz(b,1);

% Bandpass filter
fs = 1000; % Sampling frequency
f1 = 100; % Passband left frequency
f2 = 200; % Passband right frequency
N = 50; % Filter order
wn = [f1 f2]/(fs /2);
b = fir1(N,wn,'bandpass'

Guess you like

Origin blog.csdn.net/wellcoder/article/details/130073626