Butterworth Digital Band Pass Filter | Scigyan

Butterworth Digital Band Pass Filter

Matlab program to design Butter-worth Digital Band Pass Filter.

Matlab code

clc; clear all; close all;
rp=input('Enter the Passband ripple (In db) = '); 
rs=input('Enter the Stopband attenuation (In db) = '); 
fpc=input('Enter the Passband corner frequency (In Hz) = ');
fsc=input('Enter the Stopband corner frequency (In Hz) = '); 
fs=input('Enter the Sampling frequency (In Hz) = ');

fn=fs/2; % Unit frequency is the Nyquist frequency, defined as half the sampling frequency
Wp=fpc/fn; % Normalized passband corner frequency
Ws=fsc/fn; % Normalized stopband corner frequency
n=buttord(Wp,Ws,rp,rs);% n = Minimum order & Wn = cut-off frequency for Butterworth filter.
Wn=[Wp,Ws];
[b,a]=butter(n,Wn,'bandpass');
L=1024;%L define length of vectors h and w [Default value of L is 512 samples when not define]
[h,w] = freqz(b,a,L); % It returns frequency response vector h & angular frequency vector w

wi=w/pi; % Normalized angular frequency vector
mag = 20*log10(abs(h)); %Magnitude of h
ang = angle(h); %Angle of h

subplot(2,1,1);
plot(wi,mag);
title('Magnitude Response [Butterworth Digital Band Pass Filter]'); 
ylabel('Gain in dB -->');
xlabel('Normalised Frequency ( x pi rad/sample)-->'); 
grid on;

subplot(2,1,2);
plot(wi,ang); title('Phase Response');
xlabel('Normalised Frequency ( x pi rad/sample)-->'); 
ylabel('Phase in radians -->');
grid on;

Command window

Enter the Passband ripple (In db) = 2
Enter the Stopband attenuation (In db) = 80
Enter the Passband corner frequency (In Hz) = 400
Enter the Stopband corner frequency (In Hz) = 600
Enter the Sampling frequency (In Hz) = 2000

Figure window

Butterworth-Digital-Band-Pass-Filter

No comments:
Post a Comment

Related Posts Plugin for WordPress, Blogger...