You are on page 1of 57

DSP LAB RECORD

CONTENTS

1. INTRODUCTION TO TMS320C6713 DSK ........................................................... 2


2. FEATURES OF C6713 DSK................................................................................... 4
3. INTRODUCTION TO CODE COMPOSER STUDIO ............................................ 6
4. LINEAR & CIRCULAR CONVOLUTION .......................................................... 11
5. SINE WAVE AND SQUARE WAVE ................................................................... 15
6. TMS320C6713 DSK CODEC (TLV320AIC23) CONFIGURATION USING -
BOARD SUPPORT LIBRARY .................................................................................. 19
7. SINE WAVE USING DSK6713 ............................................................................ 21
8. ADVANCED DISCRETE TIME FILTER ( FIR ) ................................................. 23
9. AM FM & PWM USING MATLAB ..................................................................... 27
10. CONVOLUTION .................................................................................................. 31
11. FIR FILTERS......................................................................................................... 33
12. BUTTERWORTH IIR FILTERS .......................................................................... 36
13. CHEBYSHEV TYPE 1 FILTERS ......................................................................... 44
14. CHEBYSHEV TYPE 2 FILTERS ......................................................................... 50

SCT COLLEGE OF ENGINEERING Page 1


DSP LAB RECORD

INTRODUCTION TO TMS320C6713 DSK

The C6713 DSK builds on Ti‟s industry-leading line of low cost, easy-to-use DSP
Starter Kit (DSK) development boards. The high performance board features the
TMS320C6713 floating point DSP, capable of performing 1350 million floating point
operations per second(MFLOPS) , the C6713 DSP makes the C6713 DSK the most
powerful DSK development board.

The DSK is USB port interfaced platform that allows efficiently develop and testing
applications for C6713. The DSK consists of a C6713-based printed circuit board that
will serve as a hardware reference design for TI‟s customer‟s product s. With the
extensive host PC and target DSP software support, including bundled TI tools, the
DSK provides ease-of -use and capabilities that are attractive to DSP engineers.

The C6713 DSK has a TMS 320C6713 DSP onboard that allows full speed
verification of the Code Composer Studio. The C6713 DSK provides

 A USB interface
 SDRAM and ROM
 An analog interface circuit for data conversion (AIC)
 An I/O port
 Embedded JTAG emulation support

Connectors on the C6713 DSK provide DSP external memory interface (EMIF) and
peripheral signals that enable its functionality to be expanded with custom or third
party daughter boards.

The DSK provides a C6713 hardware reference design that can assist in the
development of C6713 based products. In addition to providing a reference for
interfacing the DSP to various types of memories and peripheral interfaces, the design
also address power, clock, JTAG and parallel peripheral interfaces.

SCT COLLEGE OF ENGINEERING Page 2


DSP LAB RECORD

The C6713 DSK includes a stereo codec. The analog interface circuit (AIC) has the
following characteristics:

High performance Stereo Codec

 90 dB SNR Multibit Sigma –Delta ADC (A- weighted at 48kHz)


 100 dB SNR Multibit Sigma Delta DAC (A- weighted at 48kHz)
 1.42 V – 3.6 V Core Digital Supply: compatible With TI C54x DSP Core
Voltages
 2.7 V – 3.6 V Buffer and Analog Supply: Compatible with both TI C54x DSP
Buffer Voltages
 8 kHz – 96 KHz Sampling Frequency Support

Software Control via TI McBSP –Compatible Multiprotocol Serial Port

 12 C compatible and SPI – compatible Serial Port Protocols


 Glueless Interface to TI McBSP's

Audio- Data Input/Output via TI McBSP- Compatible Programmable Audio Interface

 12 S- compatible interface requiring only one McBSP for both ADC and DAC
 Standard 12S MSB or LSB justified – Data Transfers
 16/20/24/32- Bit Word Length

SCT COLLEGE OF ENGINEERING Page 3


DSP LAB RECORD

FEATURES OF C6713 DSK

The 6713 DSK is a low-cost standalone development platform that enables customers
to evaluate and develop applications for the TI C67XX DSP family. The DSP also
serves as a hardware reference design for the TMS320C6713 DSP. Schematics, logic
equations and application notes are available to ease hardware development and
reduce time to market.

The DSK uses the 32bit EMIF for the SDRAM (CE0) and daughtercard expansion
interface ( CE2 and CE3). The Flash is attached to CE1 of the EMIF in 8-bit mode.

An on-board AIC23 codec allows the DSP to transmit and receive analog signals.
McBSP0 is used for the codec control interface and McBSP1 is used for data. Analog
audio I/O is done through four 3.5mm audio jacks that correspond to microphone
input, line input, line output and headphone output. The codec can select the
microphone or line input as the active input. The analog output is driven to both the
line out (fixed gain) and headphone (adjustable gain) connectors. McBSP1 can be re-
routed to the expansion connectors in software.

A programmable logic device called CPLD is used to implement glue logic that ties
the board components together. The CPLD has a register based user interface the lets
the user configure the board by reading and writing to the CPLD registers. The
registers reside at the midpoint of CE1.

The DSK include 4 LEDs and 4 DIP switches as a simple way to provide the user
with interactive feedback. Both are accessed by the reading and writing to the CPLD
register.

An included 5V external power supply is used to power is used to power the board.
On-board voltage regulators provide 1.26V DSP core voltage, 3.3V digital and 3.3V
analog voltages. A voltage supervisor monitors the internally generated voltage and
will hold the board in reset until the supplies are within operating specifications and
the reset button is released. If desired, JP1 and JP2 can be used as power test points
the core and I/O power supplies.

Code Composer communicates with the DSP through an embedded JTAG emulator
with a USB host interface. The DSK can also be used with an external emulator
through the external JTAG connector.

SCT COLLEGE OF ENGINEERING Page 4


DSP LAB RECORD

SCT COLLEGE OF ENGINEERING Page 5


DSP LAB RECORD

INTRODUCTION TO CODE COMPOSER STUDIO

Code Composer is the DSP industry‟s first fully integrated development environment
(IDE) with DSP- specific functionality. With a familiar environment like MS- based
C++, Code composer lets you edit, build, debug, profile and manage projects from a
single unified environment. Other unique features include graphical signal analysis,
injection/extraction of data signals via file I/O, multi-processor debugging, automated
testing and customization via a C-interpretive scripting languages and much more.

CODE COMPOSER FEATURE INCLUDE:

 IDE
 Debug IDE
 Advanced watch windows
 Integrated editor
 File I/O, probe points and graphical algorithm scope probes
 Advanced graphical signal analysis
 Interactive profiling
 Automated testing and customization via scripting
 Visual project management system
 Compile in the background while editing and debugging
 Multi-processor debugging
 Help on the target DSP

SCT COLLEGE OF ENGINEERING Page 6


DSP LAB RECORD

PROCEDURE TO WORK ON CODE COMPOSER STUDIO

1. To create a new project

Project  New

2. To create source file

File  New  Source file


Save the source file in project folder
File  Save

SCT COLLEGE OF ENGINEERING Page 7


DSP LAB RECORD

3. To add source file to the project

Project  Add files to project  <source file>

4. To add rts6700.lib & hello.cmd

Project  Add files to project  rts6700.lib


Path : C:\CCstudio\c6000\lib\rts6700.lib
Note: Select Object & library files (*.o, *.l) in Type of file

Project  Add files to project  hello.cmd


Path: C:\CCstudio\tutorial\dsk6713\hello1\hello.cmd
Note: Select Linker command file (*.cmd) in Type of file

SCT COLLEGE OF ENGINEERING Page 8


DSP LAB RECORD

5. To compile
Project  Compile file ( or use icon or ctrl+F7 )

6. To build or link

Project build (or use F7 )


(which will create a .out file in project folder)

7. To load the program:

File  Load Program  <select the .out file in debug folder in project folder>

8. To run the program

Debug  Run ( or use icon or F5)

SCT COLLEGE OF ENGINEERING Page 9


DSP LAB RECORD

To perform Single Step Debugging:

1. Keep the cursor on the line from point to start single step debugging.
To set the break point click icon from tool bar menu.

2. Load the .out file onto the target

3. Go to View and select Watch window

4. Select Debug  Run (F5)

5. Execution should halt at break point

6. Now press F10. See the changes happening the watch window

7. Similarly go to view & select CPU registers to view the changes happening in
CPU registers.

8. Repeat steps 2 to 6

SCT COLLEGE OF ENGINEERING Page 10


DSP LAB RECORD

Experiment no 1

LINEAR & CIRCULAR CONVOLUTION

AIM

To implement circular and linear convolution using Code Composer Studio.

PROCEDURE

1. Open Code Composer Setup and select C6713 simulator, click save and quit
2. Start a new project using „Project  New‟ pull down menu, save it in a
separate directory (D:\My projects) with file name lconv.pjt
3. Create a new source file using File  New  Source file menu and save it in
the project folder(linear.c)
4. Add the source file (linear.c) to the project
Project  Add files to Project  Select linear.c
5. Add the linker command file hello.cmd
Project  Add files to Project
(path: C:\CCstudio\tutorial\dsk6713\hello\hello.cmd)
6. Add the run time support library file rts6700.lib
Project  Add files to Project
(path: C\CCStudio\cgtools\lib\rts6700.lib)
7. Compile the program using „project  Compile‟ menu or by Ctrl+F7
8. Build the program using „project  Build‟ menu or by F7
9. Load the linear.out file (from project folder lcconv\Debug) using
File  Load Program
10. Run the program using „Debug  Run‟ or F5
11. To view the output graphically
Select View  Graph  Time and Frequency
12. Repeat the steps 2 to 11 for circular convolution

PROGRAM

Linear Convolution
#include<stdio.h>
#define LENGTH1 6
#define LENGTH2 4
int x[LENGTH1+LENGTH2-1]={1,2,3,4,5,6,0,0,0};

SCT COLLEGE OF ENGINEERING Page 11


DSP LAB RECORD

int h[LENGTH1+LENGTH2-1]={1,2,3,4,0,0,0,0,0};
int y[LENGTH1+LENGTH2-1];
main()
{
int i=0,j;
for(i=0;i<LENGTH1 + LENGTH2-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
for(i=0;i<LENGTH1 + LENGTH2-1;i++)
printf("%d\n",y[i]);
}

RESULT

The convoluted sequence is obtained as

1 4 10 20 30 40 43 38 24

SCT COLLEGE OF ENGINEERING Page 12


DSP LAB RECORD

Circular convolution
#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf("Enter the length of 1st sequence\n");
scanf("%d",&m);
printf("Enter the length of 2nd sequence\n");
scanf("%d",&n);
printf("Enter the 1st sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("Enter the 2nd sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0)
{
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];
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];

SCT COLLEGE OF ENGINEERING Page 13


DSP LAB RECORD

for(k=1;k<n;k++)
{
y[k]=0;
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];
}
}
printf("The circular convolution is \n");
for(i=0;i<n;i++)
printf("%d\t",y[i]);
}

RESULT

Enter the length of 1st sequence 4

Enter the length of 2nd sequence 4

Enter the 1st sequence 3 2 1 4

Enter the 2nd sequence 1 2 3 4

The circular convolution is 22 24 30 24

SCT COLLEGE OF ENGINEERING Page 14


DSP LAB RECORD

Experiment 2

SINE WAVE AND SQUARE WAVE

AIM

To generate a sine wave and square wave using C6713 simulator

PROCEDURE

1. Open Code Composer Setup and select C6713 simulator, click save and quit
2. Start a new project using „Project  New‟ pull down menu, save it in a
separate directory (D:\My projects) with file name sinewave.pjt
3. Create a new source file using File  New  Source file menu and save it in
the project folder(sinewave.c)
4. Add the source file (sinewave.c) to the project
Project  Add files to Project  Select sinewave.c
5. Add the linker command file hello.cmd
Project  Add files to Project
(path: C:\CCstudio\tutorial\dsk6713\hello\hello.cmd)
6. Add the run time support library file rts6700.lib
Project  Add files to Project
(path: C\CCStudio\cgtools\lib\rts6700.lib)
7. Compile the program using „project  Compile‟ menu or by Ctrl+F7
8. Build the program using „project  Build‟ menu or by F7
9. Load the sinewave.out file (from project folder lcconv\Debug) using
File  Load Program
10. Run the program using „Debug  Run‟ or F5
11. To view the output graphically
Select View  Graph  Time and Frequency
12. Repeat the steps 2 to 11 for square wave

PROGRAM

Sine Wave

#include <stdio.h>
#include <math.h>
float a[500];
void main()
{
int i=0;
for(i=0;i<500;i++)

SCT COLLEGE OF ENGINEERING Page 15


DSP LAB RECORD

{
a[i]=sin(2*3.14*10000*i);
}
}

Square wave

#include <stdio.h>
#include <math.h>
int a[1000];
void main()
{
int i,j=0;
int b=5;
for(i=0;i<10;i++)
{ for (j=0;j<=50;j++)
{
a[(50*i)+j]=b;
}
b=b*(-1) ;
}
}

SCT COLLEGE OF ENGINEERING Page 16


DSP LAB RECORD

RESULT

The sine wave and square wave has been obtained.

Sine Wave

SCT COLLEGE OF ENGINEERING Page 17


DSP LAB RECORD

Square Wave:

SCT COLLEGE OF ENGINEERING Page 18


DSP LAB RECORD

Experiment 3

TMS320C6713 DSK CODEC (TLV320AIC23)


CONFIGURATION USING BOARD SUPPORT LIBRARY

AIM

To configure the codec TLV320AIC23 for a talk through program using the board
support library

PREREQUISITES

TMS320C6713 DSP starter kit, PC with Code Composer Studio, CRO, Audio source,
Speakers, Signal Generator.

PROCEDURE

1. Connect Speaker to the LINE OUT socket.


2. Connect the line out from the PC to the LINE IN socket.
3. Now switch ON the DSK and bring up Code Composer Studio on PC
4. Create a new project with name codec.pjt
5. From File menu  New  DSP/BIOS Configuration  Select dsk6713.cdb
and save it as “xyz.cdb”
6. Add xyz.cdb to the current project
7. Create a new source file and save it as codec.c
8. Add the source file codec.c to the project
9. Add the library file “dsk6713bsl.lib” to the project
( Path: C:\CCStudio\C6000\dsk6713\lib\dsk6713bsl.lib)
10. Copy files “dsk6713.h” and “dsk6713_aic23.h” to the Project folder
11. Build (F7) and load the program to the DSP Chip ( File  Load Program)
12. Run the program (F5)
13. Give an audio output from the PC and notice the output in the speaker
14. Vary the sampling frequency using the DSK6713_AIC23_SetFreq

PROGRAM

Codec.c

#include"xyzcfg.h"
#include"dsk6713.h"
#include"dsk6713_aic23.h"

SCT COLLEGE OF ENGINEERING Page 19


DSP LAB RECORD

DSK6713_AIC23_Config config= DSK6713_AIC23_DEFAULTCONFIG;


void main()
{
DSK6713_AIC23_CodecHandle hCodec;
int l_input,r_input,l_output,r_output;
DSK6713_init();
hCodec=DSK6713_AIC23_openCodec(0,&config);
DSK6713_AIC23_setFreq= DSK6713_AIC23_FREQ_48KHZ;
while(1)
{
while(!DSK6713_AIC23_read(hCodec,&l_input));
while(!DSK6713_AIC23_read(hCodec,&r_input));
r_output = r_input;
l_output = l_input;
while(!DSK6713_AIC23_write(hCodec,l_output));
while(!DSK6713_AIC23_write(hCodec,r_output));
}
DSK6713_AIC23_closeCodec(hCodec);
}

RESULT

The Codec TMS320AIC23 Successfully configured using the board support library
and output is verified.

SCT COLLEGE OF ENGINEERING Page 20


DSP LAB RECORD

Experiment 4

SINE WAVE USING DSK6713

AIM

To generate a real time sine wave using TMS320C6713 DSK

PROCEDURE

1. Connect Speaker to the LINE OUT socket.


2. Now switch ON the DSK and bring up Code Composer Studio on PC
3. Create a new project with name sinewave.pjt
4. From File menu  New  DSP/BIOS Configuration  Select dsk6713.cdb
and save it as “xyz.cdb”
5. Add xyz.cdb to the current project
6. Create a new source file and save it as sinewave.c
7. Add the source file sinewave.c to the project
8. Add the library file “dsk6713bsl.lib” to the project
( Path: C:\CCStudio\C6000\dsk6713\lib\dsk6713bsl.lib)
9. Copy files “dsk6713.h” and “dsk6713_aic23.h” to the Project folder
10. Build (F7) and load the program to the DSP Chip ( File  Load Program)
11. Run the program (F5)
12. Give an audio output from the PC and notice the output in the speaker

PROGRAM

Sinewave.c
#include "xyzcfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include <stdio.h>
#include <math.h>
float a[500],b;
DSK6713_AIC23_Config config= DSK6713_AIC23_DEFAULTCONFIG;
void main()
{

SCT COLLEGE OF ENGINEERING Page 21


DSP LAB RECORD

int i=0;
DSK6713_AIC23_CodecHandle hCodec;
Int l_output,r_output;
DSK6713_init();
hCodec=DSK6713_AIC23_openCodec(0,&config);
DSK6713_AIC23_setFreq=DSK6713_AIC23_FREQ_48KHZ;
for(i=0;i<500;i++)
{
a[i]=sin(2*3.14*10000*i);
}
while(1)
{
for(i=0;i<500;i++)
{
b=400*a[i];
while(!DSK6713_AIC23_write(hCodec,b));
}
}
DSK6713_AIC23_closeCodec(hCodec);
}

RESULT

The sine wave tone have been successfully generated and obtained through speaker

SCT COLLEGE OF ENGINEERING Page 22


DSP LAB RECORD

Experiment 5

ADVANCED DISCRETE TIME FILTER ( FIR )

AIM

To generate filter coefficients using MATLAB and to implement Audio filter using
DSK6713

PROCEDURE

1. Connect Speaker to the LINE OUT socket.


2. Connect the line out from the PC to the LINE IN socket.
3. Now switch ON the DSK and bring up Code Composer Studio on PC
4. Create a new project with name firfilter.pjt
5. From File menu  New  DSP/BIOS Configuration  Select dsk6713.cdb
and save it as “xyz.cdb”
6. Add xyz.cdb to the current project
7. Create a new source file and save it as firfilter.c
8. Add the source file firfilter.c to the project
9. Add the library file “dsk6713bsl.lib” to the project
( Path: C:\CCStudio\C6000\dsk6713\lib\dsk6713bsl.lib)
10. Copy files “dsk6713.h” and “dsk6713_aic23.h” to the Project folder
11. Build (F7) and load the program to the DSP Chip ( File  Load Program)
12. Run the program (F5)
13. Give an audio output from the PC and notice the output in the speaker

SCT COLLEGE OF ENGINEERING Page 23


DSP LAB RECORD

Procedure for Generating Filter Coefficients in MATLAB

1. Open Matlab
2. Start  Toolboxes  Filter Design  Filter Design & Analysis Tool

3. Select the filter type and give the order and specifications for the filter and
click Design filter

SCT COLLEGE OF ENGINEERING Page 24


DSP LAB RECORD

4. From the File option select Export (or use ctrl + E)

5. Select export to Coefficient File(ASCII) and save the coefficients as txt file

6. Use these coefficients to form the coefficients in the C-file.

PROGRAM

#include"xyzcfg.h"
#include"dsk6713.h"
#include"dsk6713_aic23.h"
#define FIR_ORD 20
short fir_filter(Uint32 in,short *in_buff,float *coeff);
float fir_coeff[FIR_ORD+1]={ -0.03076334540056, -0.005410850195565,
0.03739961263014, 0.02059285910535, -0.04315598597689, -0.04556930460411,
0.04761022772871, 0.09663870571612, -0.05042696667111, -0.3229392723481,
0.5652971907268, -0.3229392723481, -0.05042696667111, 0.09663870571612,
0.04761022772871, -0.04556930460411, -0.04315598597689, 0.02059285910535,
0.03739961263014, -0.005410850195565, -0.03076334540056 };

SCT COLLEGE OF ENGINEERING Page 25


DSP LAB RECORD

short x_buff[FIR_ORD+1];
DSK6713_AIC23_Config config = DSK6713_AIC23_DEFAULTCONFIG;
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input,r_input,l_output,r_output;
DSK6713_init();
hCodec = DSK6713_AIC23_openCodec(0,&config);
DSK6713_AIC23_setFreq(hCodec,DSK6713_AIC23_FREQ_48KHZ);
while(1)
{
while(!DSK6713_AIC23_read(hCodec,&l_input));
while(!DSK6713_AIC23_read(hCodec,&r_input));
l_output=5*fir_filter(l_input,x_buff,fir_coeff);
r_output=5*fir_filter(l_input,x_buff,fir_coeff);
while(!DSK6713_AIC23_write(hCodec,l_output));
while(!DSK6713_AIC23_write(hCodec,r_output));
}
DSK6713_AIC23_closeCodec(hCodec);
}
short fir_filter(Uint32 in, short *in_buff, float *coeff)
{
int out=0;
int i;
for(i=FIR_ORD;i>0;i--)
{
in_buff[i]=in_buff[i-1];
out=out+in_buff[i]*coeff[i];
}
in_buff[0]=in;
out=out+in_buff[0]*coeff[0];
return out;
}

RESULT

The FIR filter has been implemented and the output is verified

SCT COLLEGE OF ENGINEERING Page 26


DSP LAB RECORD

Experiment 6

AM FM & PWM USING MATLAB

AIM

To implement a program in MATLAB to generate AM, FM and PWM wave.

PROGRAM

Amplitude Modulated wave


clc; clear all; close all;
t = 0:0.0001:0.015;
m = input(„Modulation Index = ‟);
fm=input(„Frequency of input wave=‟);
fc=input(„Frequency of carrier wave=‟);
x=sin(2*pi*fm*t);
y=sin(2*pi*fc*t);
e=(1+(m.*x)).*y;
plot(e);
title(„AM WAVE‟);
xlabel(„TIME INDEX‟);
ylabel(„AMPLITUDE‟);

RESULT

Modulation Index = 0.5


Frequency of input wave= 100
Frequency of carrier wave= 1000

SCT COLLEGE OF ENGINEERING Page 27


DSP LAB RECORD

Frequency modulated wave


clc; close all; clear all;

a= input („enter amplitude‟);

fc=input(„enter carrier freq‟);

fm=input(„enter modulation freq‟);

m=input(„enter modulation index‟);

n=0:0.001:.2;

y=a*sin(2*pi*fc*n-(m*cos(2*pi*fm*n)));

plot(n,y);

title(„FM‟);

xlabel(„TIME‟);

ylabel(„AMPLITUDE‟);

SCT COLLEGE OF ENGINEERING Page 28


DSP LAB RECORD

RESULT

enter amplitude = 1

enter carrier freq =100

enter modulation freq =10

enter modulation index =5

SCT COLLEGE OF ENGINEERING Page 29


DSP LAB RECORD

Pulse Width Modulated Wave


clc; close all; clear all;
fs=100;
t= 0:1/(5*fs):2;
x=sawtooth(2*pi*20*t);
m=0.75*sin(2*pi*t);
k=length(x);
for i=1:k
if (m(i)>=x(i))
pwm(i)=1;
else if (m(i)<x(i)
pwm(i)=0;
end;
end;
subplot(2,2,3);
plot(t,pwm,t,m);
axis([0,0.5,-2,2]);

RESULT

SCT COLLEGE OF ENGINEERING Page 30


DSP LAB RECORD

Experiment 7

CONVOLUTION

AIM

To write a program in MATLAB for convolution of two sequence.

PROGRAM

clc; close all; clear all;


a=input(„enter first sequence ‟);
b= input(„enter second sequence ‟);
c= fliplr(b);
d=length(a);
e=length(b);
f=[zeros(1,e-1),a,zeros(1,e)];
g=0;
i=d+e-1;
for h=0:(d+e-1);
j=[zeros(1,g),c,zeros(1,i)];
k=sum(f.*j);
con(g+1)=k;
g=g+1;
i= i-1;
end
m= 0:d+e-1;
stem(m,con);
title(„convoluted sequence‟);
xlabel(„time‟);
ylabel(„amplitude‟);

SCT COLLEGE OF ENGINEERING Page 31


DSP LAB RECORD

RESULT

enter first sequence [1 2 3 4]


enter second sequence [4 3 2 1 ]

SCT COLLEGE OF ENGINEERING Page 32


DSP LAB RECORD

Experiment 8

FIR FILTERS

AIM

To write a program in MATLAB for implementing FIR filters.

PROGRAM

clc; clear all; close all;


rp= input('Enter the passband ripple ');
rs= input('Enter the stop band ripple ');
fp= input('Enter the passband frequency ');
fs=input('Enter the stopband frequency ');
f=input('Enter the sampling frequency ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if (rem(n,2)~=0)
n1=n;
n=n-1;
end
y=boxcar(n1);
%LOW PASS FILTER
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);

SCT COLLEGE OF ENGINEERING Page 33


DSP LAB RECORD

plot(o/pi,m);
title('1. LPF');
ylabel('Gain(dB)');
xlabel(' Normalised Frequency');
%HIGH PASS FILTER
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi,m);
title('2. HPF');
ylabel('Gain(dB)');
xlabel(' Normalised Frequency');
%BAND PASS FILTER
wn=[wp,ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m);
title('3. BPF');
ylabel('Gain(dB)');
xlabel(' Normalised Frequency');
%BAND STOP FILTER
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi,m);

SCT COLLEGE OF ENGINEERING Page 34


DSP LAB RECORD

title('4. BSF');
ylabel('Gain(dB)');
xlabel(' Normalised Frequency');

RESULT

Enter the passband ripple .05


Enter the stopband ripple .04
Enter the passband frequency 1500
Enter the stopband frequency 2000
Enter the sampling frequency 9000

SCT COLLEGE OF ENGINEERING Page 35


DSP LAB RECORD

Experiment 9

BUTTERWORTH IIR FILTERS

AIM

To design and simulate Butterworth IIR filters using MATLAB

PROGRAM

Low Pass Filter

clc; clear all; close all;


rp= input('Enter the passband ripple ');
rs= input('Enter the stop band ripple ');
wp= input('Enter the passband frequency ');
ws=input('Enter the stopband frequency ');
fs=input('Enter the sampling frequency ');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('IIR LPF');
ylabel('Gain(dB)');
xlabel('Normalised frequency');
subplot(2,1,2);

SCT COLLEGE OF ENGINEERING Page 36


DSP LAB RECORD

plot(om/pi,an);
ylabel('Phase(radians)');
xlabel('Normalised frequency');

RESULT

Enter the passband ripple .5


Enter the stop band ripple 50
Enter the passband frequency 200
Enter the stopband frequency 400
Enter the sampling frequency 1000

SCT COLLEGE OF ENGINEERING Page 37


DSP LAB RECORD

HPF

clc; clear all; close all;


rp= input('Enter the passband ripple ');
rs= input('Enter the stop band ripple ');
wp= input('Enter the passband frequency ');
ws=input('Enter the stopband frequency ');
fs=input('Enter the sampling frequency ');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,'high');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('IIR HPF');
ylabel('Gain(dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase(radians)');
xlabel('Normalised frequency');

SCT COLLEGE OF ENGINEERING Page 38


DSP LAB RECORD

RESULT

Enter the passband ripple .5


Enter the stop band ripple 50
Enter the passband frequency 1200
Enter the stopband frequency 1000
Enter the sampling frequency 4000

SCT COLLEGE OF ENGINEERING Page 39


DSP LAB RECORD

BPF

clc; clear all; close all;


rp= input('Enter the passband ripple ');
rs= input('Enter the stop band ripple ');
wp= input('Enter the passband frequency ');
ws=input('Enter the stopband frequency ');
fs=input('Enter the sampling frequency ');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('IIR BPF');
ylabel('Gain(dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase(radians)');
xlabel('Normalised frequency');

SCT COLLEGE OF ENGINEERING Page 40


DSP LAB RECORD

RESULT

Enter the passband ripple .4


Enter the stop band ripple 50
Enter the passband frequency [800 1200]
Enter the stopband frequency [500 1500]
Enter the sampling frequency 4000

SCT COLLEGE OF ENGINEERING Page 41


DSP LAB RECORD

BSF

clc; clear all; close all;


rp= input('Enter the passband ripple ');
rs= input('Enter the stop band ripple ');
wp= input('Enter the passband frequency ');
ws=input('Enter the stopband frequency ');
fs=input('Enter the sampling frequency ');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,'stop');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('IIR BSF');
ylabel('Gain(dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase(radians)');
xlabel('Normalised frequency');

SCT COLLEGE OF ENGINEERING Page 42


DSP LAB RECORD

RESULT

Enter the passband ripple .4


Enter the stop band ripple 50
Enter the passband frequency [800 1500]
Enter the stopband frequency [1000 1200]
Enter the sampling frequency 4000

SCT COLLEGE OF ENGINEERING Page 43


DSP LAB RECORD

Experiment 10

CHEBYSHEV TYPE 1 FILTERS

AIM

To design and simulate Chebyshev type 1 filters using MATLAB

PROGRAM

LPF

clc; clear all; close all;


rp= input('Enter the passband ripple ');
rs= input('Enter the stop band ripple ');
wp= input('Enter the passband frequency ');
ws=input('Enter the stopband frequency ');
fs=input('Enter the sampling frequency ');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('Chebyshev Type 1 LPF');
ylabel('Gain(dB)');
xlabel('Normalised frequency');
subplot(2,1,2);

SCT COLLEGE OF ENGINEERING Page 44


DSP LAB RECORD

plot(om/pi,an);
ylabel('Phase(radians)');
xlabel('Normalised frequency');

RESULT

Enter the passband ripple .5


Enter the stop band ripple 50
Enter the passband frequency 1000
Enter the stopband frequency 1500
Enter the sampling frequency 4000

SCT COLLEGE OF ENGINEERING Page 45


DSP LAB RECORD

HPF

clc; clear all; close all;


rp= input('Enter the passband ripple ');
rs= input('Enter the stop band ripple ');
wp= input('Enter the passband frequency ');
ws=input('Enter the stopband frequency ');
fs=input('Enter the sampling frequency ');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn,'high');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('Chebyshev Type 1 HPF');
ylabel('Gain(dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase(radians)');
xlabel('Normalised frequency');

SCT COLLEGE OF ENGINEERING Page 46


DSP LAB RECORD

RESULT

Enter the passband ripple .5


Enter the stop band ripple 50
Enter the passband frequency 1500
Enter the stopband frequency 1000
Enter the sampling frequency 5000

SCT COLLEGE OF ENGINEERING Page 47


DSP LAB RECORD

BSF

clc; clear all; close all;


rp= input('Enter the passband ripple ');
rs= input('Enter the stop band ripple ');
wp= input('Enter the passband frequency ');
ws=input('Enter the stopband frequency ');
fs=input('Enter the sampling frequency ');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn,'stop');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('Chebyshev Type 1 BSF');
ylabel('Gain(dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase(radians)');
xlabel('Normalised frequency');

SCT COLLEGE OF ENGINEERING Page 48


DSP LAB RECORD

RESULT

Enter the passband ripple .5


Enter the stop band ripple 50
Enter the passband frequency [1000 1200]
Enter the stopband frequency [800 1500]
Enter the sampling frequency 4500

SCT COLLEGE OF ENGINEERING Page 49


DSP LAB RECORD

Experiment 11

CHEBYSHEV TYPE 2 FILTERS

AIM

To design and simulate Chebyshev type 2 filters using MATLAB

PROGRAM

LPF

clc; clear all; close all;

rp= input('Enter the passband ripple ');

rs= input('Enter the stop band ripple ');

wp= input('Enter the passband frequency ');

ws=input('Enter the stopband frequency ');

fs=input('Enter the sampling frequency ');

w1=2*wp/fs;

w2=2*ws/fs;

[n,wn]=cheb2ord(w1,w2,rp,rs);

[b,a]=cheby2(n,rp,wn);

w=0:0.01:pi;

[h,om]=freqz(b,a,w);

m=20*log10(abs(h));

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

title('Chebyshev Type 2 LPF');

ylabel('Gain(dB)');

xlabel('Normalised frequency');

SCT COLLEGE OF ENGINEERING Page 50


DSP LAB RECORD

subplot(2,1,2);

plot(om/pi,an);

ylabel('Phase(radians)');

xlabel('Normalised frequency');

RESULT

Enter the passband ripple .5

Enter the stop band ripple 50

Enter the passband frequency 1000

Enter the stopband frequency 1500

Enter the sampling frequency 4000

SCT COLLEGE OF ENGINEERING Page 51


DSP LAB RECORD

HPF

clc; clear all; close all;


rp= input('Enter the passband ripple ');
rs= input('Enter the stop band ripple ');
wp= input('Enter the passband frequency ');
ws=input('Enter the stopband frequency ');
fs=input('Enter the sampling frequency ');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb2ord(w1,w2,rp,rs);
[b,a]=cheby2(n,rp,wn,'high');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('Chebyshev Type 2 HPF');
ylabel('Gain(dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase(radians)');
xlabel('Normalised frequency');

SCT COLLEGE OF ENGINEERING Page 52


DSP LAB RECORD

RESULT

Enter the passband ripple .5


Enter the stop band ripple 50
Enter the passband frequency 1000
Enter the stopband frequency 800
Enter the sampling frequency 4500

SCT COLLEGE OF ENGINEERING Page 53


DSP LAB RECORD

BPF

clc; clear all; close all;


rp= input('Enter the passband ripple ');
rs= input('Enter the stop band ripple ');
wp= input('Enter the passband frequency ');
ws=input('Enter the stopband frequency ');
fs=input('Enter the sampling frequency ');
w1=2*wp/fs;
w2=2*ws/fs;
[n wn]=cheb2ord(w1,w2,rp,rs);
[b,a]=cheby2(n,rp,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('Chebyshev Type 2 BPF');
ylabel('Gain(dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase(radians)');
xlabel('Normalised frequency');

SCT COLLEGE OF ENGINEERING Page 54


DSP LAB RECORD

RESULT

Enter the passband ripple .5


Enter the stop band ripple 50
Enter the passband frequency [800 1500]
Enter the stopband frequency [1000 1200]
Enter the sampling frequency 4500

SCT COLLEGE OF ENGINEERING Page 55


DSP LAB RECORD

BSF

clc; clear all; close all;


rp= input('Enter the passband ripple ');
rs= input('Enter the stop band ripple ');
wp= input('Enter the passband frequency ');
ws=input('Enter the stopband frequency ');
fs=input('Enter the sampling frequency ');
w1=2*wp/fs;
w2=2*ws/fs;
[n wn]=cheb2ord(w1,w2,rp,rs);
[b,a]=cheby2(n,rp,wn,'stop');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('Chebyshev Type 2 BSF');
ylabel('Gain(dB)');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase(radians)');
xlabel('Normalised frequency');

SCT COLLEGE OF ENGINEERING Page 56


DSP LAB RECORD

RESULT

Enter the passband ripple .5


Enter the stop band ripple 50
Enter the passband frequency [800 1500]
Enter the stopband frequency [1000 1200]
Enter the sampling frequency 4500

SCT COLLEGE OF ENGINEERING Page 57

You might also like