You are on page 1of 12

Digital Signal Processing

EEE-324

Lab Project

Name MUHAMMAD SOHAIB

Registration Number FA18-BCE-070

Class BEE(-6C)

Instructor’s Name Sir. Mubeen Sabir

Lab Assessment

Post Lab Total


Pre-
In-Lab Data Data Writing
Lab
Presentation Analysis Style
Lab Project
Question:

Design a digital FIR low pass filter (with the following specifications):

𝑤𝑝 = 0.2𝜋, 𝑅𝑝 = 0.25 𝑑𝐵, 𝑤𝑠 = 0.3𝜋, 𝐴𝑠 = 50 𝑑𝐵

Choose an appropriate window function from Table 7.1 of book “Digital


signal processing using MATLAB” 3rd edition by Vinay K. Ingle and John G.
Proakis.

(i) Plot the impulse response and provide a plot of the frequency
response of the designed filter
(ii) Chose an input signal of your choice (plot it as well) and show
filtered signal. Do this for both: first by adjusting frequency of input
signal within pass band and then adjusting it into stop band
(iii) show all the steps “how to perform part (ii)” using code composer
studio

Objective:

In this lab we aim to learn regarding:

• Designing digital low pass FIR filter


• Designing passband and stopband filter
• Working on code composer studio

Introduction:

Low pass filter:


A low-pass filter (LPF) is a filter that passes signals with a frequency lower than a selected
cutoff frequency and attenuates signals with frequencies higher than the cutoff frequency. The
exact frequency response of the filter depends on the filter design.

FIR low pass filter:

It removes high frequency signal components from the input using an FIR low pass filter. The
example demonstrates how to configure an FIR filter and then pass data through it in a block-
byblock fashion.

• In signal processing, a finite impulse response (FIR) filter is a filter whose impulse
response (or response to any finite length input) is of finite duration, because it settles to
zero in finite time. This contrasts with infinite impulse response (IIR) filters, which may
have internal feedback and may continue to respond indefinitely (usually decaying).
• The impulse response of an Nth-order discrete-time FIR filter lasts exactly N + 1
samples (from first nonzero element through last nonzero element) before it then settles
to zero.
• FIR filters can be:
 Discrete time or digital 
Continuous time or analog.
• The window design method is also advantageous for creating efficient half-band filters,
because the corresponding sinc function is zero at every other sample point (except the
center one).
• The product with the window function does not alter the zeros, so almost half of the
coefficients of the final impulse response are zero.
• An appropriate implementation of the FIR calculations can exploit that property to double
the filter's efficiency.
PASS BAND AND STOP BAND FILTERS:
A passband is the range of frequencies or wavelengths that can pass through a filter. For
example, a radio receiver contains a bandpass filter to select the frequency of the desired radio
signal out of all the radio waves picked up by its antenna. The passband of a receiver is the range
of frequencies it can receive when it is tuned into the desired frequency (channel).
A stopband is a band of frequencies, between specified limits, through which a circuit, such as a
filter or telephone circuit, does not allow signals to pass, or the attenuation is above the required
stopband attenuation level.
Code Composer Studio:

Code Composer Studio software is an integrated development environment (IDE) that supports
TI's microcontroller (MCU) and embedded processor portfolios. Code Composer Studio software
comprises a suite of tools used to develop and debug embedded applications. The software
includes an optimizing C/C++ compiler, source code editor, project build environment,
debugger, profiler and many other features. The intuitive IDE provides a single-user interface
that takes you through each step of the application development flow. Familiar tools and
interfaces let you get started faster than ever before. Code Composer Studio software combines
the advantages of the Eclipse software framework with advanced embedded-debug capabilities
from TI resulting in a compelling feature-rich development environment for embedded
developers.

Task 1:

Plot the impulse response and provide a plot of the frequency response of the
designed filter.
Code:

wp= 0.2*pi; ws=


0.3*pi;
Rp= 0.25; %Actual Passband Ripple As=
50; %Min stopband attenuation
delW= ws-wp;
M= (12*pi/delW)+1; %Approximate value used
n= [0:1:M-1]; width= (ws+wp)/2; hd=
ideal_lp(width, M); w_black= (blackman(M))';
h= hd.*w_black;
[db, mag, pha, grd, w]= freqz_m(h, [1]);
delta_w= 2*pi/1000; subplot(4,1,1)
plot(w/pi, db);grid title('Magnitude
Respone in dB') axis ([0 1 -100
10]) subplot(4,1,2)
stem(n,w_black);grid
title('Blackman Window') axis ([0
M-1 0 1.1]) subplot(4,1,3)
stem(n,hd);grid title('Ideal Impulse
Response') axis ([0 M-1 -0.1 0.3])
subplot(4,1,4) stem(n,h);grid
title('Actual Impulse Response using Blackman window')
axis ([0 M-1 -0.1 0.3])

figure(); t=0:1:100;
y1=3*sin(0.18*pi.*t);
y2=3*sin(0.8*pi.*t);
x=filter(h,1,y1);
subplot(2,1,1)
stem(t,y1,'-')
legend('Original Signal')
subplot(2,1,2)
stem(t,x,'*')
legend('Filtered Signal')

figure(); t=0:1:100;
y1=3*sin(0.18*pi.*t);
y2=3*sin(0.8*pi.*t);
x=filter(h,1,y2);
subplot(2,1,1)
stem(t,y2,'-')
legend('Original Signal')
subplot(2,1,2)
stem(t,x,'*')
legend('Filtered Signal')

Freqz_m. m file code:

function [db, mag, pha, grd, w]= freqz_m(b,a)


[H,w]=freqz(b,a,1000,'whole');
H=(H(1:1:501))'; w=(w(1:1:501))';
mag= abs(H); db=
20*log10((mag+eps)/max(mag));
pha= angle(H);
grd= grpdelay(b,a,w);

ideal_lp.m file code:


function hd= ideal_lp(width, M)
alpha= (M-1)/2; n= [0:1:(M-1)];
m= n-alpha+eps;
hd= sin(width*m) ./ (pi*m);

PLOT:

Figure 1
Figure 2

Figure 3
Task (ii):
Figure 4

Figure 5
Task (iii):
Show all the steps “how to perform part (ii)” using code composer studio?

CODE:
#include<stdio.h>; int

m,n,x[1000],h[1000],y[1000],i,j,k,x2[1000],a[1000];

void main()

DSK6713_init(); //header file

printf ("Enter the length of first sequence\n");

scanf("%d",&m);

printf("Enter the length of second sequence\n");

scanf("%d",&n);

printf("Enter the first sequence\n");

for(i=0;i<m;i++)

scanf("%d",&x[i]);

printf("Enter the second sequence\n");

for(j=0;j<n;j++) scanf("%d",&h[j]); if((m-n)!=0)

//If length of both sequence is not equal

if(m>n)

for(i-n;i<m;i++)

h[i]=0;

n=m;

for(i-m;i<n;i++)
{

x[i]=0;

m=n;}

} y[0]=0;

a[0]=h[0];

for(j-1;j<n;j++)

a[j]=h[n-j];

//Circular Convolution

for(i=0;i<n;i++)

y[0]+=x[i]*a[i];

for(k=1;k<n;k++)

y[k]=0;

//Circular Shift//

for(j=1;j<n;j++)

x2[j]=a[j-1];

x2[0]=a[n-1];

for(i=0;i<n;i++)

a[i]=x2[i]; y[k]+=x[i]*x2[i]

}}//Display Result
printf("Circular Convolution is\n");

for(i=0;i<n;i++)

printf("%d \t",y[i]);

Loading a project in Code Composer Studio:


● First Open Code Composer Studio from start menu. When you initially start CCS, the
DSK is not connected.
● Go to the debug menu and click connect or Press Alt+Ctrl+C from your keyboard.
The DSK will get connected. If not, then check cables and run the diagnostic utility
located at your Desktop. The test is run by pressing start button, program will test
each module of DSK 6713 till all tests are passed
● Then right click on the projects and open a new Project then name the project file.
● Go to file menu and click on Load Program
● Double click on the debug folder
● Double click on ‘project name. Out’ to load this program
● Go to the debug menu and click on Run to run the code on code composer studio.
● Now to stop executing a program again go to the debug menu and click on Halt it will
stop executing the code in CCS.
● If you want to view the C code go to the Projects, then project.pjt then the Source file
and double click on project name.c it will open the C code of the led.
● If you want to view the header files of the C code go to Projects, then to project.pjt
file then Include file and double click the file you want to see.
CONCLUSION

In this Project we design a digital FIR low pass filter. This filter Removes high frequency signal
components from the input using an FIR lowpass filter. The example demonstrates how to configure an
FIR filter and then pass data through it in a block-by-block fashion.

FIR filters are widely used due to the powerful design algorithms that exist for them, their inherent
stability when implemented in non-recursive form, the ease with which one can attain linear phase, their
simple extensibility to multirate cases, and the ample hardware support that exists for them among other
reasons.

In task 1, the window method of FIR filter design (also called the Fourier series method) begins with our
deciding what frequency response we want for our low-pass filter. We can start by considering a
continuous low-pass filter, and simulating that filter with a digital filter. We'll define the continuous
frequency response H(f) to be ideal, i.e., a low-pass filter with unity gain at low frequencies and zero gain
(infinite attenuation) beyond some cutoff frequency.

In task 2, we adjust input signal within pass band and then adjusting it into stop band. A passband is the
range of frequencies or wavelengths that can pass through a filter. For example, a radio receiver
contains a bandpass filter to select the frequency of the desired radio signal out of all the radio waves
picked up by its antenna. The passband of a receiver is the range of frequencies it can receive when it is
tuned into the desired frequency (channel).

A stopband is a band of frequencies, between specified limits, through which a circuit, such as a filter or
telephone circuit, does not allow signals to pass, or the attenuation is above the required stopband
attenuation level.

In task 3, we just show all the steps “how to perform part (ii)” using code composer studio

You might also like