Butterworth filter

This section of MATLAB source code covers butterworth low pass filter and high pass filter matlab code.

Butterworth Low Pass Filter MATLAB Code

%Butterworth Low Pass Filter
clc;
close all;
clear all;
format long;
rp=input('enter the passband ripple:(default:0.15)');
rs=input('enter the stopband ripple:(default:60)');
wp=input('enter the passband frequency:(default:1500)');
ws=input('enter the stopband frequency:(default:3000)');
fs=input('enter the sampling frequency:(default:7000)');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
[z,p,k]= butter(n,wn);
[b,a]=butter(n,wn,'s');
w=0:0.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('gain in db--------->');
xlabel('(a) normalized freq------>');
subplot(2,1,2);
plot(om/pi,an);
ylabel('phase in db--------->');
xlabel('(b) normalized freq------>');

Output plot

Butterworth low pass filter matlab

Butterworth High Pass Filter MATLAB Code

%Butterworth High Pass Filter
clc;
close all;
clear all;
format long;
rp=input('enter the passband ripple:(default:0.2)');
rs=input('enter the stopband ripple:(default:40)');
wp=input('enter the passband frequency:(default:2000)');
ws=input('enter the stopband frequency:(default:3500)');
fs=input('enter the sampling frequency:(default:8000)');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
[z,p,k]= butter(n,wn);
[b,a]=butter(n,wn,'high','s');
w=0:0.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('gain in db--------->');
xlabel('(a) normalized freq------>');
subplot(2,1,2);
plot(om/pi,an);
ylabel('phase in db--------->');
xlabel('(b) normalized freq------>');

Output plot

Butterworth high pass filter matlab

Useful Links to MATLAB codes

Refer following as well as links mentioned on left side panel for useful MATLAB codes.
OFDM Preamble generation  Time off estimation corr  Freq off estimation corr  channel estimation  11a WLAN channel  PN sequence generation  OFDMA Tx Rx  AES DES  carrier aggregation  CCDF  FIR Filter  IIR Filter  Low Pass FIR  Viterbi decoder  CRC8 CRC32 

RF and Wireless tutorials

WLAN  802.11ac  802.11ad  wimax  Zigbee  z-wave  GSM  LTE  UMTS  Bluetooth  UWB  IoT  satellite  Antenna  RADAR