FIR Digital Filter MATLAB source code

This section of MATLAB source code covers FIR digital filter matlab code. It describes FIR filter as per rectangular,Bartlett,Blackman,Chebyshev,Hamming and Hanning window types.

This page covers FIR Digital Filter with window type as Hamming window. The same is used by 'fir1' matlab function by default.

FIR digital filter operates on digital sample values. It uses current and past input samples to produce a current output sample. It does not use previous output samples. There are various types of FIR filter based on need viz. low pass,high pass, band pass and band stop.Low pass filter is described in the below code.

FIR Filter Specifications

Following points are usually considered to design FIR filter other the window type.
INPUT:
• Window Type
• Passband and stopband ripples
• passband and stopband edge frequencies
• sampling frequency
• order of the filter
• window coefficients
OUTPUT:
• magnitude and phase responses

Entering Input parameters

clc;clear all;close all;
rp=input('enter the passband ripple(Example:0.02):');
rs=input('enter the stopband ripple(Example:0.01):');
fp=input('enter the passband freq(Example:1500):');
fs=input('enter the stopband freq(Example:2000):');
f=input('enter the sampling freq(Example:6000):');

MATLAB built-in 'fir1' MATLAB function

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=hamming(n1);

% low-pass filter
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
figure,plot(o/pi,m);title('FIR Filter Response');ylabel('Gain in dB');xlabel('Normalised frequency');


INPUT and OUTPUT of Low Pass FIR filter

FIR filter input
FIR filter output

Low Pass and High Pass FIR Filter using kaiser,rectangular and triangular window method

FIR LPF HPF using triangular window method
FIR LPF HPF using rectangular window method
FIR LPF HPF using kaiser window method

Useful Links to MATLAB codes

Refer following as well as links mentioned on left side panel for useful MATLAB codes.
PTS for PAPR reduction
OFDM Preamble generation
Time off estimation corr
Freq off estimation corr
channel estimation
11a WLAN channel
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