Code covered by the BSD License  

Highlights from
FIR Filter design

FIR Filter design

by

 

Designing FIR Frequency selective filters

FIR_Filter_design.m
% LPF stands for Low pass filter
% HPF stands for High pass filter
% BPF stands for Band pass filter
% BRF stands for Band reject filter
% Rectangular, Hanning and hamming are different types of Windowing
% techniques

clear all
clc;
w=0:pi/20:pi;
q=1:1:7
%plottting different types of windows
%rectangular window
for j=1:1:7
    rect(j)=1;
end
plot(q,rect,'r*')
xlabel('time (seconds)')
ylabel('Magnitue')
title('\it{Plotting rectangular window}','FontSize',16)
text(2.5,1.5,'rect','FontSize',16)
figure,

%Hanning window
for j=1:1:7
    hanning(j)=(1/2)*(1-cos((pi/3)*j));
end
plot(q,hanning,'g')
xlabel('time (seconds)')
ylabel('Magnitue')
title('\it{Plotting hanning window}','FontSize',16)
text(5,0.8,'hanning','FontSize',16)
figure,

%Hamming window
for j=1:1:7
    hamming(j)=0.54-0.46*cos((pi/3)*j);
end
plot(q,hamming,'b')
xlabel('time (seconds)')
ylabel('Magnitue')
title('\it{Plotting hamming window}','FontSize',16)
text(5,0.8,'hamming','FontSize',16)
figure,

%plotting LPF using different windows

for i=0:pi/20:pi
    lpf_rect((i)*(20/pi)+1)=0.318+2*(0.268*cos(i)+0.145*cos(2*i)+0.015*cos(3*i));
end
plot(w,lpf_rect,'r*')       % rectangular window
xlabel('Frequency (Hz)')
ylabel('Gain')
title('\it{Plotting LPF using rectangular window}','FontSize',16)
text(2,1,'lpfrect','FontSize',16)

figure,
for i=0:pi/20:pi
    lpf_hanning((i)*(20/pi)+1)=0.318+2*(0.201*cos(i)+0.036*cos(2*i));
end
plot(w,lpf_hanning,'g*')       % Hanning window
xlabel('Frequency (Hz)')
ylabel('Gain')
title('\it{Plotting LPF using hanning window}','FontSize',16)
text(2,0.7,'lpfhanning','FontSize',16)
figure,
for i=0:pi/20:pi
    lpf_hamming((i)*(20/pi)+1)=0.318+2*(0.206*cos(i)+0.045*cos(2*i)+0.012*cos(3*i));
end
plot(w,lpf_hamming,'b*')         % Hamming window
xlabel('Frequency (Hz)')
ylabel('Gain')
title('\it{Plotting LPF using hamming window}','FontSize',16)
text(2,0.75,'lpfhamming','FontSize',16)
figure,


%plotting HPF using different windows

for i=0:pi/20:pi
    hpf_rect((i)*(20/pi)+1)=0.682-2*(0.268*cos(i)+0.145*cos(2*i)+0.015*cos(3*i));
end
plot(w,hpf_rect,'r*')       % rectangular window
xlabel('Frequency (Hz)')
ylabel('Gain')
title('\it{Plotting HPF using rectangular window}','FontSize',16)
text(0.3,1.1,'hpfrect','FontSize',16)


figure,
for i=0:pi/20:pi
    hpf_hanning((i)*(20/pi)+1)=0.682-2*(0.201*cos(i)+0.036*cos(2*i));
end
plot(w,hpf_hanning,'g*')       % Hanning window
xlabel('Frequency (Hz)')
ylabel('Gain')
title('\it{Plotting HPF using hanning window}','FontSize',16)
text(0.5,1,' hpfhanning','FontSize',16)

figure,
for i=0:pi/20:pi
    hpf_hamming((i)*(20/pi)+1)=0.682-2*(0.206*cos(i)+0.045*cos(2*i)+0.012*cos(3*i));
end
plot(w, hpf_hamming,'b*')         % Hamming window
xlabel('Frequency (Hz)')
ylabel('Gain')
title('\it{Plotting HPF using hamming window}','FontSize',16)
text(0.5,1,'hpfhamming','FontSize',16)
figure,

%plotting BPF using different windows

for i=0:pi/20:pi
    bpf_rect((i)*(20/pi)+1)=0.318-2*(0.022*cos(i)+0.265*cos(2*i)+0.045*cos(3*i));
end
plot(w,bpf_rect,'r*')       % rectangular window
xlabel('Frequency (Hz)')
ylabel('Gain')
title('\it{Plotting BPF using rectangular window}','FontSize',16)
text(2,0.8,'bpfrect','FontSize',16)

figure,
for i=0:pi/20:pi
    bpf_hanning((i)*(20/pi)+1)=0.318-2*(0.0165*cos(i)+0.066*cos(2*i));
end
plot(w,bpf_hanning,'g*')       % Hanning window
xlabel('Frequency (Hz)')
ylabel('Gain')
title('\it{Plotting BPF using hanning window}','FontSize',16)
text(2.1,0.48,'bpfhanning','FontSize',16)
figure,
for i=0:pi/20:pi
    bpf_hamming((i)*(20/pi)+1)=0.318-2*(0.0169*cos(i)+0.082*cos(2*i)+0.0036*cos(3*i));
end
plot(w,bpf_hamming,'b*')         % Hamming window
xlabel('Frequency (Hz)')
ylabel('Gain')
title('\it{Plotting BPF using hamming window}','FontSize',16)
text(2.1,0.48,'bpfhamming','FontSize',16)
figure,

%plotting BRF using different windows

for i=0:pi/20:pi
    brf_rect((i)*(20/pi)+1)=0.318+2*(0.022*cos(i)+0.265*cos(2*i)+0.045*cos(3*i));
end
plot(w,brf_rect,'r*')       % rectangular window
xlabel('Frequency (Hz)')
ylabel('Gain')
title('\it{Plotting BRF using rectangular window}','FontSize',16)
text(2,0.8,'brfrect','FontSize',16)

figure,
for i=0:pi/20:pi
    brf_hanning((i)*(20/pi)+1)=0.318+2*(0.0165*cos(i)+0.066*cos(2*i));
end
plot(w,brf_hanning,'g*')       % Hanning window
xlabel('Frequency (Hz)')
ylabel('Gain')
title('\it{Plotting BRF using hanning window}','FontSize',16)
text(2.1,0.48,'brfhanning','FontSize',16)
figure,
for i=0:pi/20:pi
    brf_hamming((i)*(20/pi)+1)=0.318+2*(0.0169*cos(i)+0.082*cos(2*i)+0.0036*cos(3*i));
end
plot(w,brf_hamming,'b*')         % Hamming window
xlabel('Frequency (Hz)')
ylabel('Gain')
title('\it{Plotting BRF using hamming window}','FontSize',16)
text(2.1,0.48,' brfhamming','FontSize',16)

Contact us