ad space

Designing and Analyzing a Low-Pass Butterworth Filter in MATLAB: A Step-by-Step Guide

Low-pass filters (LPF) are essential in signal processing to eliminate high-frequency noise. In this guide, we’ll design and analyze a Butterworth LPF in MATLAB, moving step-by-step from defining filter parameters to visualizing its frequency response. We’ll also explore its poles and zeros to better understand filter behavior.

Step 1: Define Filter Parameters

To begin, we set our cutoff frequency to 200 Hz and the sampling frequency to 1000 Hz. These values will shape the filter’s characteristics.

% Define filter parameters
fc = 200; % Cutoff frequency in Hz
fs = 1000; % Sampling frequency in Hz

Step 2: Design a 2nd-Order Butterworth LPF

Using the Butterworth filter function butter(), we calculate the filter coefficients, which will allow us to create a low-pass filter with a smooth response in the passband.

% Calculate filter coefficients
[b, a] = butter(2, 2*fc/fs); % 2nd order filter, normalized cutoff


 

Here, [b, a] represent the numerator and denominator coefficients for the transfer function.

Step 3: Create Transfer Function and Extract Coefficients

Next, we’ll define the transfer function using tf(), with sampling time 1/fs to ensure proper scaling.

% Calculate filter coefficients
[b, a] = butter(2, 2*fc/fs); % 2nd order filter, normalized cutoff

Step 4: Convert to Symbolic Transfer Function

For a clearer understanding, we convert the transfer function to a symbolic expression and display it in a readable format.

syms z;
H_sym = poly2sym(num, z) / poly2sym(den, z);
H_str = char(vpa(H_sym, 3));

Step 5: Display the Transfer Function Equation

Now, we print the symbolic form of the transfer function.

disp('Transfer function equation:');
disp(H_str);

 

 

The transfer function might look something like:

0.207z2+0.413z+0.207z20.37z+0.196\frac{0.207 z^2 + 0.413 z + 0.207}{z^2 - 0.37 z + 0.196}

Step 6: Plot Poles and Zeros of the Filter

To assess the filter’s stability, we plot its poles and zeros using zplane().

zplane(b, a);
title('Pole-Zero Plot of Low-Pass Filter');

Step 7: Plot Frequency Response

Finally, we use freqz() to observe how the filter attenuates high-frequency components.

freqz(b, a);
title('Frequency Response of the Low-Pass Filter');

Complete MATLAB Code

Here is the complete code to design and analyze a 2nd-order Butterworth LPF:

clear
fc = 200; % Cutoff frequency
fs = 1000; % Sampling frequency
[b, a] = butter(2, 2*fc/fs); % Calculate filter coefficients

H = tf(b, a, 1/fs);
[num, den] = tfdata(H, 'v');

% Convert transfer function to symbolic expression
syms z;
H_sym = poly2sym(num, z) / poly2sym(den, z);
H_str = char(vpa(H_sym, 3));

% Display transfer function equation
disp('Transfer function equation:');
disp(H_str);

% Plot poles and zeros
zplane(b, a);
title('Pole-Zero Plot of Low-Pass Filter');

% Plot frequency response
freqz(b, a);


Summary

In this guide, we designed a 2nd-order Butterworth low-pass filter in MATLAB with a 200 Hz cutoff frequency and 1000 Hz sampling frequency. We visualized its frequency response and pole-zero plot, gaining insights into its filtering characteristics and stability.

Conclusion

The Butterworth filter is widely used due to its smooth passband response and ease of implementation. Following these steps, you can design and analyze your own LPFs in MATLAB for various signal processing applications.

References

  1. FIR and IIR Filter Design with Z-Transform
  2. Frequency Sampling Method for FIR Filter Design
  3. Computing the Z-Transform in MATLAB

Post a Comment

Previous Post Next Post