FIR Digital Filter using triangular Window technique
This section of MATLAB source code covers FIR low pass and high pass filter using triangular method.
FIR Low Pass Filter MATLAB Code
clc;
close all;
clear all;
format long;
rp=input('enter the passband ripple:(default:0.04)');
rs=input('enter the stopband ripple:(default:0.02)');
fp=input('enter the passband frequency:(default:1500)');
fs=input('enter the stopband frequency:(default:2000)');
f=input('enter the sampling frequency:(default:8000)');
wp=2*(fp/f);
ws=2*(fs/f);
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end;
y=triang(n1);
%Lowpass filter
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,1);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('Normalised frequency---->');
title('FIR filter using Triangular window of LPF ----');
grid on;
close all;
clear all;
format long;
rp=input('enter the passband ripple:(default:0.04)');
rs=input('enter the stopband ripple:(default:0.02)');
fp=input('enter the passband frequency:(default:1500)');
fs=input('enter the stopband frequency:(default:2000)');
f=input('enter the sampling frequency:(default:8000)');
wp=2*(fp/f);
ws=2*(fs/f);
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end;
y=triang(n1);
%Lowpass filter
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,1);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('Normalised frequency---->');
title('FIR filter using Triangular window of LPF ----');
grid on;
FIR High Pass Filter MATLAB Code
%Highpass filter
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,2);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('Normalised frequency---->');
title('FIR filter using Triangular window of HPF ----');
grid on ;
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,2);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('Normalised frequency---->');
title('FIR filter using Triangular window of HPF ----');
grid on ;
Output plot
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