Skip to content

Instantly share code, notes, and snippets.

@Arunprakash-A
Last active May 26, 2021 17:10
Show Gist options
  • Save Arunprakash-A/b4a762425fc9aeaec3fbab8569f116dc to your computer and use it in GitHub Desktop.
Save Arunprakash-A/b4a762425fc9aeaec3fbab8569f116dc to your computer and use it in GitHub Desktop.
IIR Butterworth filter design in Matlab
% ************IIR Analog Butterworth Filter Design ******************%
%************* Author : Arun Prakash A ******************************%
clc;
clear all;
close all;
% Specifications
Wp=2*pi*100; % Passband cutoff in rad/s
Ws=2*pi*200; % stopband cutoff in rad/s
Fs=8000; % Sampling Frequency
Ts=1/Fs;
wp=Wp*Ts; % Digital passband cutoff freq in rad/sample
ws=Ws*Ts; % Digital stopband cutoff freq in rad/sample
ap=3; % passband attenuation in dB
as=30; % stopband Attenuation in dB
% Design Starts from here
[N,wc]=buttord(wp,ws,ap,as,'s'); % returns order and Wc
[zeros,poles,kf]=buttap(N); % returns Pole locations and gain
[ztn,ptn]=zp2tf(zeros,poles,kf); % cooefficients of denominator polynomial
[normalized_zeros,normalized_poles]=lp2lp(ztn,ptn,wc); % Denormalize
[mag,freq]=freqs(normalized_zeros,normalized_poles,500); % plot magnitude response
%plot the magnitude response
plot((freq/(2*pi))*Fs,20*log10(abs(mag))); % ./ 2*pi to see an integer of freq in Hz
axis([0 400 -50 0 ])
title('Analog Butterworth Filter');
xlabel('Frequency in Hz');
ylabel('Magnitude in dB');
grid on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment