Professional Documents
Culture Documents
Faculty of Engineering
Laboratory Report Cover Sheet
Students must complete all details except the faculty use part.
Please submit all reports to your subject supervisor or the office of the concerned faculty.
Laboratory Title: Digital Filter Design and FIR Filtering of Sinusoidal Waveforms.
Experiment Number: 06 Due Date: _10-04-20 Semester: Fall 19-20
Subject Code: EEE_____ Subject Name: DIGITAL SIGNAL PROCESSING Section: _D__
Course Instructor: TAHIA FAHRIN KARIM Degree Program: EEE
Faculty comments___________________________________________________________________________
___________________________________________________________________________________________
Title: Digital Filter Design and FIR Filtering of Sinusoidal Waveforms.
Introduction:
An analog signal may be processed by a digital filter by first being digitized and
represented as a sequence of numbers, then manipulated mathematically, and then
reconstructed as a new analog signal. Digital filters may be more expensive due to
complexity but they make many designs practical, which are impossible for analog filters.
Digital filters are now common in everyday electronics such as radios, cell phones, and
stereo receivers. The goal of this lab is to learn how to-
7. Design few digital filter techniques.
8. implement FIR filters in MATLABTM,
9. study the response of FIR filters to inputs such as complex exponentials.
10. use FIR filters to study properties such as linearity and time-invariance.
y [ n]= ∑ bk x [n− k ]
k= 0 … … … (1)
An FIR filter is a discrete-time system that converts an input signal x(n) into an output
signal y(n) by means of the weighted summation. Equation (1) gives a rule for computing
the nth value of the output sequence from certain values of the input sequence. The filter
coefficients {bk} are constants that define the filter’s behavior. As an example, a system can
be considered for which the output values are given by
1 1 1 1
y (n)= 3 x (n)+ 3 x ( n− 1)+ 3 x (n− 2)= 3 [ x (n)+ x (n− 1)+ x (n− 2)] … … … (2)
This equation states that the nth value of the output sequence is the average of the n th value
of the input sequence x(n) and the two preceding values, x(n - 1) and x(n - 2). For this
example the bk’s are b0 = 1/3, b1 =1/3, and b2 = 1/3.
In our theory classes we examined filters that average input samples over a certain interval.
These filters are called “running average” filters or “averagers” and they have the following
form:
M
y (n)=
1
∑ bk x ( n− k )
M +1 k = 0 ………(3)
The frequency response for the three-point running average operator is given by:
H (e j ω)= 2cosω+1 e− j ω
3
A digital filter can be described as a moving average filter:-
y(n) = b0x(n) + b1x(n-1) + b2x(n-2) + b3x(n-3) + ..... - a1y(n-1) - a2y(n-2) + a3y(n-3) - .....
or,
b0x(n) + b1x(n-1) + b2x(n-2) + b3x(n-3) +..... - y(n) - a1y(n-1) - a2y(n-2) + a3y(n-3) - ..... = 0
[x ( n) ]
x ( n− 1)
[ ]
y ( n)
y ( n− 1)
[b0 b1 b2 b3 b4 ...]
x ( n− 2)
− [1 a1 a2 y ( n− 2) = 0
a3 a4 ...] y ( n− 3)
x ( n− 3) y ( n− 4)
x ( n− 4) ...
...
Which can be again re-written as:
B*X - A*Y=0 … … … (4)
And a moving average filter with time window length of 4 is defined as:
MATLABTM has a built-in function for implementing the operation in (1) to (4); namely,
the function filter( )(see in the Appendix of this lab sheet), which implements an operation
called convolution.
y=filter(B,A,x)
[Here A & B are coefficients of the filter in equation 1, x is the input signal and y is
the output of the filter]
After implementing coefficients A and B to the filter we usually test the filter by using a
signal generator and oscilloscope. Command freqz() in MATLAB do the oscilloscope and
signal generator job together.
[h,w]=freqz(B,A,n,Fs)
Where; A and B is the same in Equation 1, n is number of points we want to see the
frequency response graph, Fs is sampling frequency and h is the frequency response. Note
that if we drop the n the default is 512 and if drop Fs the default is pi=3.14.
In addition, this lab will introduce examples to show how a filter reacts to different
frequency components in the input.
Apparatus:
%(A)
bb = 1/3*ones(1,3);
ww = -pi:(pi/200):pi;
H = freqz( bb, 1, ww );
subplot(2,1,1)
plot(ww, abs(H) ) %<-- Magnitude
title('Magnitude Part');
subplot(2,1,2)
plot(ww, angle(H) ); %<-- Phase
title('Angle Part');
%B(1)
A= [1];
B=0.25*[1 1 1 1];
[h1,w1]=freqz(B,A,10)
plot(w1,abs(h1),'r+:');
title('Magnitude Part for 4 point averaging filter');
yy = filter(bb, 1, x); %<--Compute the output
%B(2)
A= [1];
B=0.025*ones(40,1);
[h2,w2]=freqz(B,A);
plot(w2,abs(h2),'r+:');
title('Magnitude Part for 40 point averaging filter');
%c
bb = [1, -1]; %-- Filter Coefficients
ww = -pi:(pi/100):pi;
H = freqz(bb, 1, ww);
plot(ww, abs(H))
title('Magnitude Part');
%D(1)
% This program will show the usages of digital filter
% generate three cosine signals and add them together
time=[0:0.02:20]; %Ts=0.02>>Fs=1/0.02=50 Hz
signal1=cos(2*pi*0.1*time)
signal2=0.25*cos(2*pi*0.5*time)
signal3=.1*cos(2*pi*2*time);
%0.1,0.5 and 2 Hz components
original_signal=signal1+signal2+signal3
subplot(221)
plot(time,original_signal)
title('original signal')
% generate random noise and addeded with the signal
noise=randn(1,1001);
x=noise+original_signal;
subplot(222)
plot(time,x)
title('signal with noise added')
%D(2)
A= [1];
B=0.25*[1 1 1 1];
y=filter(B,A,x);
subplot(223)
plot(time,y)
title('Filtered by 4-point averaging filter')
%D(3)
A= [1];
B=0.025*[ones(1,40)];
y=filter(B,A,x);
subplot(224)
plot(time,y)
title('Filtered by 40-point averaging filter')
Results and Discussion:
Overall, throughout the laboratory experiment, we completed our objective of understanding Digital
Filter Designing and FIR Filtering of Sinusoidal Waveforms. We also discussed some important
properties of FIR filter deigning. Here we had deigned a filter that filtered a noise sinusoidal signal,
for that we generated a signal and add some noise by rand () built in function in MATLAB after that
we passed this signal through our deigned FIR filter and got almost the same signal as input was.
When we did this in MATLAB, we took some precautions by taking this command close all or clc
we make sure any previous command doesn’t interrupt with the new. As we got the result as same as
what we expected therefor our excrement was successful.
Reference(s):