Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

DIGITAL SIGNAL PROCESSING

LABORATORY REPORT

EXPERIMENT 6
FIR FILTER DESIGN

PUNIT KUMAR OJHA


18EE01011
Problem Statement:
Given the following audio specifications:

Sampling rate = 16000 Hz, Crossover frequency = 2000 Hz, Transition band range = 1600 Hz,
Passband ripple = 0.1 dB, Stopband attenuation = 50 dB, Filter type = FIR

Determine the following for each filter:

1. Window function
2. Filter length
3. Cut-off frequency.

Theory:

The window method for digital filter design is fast, convenient, and robust, but generally
suboptimal. The window method consists of simply “windowing” a theoretically ideal filter
impulse response h(n) by some suitably chosen window function w(n), which gives us the
following equation:

ℎ (𝑛) = 𝑤(𝑛). ℎ(𝑛), 𝑛𝜖𝑍

Window functions are always time limited. For a finite integer 𝑁, w(n)=0 for all |n| > 𝑁.
Therefore, impulse response ℎ(𝑛) is always time limited as needed for practical
implementation. The window method always designs a finite impulse response digital filter.
When we approximate an ideal filter with a practical filter using the window method, there
occurs some error in our approximation. The peak approximation error depends on the window
type and is shown below for some of the most important window functions:

For practical purposes, we generally use either Hamming or Blackman window as they give
us attenuation greater than 50 dB in the stopband. However, the Blackman window leads to an
overdesigned filter. This is because for a given window length ‘M’, the Blackman gives a
wider main lobe which is not desired. So, if we want to use a Blackman window, we will have
to keep the window size (M) quite large as compared to the size of the Hamming window.
After going through the analysis of various windows, it seems reasonable to use Hamming
window for our filter designing task.
We can calculate the various parameters of the window depending upon the application
requirement. By using the transition band requirement of the filter, we can get rough
estimation about the size of the window.

Here, the transition band is 1600 Hz and sampling frequency is 16000 Hz.

1600
𝐻𝑒𝑛𝑐𝑒, ∆𝑓 = = 0.1
16000
3.3
W𝑖𝑛𝑑𝑜𝑤 𝐿𝑒𝑛𝑔𝑡ℎ, 𝑀 = = 33
∆f

Using the equation describing a Hamming window, we find the window as


𝜋𝑛
𝑤(𝑛) = 0.54 + 0.46 cos ( )
𝑀
The cut-off frequency of the ideal filter is given as:

ωs + ωp 16000 +(16000−1600)
ωc = = = 15.2 kHz
2 2

1. Use MATLAB to design and plot frequency responses for both filters.

%sampling rate
Fs = 16000;

%transition band range


Tbr = 1600;

%cross-over frequency
Fc = 2000;
n = -100:100;
w = 0:0.0001:pi;

%low-pass/high-pass filter
lpf = 0*w;
hpf = 0*w;

%creating window function


for i=1:length(w)
if (w(i) < 2*pi*Fc/Fs)
lpf(i)=1;
end

if(w(i) > 2*pi*Fc/Fs)


hpf(i)=1;
end
end

delta_f = Tbr/Fs;
len = 3.3/delta_f;
window = 0*n;

for i=1:length(n)
if(n(i) >= -len && n(i) <= len)
window(i)=0.54+0.46*cos(pi*n(i)/len);
end
end

%ideal lpf
ideall = 0*n;
for i=1:length(n)
ideall(i) = sum(lpf.*exp(1j*n(i)*w)*(w(2)-
w(1)))/(2*pi);
end

%real lpf
reall = ideall.*window;
reall = real(reall);
padding = zeros(1, round(len));
h1 = horzcat(padding, reall);
h1 = h1(1:length(h1)-33);
reallpf = fft(h1);
Gain1 = abs(reallpf);
dB1 = 10*log(Gain1);
r1 = linspace(-pi,pi,length(dB1));
f1 = plot(r1.*Fs./2./pi,dB1);
axis tight;
grid on;
ylabel('Magnitude Frequency Response')
xlabel('Frequency (in Hz)')
hold on;

idealh = 0*n;
for i=1:length(n)
idealh(i) = sum(hpf.*exp(1j*n(i)*w)*(w(2)-
w(1)))/(2*pi);
end

realh = idealh.*window;
realh = real(realh);
padding = zeros(1,round(len));
h2 = horzcat(padding, realh);
h2 = h2(1:length(h2)-33);
realhpf = fft(h2);
Gain2 = abs(realhpf);
dB2 = 10*log(Gain2);

r2 = linspace(-pi,pi,length(dB2));
f2 = plot(r2.*Fs./2./pi,dB2);

legend([f1, f2], ["hpf", "lpf"]);

You might also like