Group 06 Expt 02 Report
Group 06 Expt 02 Report
25 August 2023
Group-6
Harshith Reddy(21EC10028)
NithyaSree(21EC10084)
AIM
● To observe whether pass band frequencies are attenuated and stop band
frequencies are attenuated by the designed filter
● To observe how our designed FIR filters are responding to the input signals
contaminated by noise
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 hd(n) by some suitably chosen window function w(n), yielding
h(n)=hd(n)w(n).
Window functions are always time limited. This means there is always a finite integer
Nw such that w(n)=0 for all |n|>Nw. The final windowed impulse response h(n)is thus
always time-limited, as needed for practical implementation. The window method always
designs a finite-impulse-response(FIR) digital filter (as opposed to an infinite-impulse-
response(IIR) digital filter).
By the dual of the convolution theorem, pointwise multiplication in the time domain
corresponds to convolution in the frequency domain. Thus, the designed filter h(n)has a
frequency response given by
H(ω)=Hd(ω)*W(ω)
where Hd=DTFT(hd)is the ideal frequency response and W=DTFT(w)is the window
transform. For the ideal lowpass filter, H(f)is a rectangular window in the frequency
domain. The frequency response H(f)is thus obtained by convolving the rectangular
window with the window transform W(f).
The pass-band gain is primarily the area under the main lobe of the window transform,
provided the main lobe fits inside the pass-band (i.e, The total lowpass bandwidth is greater
than or equal to the main-lobe width of W).The stop-band gain is given by an
1
integral over a portion of the side lobes of the window transform. Since side-lobes oscillate
about zero, a finite integral over them is normally much smaller than the side-lobes
themselves, due to adjacent side-lobe cancellation under the integral.
=0 ; otherwise
=0 ; otherwise
=0 ; otherwise
=0 ; otherwise
=0 ; otherwise
WINDOW FUNCTIONS
CODE:
N=7;
k=(N-1)/2;
for i=1:N
w(i)=1;%Rectangular Window
%w(i)=1-abs((i-k)/(k));%Triangular Window
%w(i)=0.5-0.5*cos(2*pi*i/(N-1));%Hanning Window
%w(i)=0.54-0.46*cos(2*pi*i/(N-1));%Hamming Window
%w(i)=0.42-0.5*cos(2*pi*i/(N-1))+0.08*cos(4*pi*i/(N-1));%Blackman Window
end
Wc=pi/6;
for i=1:k-1
hd(i)=(sin(Wc*(i-k))/(pi*(i-k)));
end
hd(k)=Wc/pi;
for i=k+1:N
hd(i)=(sin(Wc*(i-k))/(pi*(i-k)));
end
h=w.*hd;
omega=-1*pi:pi;
freqz(h);
2
*Taking cut-off frequency=π/6
● For N=8:
3
4
● For N=64
5
6
7
● For N=512
8
9
FILTERING & NOISE ADDITION
We will construct a signal consisting of 2 sinusoids with frequency π/2 and π/12:
x(n)=10*sin(2*(π/2)*n)+2*sin(2*(π/12)*n);
CODE:
%For input & output spectrum without Noise
N=7;
k=(N-1)/2;
%Rectangular Window Function
for i=1:N
w(i)=1;
end
%Triangular Window Function
for i=1:N
%w(i)=1-abs((i-k)/(k));
end
%Hanning Window Function
for i=1:N
%w(i)=0.5-0.5*cos(2*pi*i/(N-1));
end
%Hamming Window
for i=1:N
10
%w(i)=0.54-0.46*cos(2*pi*i/(N-1));
end
%Blackman Window
for i=1:N
%w(i)=0.42-0.5*cos(2*pi*i/(N-1))+0.08*cos(4*pi*i/(N-1));
end
Wc=pi/6;
for i=1:k-1
hd(i)=(sin(Wc*(i-k))/(pi*(i-k)));
end
hd(k)=Wc/pi;
for i=k+1:N
hd(i)=(sin(Wc*(i-k))/(pi*(i-k)));
end
h=w.*hd;
omega=-1*pi:pi;
%constructing two signals x1 & x2
Ndft = 2000;
fs = 4;
T = 1/fs;
t = 0:T:Ndft*T;
x = 10*sin(2*(pi/2)*t)+2*sin(2*(pi/12)*t);
% plotting the input signal
in = fft(x);
in = fftshift(in);
in = abs(in)/Ndft;
in(in<1e-6) = 0;
temp = linspace(-fs/2,fs/2,Ndft+1);
figure
plot(temp,in);
xlabel("frequency");
ylabel("DFT");
title("");
y = filtfilt(h,1,x);
y = fft(y);
y = fftshift(y);
m = abs(y)/Ndft;
y(m<1e-6) = 0;
%plotting the transformed signal
figure
plot(temp,m,'r');
xlabel("frequency");
ylabel("DFT");
title("Rectangular Window Output");
11
%For Input and Output Spectrum with Noise
N=511
k=(N-1)/2;
%Rectangular Window Function
for i=1:N
%w(i)=1;
end
%Triangular Window Function
for i=1:N
%w(i)=1-abs((i-k)/(k));
end
%Hanning Window Function
for i=1:N
%w(i)=0.5-0.5*cos(2*pi*i/(N-1));
end
%Hamming Window
for i=1:N
%w(i)=0.54-0.46*cos(2*pi*i/(N-1));
end
%Blackman Window
for i=1:N
w(i)=0.42-0.5*cos(2*pi*i/(N-1))+0.08*cos(4*pi*i/(N-1));
end
Wc=pi/6;
for i=1:k-1
hd(i)=(sin(Wc*(i-k))/(pi*(i-k)));
end
hd(k)=Wc/pi;
for i=k+1:N
hd(i)=(sin(Wc*(i-k))/(pi*(i-k)));
end
h=w.*hd;
omega=-1*pi:pi;
%constructing two signals x1 & x2
Ndft = 2000;
fs = 4;
T = 1/fs;
t = 0:T:Ndft*T;
x = 10*sin(2*(pi/2)*t)+2*sin(2*(pi/12)*t)+ (rand(1,Ndft+1));
% plotting the input signal
in = fft(x);
in = fftshift(in);
in = abs(in)/Ndft;
in(in<1e-6) = 0;
temp = linspace(-fs/2,fs/2,Ndft+1);
figure
plot(temp,in);
xlabel("frequency");
ylabel("DFT");
title("Input Spectrum with Noise");
y = filtfilt(h,1,x);
y = fft(y);
y = fftshift(y);
m = abs(y)/Ndft;
12
y(m<1e-6) = 0;
%plotting the transformed signal
figure
plot(temp,m,'r');
xlabel("frequency");
ylabel("DFT");
title("Blackman Window Output with Noise");
PLOTS:
● For N=8:
13
14
15
16
17
18
● For N=64:
19
20
21
22
23
24
● For N=512:
25
26
27
28
29
30
TABLES
● Table I
Rectangular Window
31
Triangular Window
Hanning Window
Hamming Window
Blackman Window
32
● Table II
Rectangular Window
Triangular Window
Hanning Window
Hamming Window
33
Blackman Window
DISCUSSION(Harshith Reddy)
Designing a low pass filter using the windowing method is a common and effective approach
in Digital Signal Processing (DSP). This technique involves the application of a window
function to the idealized frequency response of a low pass filter, resulting in a finite and
realizable filter that suits practical computational constraints.
2.WINDOWING METHOD
To address the challenges of implementing the ideal filter, the windowing method comes into play.
This method involves selecting a suitable window function, often with desirable characteristics such
as smooth tapering at the edges. The window function is multiplied with the ideal filter's frequency
response, confining it within a finite window and making it computationally feasible.
3. In a given window, it's evident that when we progressively increase the value of N, the number of
points in the N-point filter, the transition width of the low-pass filter proportionally diminishes. This
outcome signifies that immediately following the passband, the point at which the signal transition to
attenuation starts becomes notably more abrupt, leading to a substantially enhanced suppression of
unwanted frequencies. A narrower transition width is particularly advantageous since it closely
emulates a sharp stopband in the frequency response. This resemblance to a sharp stopband is crucial
34
in achieving effective filtration of undesired signals shortly after the desired signal range.
4. We can see from the plot of different window LPF frequency responses that as we
increase N values i.e np of discrete points, we get proper sinc function and hence
proper rectangular fourier transform.
Among all window designs, we can see that for stopband attenuation, Blackman
window works the best following hanning window.
We observe a special feature in triangular windows that it very easily loses its
ripples compared to other windows.
5. As the length N of the window increases, the width of the main lobe decreases,
which results in a decrease in the transition width between passband and
stopband. This relationship is given approximately by
N Δf = C, where Δf is the transition width and C is a parameter that depends on the
window.
6. The Hamming window strikes a balance between main lobe width and side lobe attenuation, while
the Hanning window excels in reducing side lobes, making it well-suited for applications where side
lobe suppression is a priority.
7. Signal-to-Noise Ratio (SNR) is a quantitative measure used to describe the relative strength of a
desired signal compared to the level of background noise present in a system or a signal. It provides
insight into how well a signal can be discerned from the noise that surrounds it. A higher SNR
indicates a stronger and more distinguishable signal, while a lower SNR suggests that the signal might
be challenging to detect or analyze due to the presence of substantial noise.
SNR(db) = 10.log(Psignal/Pnoise).
Psignal is the power of signal.
Pnoise is the power of noise.
35
DISCUSSION(NithyaSree)
● Since the frequency domain representation of an ideal low pass filter is bandlimited, its time
domain representation extends till infinity. Hence implementing it on a computer with finite
memory is impossible. Thus, we try to implement this ideal filter by limiting it within a
window. As visible in the observation, the more tapering or gradual the window is at the edges,
the lesser is the side lobes present in time domain representation.
● For a given window, we observe that as we increase the N of N-point filter, the transition width
of the low pass filter reduces i.e. just after the passband stops the rejection becomes highly
effective, lower transition width is better because that is a close replica of sharp stopband.
● We can see from the plot of different window LPF frequency responses that as we increase N
values i.e np of discrete points, we get proper sinc function and hence proper rectangular
fourier transform.
● Among all window designs, we can see that for stopband attenuation, Blackman window
works the best following hanning window. Triangular window doesn’t have good stopband
attenuation with only 60dB whereas Blackman has -160dB.
● We observe a special feature in triangular windows that it very easily loses its ripples
compared to other windows.
● The lower the order of filter, the lesser is the performance of noise removal. However, higher
order filters imply more additions and multiplications in time domain because the number of
h[i] is larger.
● At very high values, the filter performance almost saturates and is similar for most of the
windows.
36
● As the length N of the window increases, the width of the main lobe decreases, which results
in a decrease in the transition width between passband and stopband. This relationship is
given approximately by
N Δf = C, where Δf is the transition width and C is a parameter that depends on the window.
● The peak side-lobe amplitude of the window is determined by the shape of the window, and it
is essentially independent of the window length. From the result obtained we can observe that
as N changes the peak magnitude of the first side-lobe remains constant for a particular
window.
● Although Hamming and Hanning windows look similar, they show significant difference in
ripples and stopband attenuation. Hamming windows as can be read from literature has a
constant ripple envelope i.e. the peaks of the ripples are in astraight line however the ripple
envelope (peaks of ripple) move downwards linearly in Hanning window frequency
response.
● From the plots of input/output spectrum , we can observe that the sinusoidal component
above the cut-off frequency i.e. 3*Wc is removed at the output after passing through different
window LPF. The SNR remains almost the same, we have considered the magnitude of lower
frequency sin component of x(n) of magnitude 10 whereas higher frequency sin component
of magnitude 2. As the noise ranges below 1, the effect of it after passing through the filter
doesn’t alter much. i.e SNRi ≈ SNRo.
37