Sei sulla pagina 1di 58

LAB MANUAL

Prepared by:
T.Krishna Chaitanya M.Tech.
M.Suneel M.Tech.

Department of Electronics & Communications Engineering,


Bapatla Engineering College,
Bapatla.

CONTENTS
Page.No:
INTRODUCTION TO TMS320C6713 DSK

LIST PROGRAMS:
1. MAT lab program to perform Edge detection using Prewitt operator

2. MAT lab program to perform Edge detection using Roberts operator

11

3. MAT lab program to perform Edge detection using Sobel operator

13

4. MAT lab program to perform Point detection

16

5. MAT lab program to perform Line detection

18

6. MAT lab program to perform Linear and Circular convolution

21

7. MAT lab program to perform Discrete Fourier Transform

23

8. MAT lab program to perform Discrete Cosine Transform

25

9. MAT lab program to perform Image compression using JPEG standard

28

10. Program to perform Linear convolution using CC Studio

36

11. Program to perform Circular convolution using CC Studio

39

12. Program to perform FFT operation using CC Studio

43

13. Program to perform DFT operation using CC Studio

50

INTRODUCTION TO -TMS320C6713 DSK


Package Contents:

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 to efficiently develop and
test applications for the C6713. The DSK consists of a C6713-based printed circuit board
that will serve as a hardware reference design for TIs customers products. With
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 following checklist details items that are shipped with the C6711 DSK kit.
TMS320C6713 DSK TMS320C6713 DSK development board
Other hardware

External 5VDC power supply


IEEE 1284 compliant male-to-female cable

CD-ROM

Code Composer Studio DSK tools

2
The C6713 DSK has a TMS320C6713 DSP onboard that allows full-speed
verification of code with 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 you in the
development of your own C6713-based products. In addition to providing a reference for
interfacing the DSP to various types of memories and peripherals, the design also
addresses power, clock, JTAG, and parallel peripheral interfaces.
DSK HARDWARE INSTALLATION

Shut down and power off the PC


Connect the supplied USB port cable to the board
Connect the other end of the cable to the USB port of PC
Plug the other end of the power cable into a power outlet
Plug the power cable into the board
The user LEDs should flash several times to indicate board is operational
When you connect your DSK through USB for the first time on a Windows
loaded PC the new hardware found wizard will come up. So, Install the drivers
(The CCS CD contains the require drivers for C5416 DSK).
Install the CCS software for C5416 DSK.

Troubleshooting DSK Connectivity


If Code Composer Studio IDE fails to configure your port correctly, perform the
following steps:
Test the USB port by running DSK Port test from the start menu
Use StartProgramsTexas InstrumentsCode Composer StudioCode Composer
Studio C6713 DSK ToolsC6713 DSK Diagnostic Utilities

The below Screen will appear


Select StartSelect 6713 DSK Diagnostic Utility Icon from Desktop
The Screen Look like as below
Select Start Option

Utility Program will test the board


After testing Diagnostic Status you will get PASS

If the board still fails to detect


Go to CMOS setup Enable the USB Port Option
(The required Device drivers will load along with CCS Installation)
SOFTWARE INSTALLATION
You must install the hardware before you install the software on your system.
The requirements for the operating platform are;

Insert the installation CD into the CD-ROM drive


An install screen appears; if not, goes to the windows Explorer
and run setup.exe

Choose the option to install Code Composer Sutido


If you already have C6000 CC Studio IDE installed on your PC,
do not install DSK software. CC Studio IDE full tools supports
the DSK platform
Respond to the dialog boxes as the installation program runs.

4
The Installation program automatically configures CC Studio IDE for operation
with your DSK and creates a CCStudio IDE DSK icon on your desktop. To install, follow
these instructions:
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 liked
MS-based C++TM, 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 language
and much more.
CODE COMPOSER FEATURES 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

Procedure to work on Code Composer Studio :


1. To create a New Project
Project New (SUM.pjt)

2. To Create a Source file


File New

Type the code (Save & give a name to file, Eg: sum.c).
3. To Add Source files to Project
Project Add files to Project sum.c

4. To Add rts6700.lib file & hello.cmd:


Project Add files to Project rts6700.lib
Path: c:\CCStudio\c6000\cgtools\lib\rts6700.lib
Note: Select Object & Library in(*.o,*.l) in Type of files
Project Add files to Project hello.cmd
Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd
Note: Select Linker Command file(*.cmd) in Type of files

7
5. To Compile:
Project Compile File
6. To build or Link:
Project build,
Which will create the final executable (.out) file.(Eg. sum.out).
7. Procedure to Load and Run program:
Load program to DSK:
File Load program sum. out
8. To execute project:
Debug Run.

1. Edge detection using Prewitt operator


Aim: To implement edge detection (vertical, horizontal,+45,-45 ) using prewitt operator.
Software used:
Mat lab 7.0.1 version
Program:
a=imread('cameraman.tif');
p1=[-1 -1 -1;0 0 0;1 1 1];
p2=[-1 0 1;-1 0 1;-1 0 1];
p3=[0 -1 -1;1 0 -1;1 1 0];
p4=[-1 -1 0;-1 0 1;0 1 1];
[m n]=size(a);
a1=zeros(m+2,n+2);
for i=1:m
for j=1:n
a1(i+1,j+1)=a(i,j);
end
end
for i=2:m+1
for j=2:n+1
h1(i-1,j-1)=sum(sum(a1(i-1:i+1,j-1:j+1).*p1))./9;
h2(i-1,j-1)=sum(sum(a1(i-1:i+1,j-1:j+1).*p2))./9;
h3(i-1,j-1)=sum(sum(a1(i-1:i+1,j-1:j+1).*p3))./9;
h4(i-1,j-1)=sum(sum(a1(i-1:i+1,j-1:j+1).*p4))./9;
end
end

9
for i=1:m
for j=1:n
if h1(i,j)<16
h1(i,j)=0;
end
if h2(i,j)<16
h2(i,j)=0;
end
if h3(i,j)<16
h3(i,j)=0;
end
if h4(i,j)<16
h4(i,j)=0;
end
end
end
subplot(221);imshow(h1);
subplot(222);imshow(h2);
subplot(223);imshow(h3);
subplot(224);imshow(h4);
for i=1:m
for j=1:n
h(i,j)=h1(i,j)+h2(i,j)+h3(i,j)+h4(i,j);
if h(i,j)<20
h(i,j)=0;
end

10
end
end
figure,imshow(~h),title(detected image);
figure,imshow(a),title(original image);

Result: Edge detection using prewitt operator is implemented practically.

Input image

Out put edge detected image

11

2. Edge detection using Robertss operator


Aim: To implement edge detection using Roberts operator in MATLAB.
Software used:
Mat lab 7.0.1 version
Program:
a=imread('cameraman.tif');
r1=[-1 0;0 1];
r2=[0 -1;1 0];
[m n]=size(a);
a1=zeros(m+1,n+1);
for i=1:m
for j=1:n
a1(i+1,j+1)=a(i,j);
end
end
for i=1:m
for j=1:n
h1(i,j)=sum(sum(a1(i:i+1,j:j+1).*r1))./4;
h2(i,j)=sum(sum(a1(i:i+1,j:j+1).*r2))./4;
end
end
for i=1:m
for j=1:n
if h1(i,j)<5
h1(i,j)=0;
end

12
if h2(i,j)<5
h2(i,j)=0;
end
end
end
subplot(121);imshow(~h1);
subplot(122);imshow(~h2);
for i=1:m
for j=1:n
h(i,j)=h1(i,j)+h2(i,j);
if h(i,j)<5
h(i,j)=0;
end
end
end
figure,imshow(~h,[]);
Result: Edge detection using Roberts operator is implemented practically.

Input image

Out put edge detected image

13

3. Edge detection using Sobel operator


Aim: To implement edge detection Sobel operator.
Software used:
Mat lab 7.0.1 version
Program:
a=imread('cameraman.tif');
s1=[-1 -2 -1;0 0 0;1 2 1];
s2=[-1 0 1;-2 0 2;-1 0 1];
s3=[0 -1 -2;1 0 -1;2 1 0];
s4=[-2 -1 0;-1 0 1;0 1 2];
[m n]=size(a);
a1=zeros(m+2,n+2);
for i=1:m
for j=1:n
a1(i+1,j+1)=a(i,j);
end
end
for i=2:m+1
for j=2:n+1
h1(i-1,j-1)=sum(sum(a1(i-1:i+1,j-1:j+1).*s1))./9;
h2(i-1,j-1)=sum(sum(a1(i-1:i+1,j-1:j+1).*s2))./9;
h3(i-1,j-1)=sum(sum(a1(i-1:i+1,j-1:j+1).*s3))./9;
h4(i-1,j-1)=sum(sum(a1(i-1:i+1,j-1:j+1).*s4))./9;
end
end

14
for i=1:m
for j=1:n
if h1(i,j)<15
h1(i,j)=0;
end
if h2(i,j)<15
h2(i,j)=0;
end
if h3(i,j)<15
h3(i,j)=0;
end
if h4(i,j)<15
h4(i,j)=0;
end
end
end
subplot(221);imshow(~h1);
subplot(222);imshow(~h2);
subplot(223);imshow(~h3);
subplot(224);imshow(~h4);
for i=1:m
for j=1:n
h(i,j)=h1(i,j)+h2(i,j)+h3(i,j)+h4(i,j);
if h(i,j)<15
h(i,j)=0;
end

15
end
end
figure,imshow(~h,[]);

Result: Edge detection using Sobel operator is implemented practically.

Input image

Out put edge detected image

16

4. Point detection
Aim:
To implement Point detection using MATLB.
Software used:
Mat lab 7.0.1 version
Program:
a=imread('cameraman.tif');
d1=[-1 -1 -1;-1 8 -1;-1 -1-1];
[m n]=size(a);
a1=zeros(m+2,n+2);
for i=1:m
for j=1:n
a1(i+1,j+1)=a(i,j);
end
end
for i=2:m+1
for j=2:n+1
h1(i-1,j-1)=sum(sum(a1(i-1:i+1,j-1:j+1).*d1))./9;
end
end
for i=1:m
for j=1:n
if h1(i,j)<15
h1(i,j)=0;
end
end

17
end
figure,imshow(~h1,[]);

Result: The Point detection is implemented practically.

Input image

Out put point detected image

18

5. Line detection
Aim: To implement Line detection.
Software used:
Mat lab 7.0.1 version
Program:
a=imread('cameraman.tif');
s1=[-1 -1 -1;2 2 2;-1 -1 -1];
s2=[-1 2 1;-2 0 2;-1 0 1];
s3=[0 -1 -2;1 0 -1;2 1 0];
s4=[-2 -1 0;-1 0 1;0 1 2];
[m n]=size(a);
a1=zeros(m+2,n+2);
for i=1:m
for j=1:n
a1(i+1,j+1)=a(i,j);
end
end
for i=2:m+1
for j=2:n+1
h1(i-1,j-1)=sum(sum(a1(i-1:i+1,j-1:j+1).*s1))./9;
h2(i-1,j-1)=sum(sum(a1(i-1:i+1,j-1:j+1).*s2))./9;
h3(i-1,j-1)=sum(sum(a1(i-1:i+1,j-1:j+1).*s3))./9;
h4(i-1,j-1)=sum(sum(a1(i-1:i+1,j-1:j+1).*s4))./9;
end
end

19
for i=1:m
for j=1:n
if h1(i,j)<15
h1(i,j)=0;
end
if h2(i,j)<15
h2(i,j)=0;
end
if h3(i,j)<15
h3(i,j)=0;
end
if h4(i,j)<15
h4(i,j)=0;
end
end
end
subplot(221);imshow(~h1);
subplot(222);imshow(~h2);
subplot(223);imshow(~h3);
subplot(224);imshow(~h4);
for i=1:m
for j=1:n
h(i,j)=h1(i,j)+h2(i,j)+h3(i,j)+h4(i,j);
if h(i,j)<15
h(i,j)=0;
end

20
end
end
figure,imshow(~h,[]);

Result: Line detection using Sobel operator is implemented practically

Input image

out put line detected image

21

6. Convolution
Aim: To implement the circular and linear convolution using mat lab.

Software Used:
Mat lab 7.0.1 version
Program:
Circular Convolution:
x=[2 3 8 9];
m=length(x);
h=[4 2 4 8];
n=length(h);
N=max(m,n);
s=m-n;
j=1;
z=[];
if(s==0)
h=[h,zeros(1,s)];
else
x=[x,zeros(1,-s)];
h=[h,zeros(1,s)];
end
for n=1:N
y=0;
for i=1:N
j=(n-i)+1;
if(j<=0)
j=N+j;

22
end
y=y+(x(i)*h(j));
end
z=[z y];
end
z
linear convolution:
u=[2 3 4 2];
m=length(u);
v=[4 3 2 1];
n=length(v);
z=[];
for k=1:m+n-1
b=0;
for j=max(1,k+1-n): min(k,m)
y=u(j)*v(k+1-j);
b=b+y;
end
z=[z,b];
end
z
Result:

The circular & linear convolutions are implemented practically.

In put Sequence: x[n] = {1, 2, 3, 4}, h[k] = {1, 2, 3, 4}


Out put Sequence: y[r] = { 1, 4, 10, 20, 25, 24, 16}.

23

7. DFT & Inverse DFT


Aim: To implement DFT & Inverse DFT Operations for a given sequence.
Software used:
Mat lab 7.0.1 version
Program:
% DFT
functionc=udft(x)
%x=[112233];
N=length(x);
sum=0;
c=[];
fork=0:N1
t=1
forn=0:N1
R=x(t)*exp(j*2*pi*n*k/N);
sum=sum+R;
t=t+1;
end
c=[c;sum]
sum=0;
end
%InverseDFT
functionc=Uidft(x)
%x=[1,2,3,4]
N=length(x);

24
sum=0;
c=[];
forn=0:N1
t=1;
fork=0:N1
Y=x(t)*exp((j*2*pi*n*k)/N);
R=(1/N)*Y;
sum=sum+R;
t=t+1;
end
c=[c;sum]
sum=0;
end

Result:
The DFT and IDFT operations for a given sequence are performed practically.
Input:

Out Put:

DFT
x=[112233]c=12.00001.5000+2.5981i1.5000+
0.8660i
00.0000i1.50000.8660i1.5000
2.5981i
IDFT
x=c=12.00001.5000+2.5981i1.5000+0.8660ic=112233
00.0000i1.50000.8660i1.50002.5981i

25

8. DCT & Inverse DCT


Aim: To implement DCT & Inverse DCT Operations for a given matrix.
Software used:
Mat lab 7.0.1 version
Program:
clear;close;clc;
a=magic(4)
[M,N]=size(a);
for u=1:M
for v=1:N
if (u==1&&v==1)
c=1/(sqrt(M*N));
elseif ((u~=1&&v==1)||(u==1&&v~=1))
c=sqrt(2/(M*N));
elseif (u~=1&&v~=1)
c=2/(sqrt(M*N));
end
r=0;
for x=1:M
for y=1:N
r=r+a(x,y)*((cos((pi*((2*x)-1)*(u-1))/(2*M)))*(cos((pi*((2*y)-1)*(v-1))/(2*N))));
end
end
s(u,v)=c*r;
end
end

26
[M,N]=size(s);
for x=1:M
for y=1:N
q=0;
for u=1:M
for v=1:N
if (u==1&&v==1)
c=1/(sqrt(M*N));
elseif ((u~=1&&v==1)||(u==1&&v~=1))
c=sqrt(2/(M*N));
elseif (u~=1&&v~=1)
c=2/(sqrt(M*N));
end
q=q+(c*(s(u,v)*((cos((pi*((2*x)-1)*(u-1))/(2*M)))*(cos((pi*((2*y)-1)*(v-1))/(2*N))))));
b(x,y)=q;
end
end
end
end
b
Result: The DCT and IDCT operations are performed practically..

27
Input sequence:
a=

16

13

11

10

14

15

12
1

DCT out put:


s=

34.0000

0.0000 -0.0000 -0.0000

0.0000 -0.0000 13.5140

0.0000

-0.0000

2.9302

3.3785

0.0000

-0.0000 -0.0000 11.7206

0.0000

IDCT out put:


b=

16.0000

2.0000

3.0000 13.0000

5.0000 11.0000 10.0000


9.0000

7.0000

8.0000

6.0000 12.0000

4.0000 14.0000 15.0000

1.0000

28

9. Image compression using JPEG standard


Aim: To implement lossless image compression using JPEG compression standard.
Software used:
Mat lab 7.01 version
Program:
Main program:
Clc;clear all;
a=imread('cameraman.tif');
[m,n]=size(a);
a=double(a);
q=load('quant.m');
for i=1:m/8
for j=1:n/8
a1=a(((i-1)*8)+1:((i-1)*8)+8,((j-1)*8)+1:((j-1)*8)+8);
a2=becdct(a1);
a3=a2./q;
a4=round(a3);
a5=becscan2(a4);
a6=invscan2(a5);
a7=a6.*q;
a8(((i-1)*8)+1:((i-1)*8)+8,((j-1)*8)+1:((j-1)*8)+8)=becidct2(a7);
end
end
imshow(a8,[]);
figure,imshow(a,[]);

29
1.block processing:
%function a1=blockproc(a);
a=imread('cameraman.tif');
[m,n]=size(a);
for i=1:m/8
for j=1:n/8
a1(((i-1)*8)+1:((i-1)*8)+8,((j-1)*8)+1:((j-1)*8)+8) = a(((i-1)*8)+1:((i-1)*8)+8,((j-1)*8)+1:((j1)*8)+8);
end
end
2.discret cosine transform:
function s=becdct(a);
% a=magic(4)
[M,N]=size(a);
for u=1:M
for v=1:N
if (u==1&&v==1)
c=1/(sqrt(M*N));
elseif ((u~=1&&v==1)||(u==1&&v~=1))
c=sqrt(2/(M*N));
elseif (u~=1&&v~=1)
c=2/(sqrt(M*N));
end
r=0;
for x=1:M
for y=1:N
r = r+a(x,y)*((cos((pi*((2*x)-1)*(u-1))/(2*M)))*(cos((pi*((2*y)-1)*(v-1))/(2*N))));

30
end
end
s(u,v) = c*r;
end
end
end
3.Quantization:
q= [16 11 10 16 24 40 51 61;
12 12 14 19 26 58 60 55;
14 13 16 24 40 57 69 56;
14 17 22 29 51 87 80 62;
18 22 37 56 68 109 103 77;
24 35 55 64 81 104 113 92;
49 64 78 87 103 121 120 101;
72 92 95 98 112 100 103 99];
4.Zigzag scaning (pixel re-odering):
function x=becscan2(a);
% a=magic(8);
[m,n]=size(a);
c(1:m,1:n)=a(1:8,8:-1:1);
d=diag(c);
e=d';
i=1;
j=1;
x=[];
z=[];

31
b(1:8,1:8)=a(8:-1:1,8:-1:1);
y=[];
while (i<8 && j<8)
if(i==1 && mod(j,2)==1)
y=[y,b(i,j)];
z=[z,a(i,j)];
j=j+1;
i=1;
end
if (i==1 && mod(j,2)==0)
for j=j:-1:1
y=[y,b(i,j)];
z=[z,a(i,j)];
i=i+1;
end
end
if(j==1 && mod(i,2)==0)
y=[y, b(i,j)];
z=[z,a(i,j)];
i=i+1;
j=1;
end
if(j==1 && mod(i,2)==1)
for i=i:-1:1
y=[y,b(i,j)];
z=[z,a(i,j)];

32
j=j+1;
end
end
end
y=y(28:-1:1);
x=[z,e,y];
5.Inverse scaning:
function fin=invscan2(a1);
%a1=[64,2,9,17,55,3,61,54,47,40,32,26,46,12,60,6,13,20,27,34,41,49,23,35,37,21,51,7,57,50,43,
36,29,22,15,8,58,14,44,28,30,42,16,24,31,38,45,52,59,5,53,19,39,33,25,18,11,4,62,10,48,56,63,1
;];
[m n]=size(a1);
i=1;
j=1;
k1=1;
z=a1(1:28);
y1=a1(37:64);
y=y1(28:-1:1);
b=zeros(8,8);
a=zeros(8,8);
while (i<8 && j<8)
if(i==1 && mod(j,2)==1)
b(i,j)=y(k1);
a(i,j)=z(k1);
k1=k1+1;
j=j+1;
i=1;

33
end
if (i==1 && mod(j,2)==0)
for j=j:-1:1
b(i,j)=y(k1);
a(i,j)=z(k1);
k1=k1+1;
i=i+1;
end
end
if(j==1 && mod(i,2)==0)
b(i,j)=y(k1);
a(i,j)=z(k1);
k1=k1+1;
i=i+1;
j=1;
end
if(j==1 && mod(i,2)==1)
for i=i:-1:1
b(i,j)=y(k1);
a(i,j)=z(k1);
k1=k1+1;
j=j+1;
end
end
end
d=a1(36:-1:29);

34
k2=1;
i=8;
j=1;
b=b(8:-1:1,8:-1:1);
fin=b;
while (i<=8&&j<=8)
fin(i,j)=d(k2);
k2=k2+1;
i=i-1;
j=j+1;
end
for i=1:7
for j=1:7
if (i<=j&&i<=4&&i+j<=8)
fin(i,j)=a(i,j);
elseif (i>j&&j<=4&&i+j<=8)
fin(i,j)=a(i,j);
else
fin(i,j)=fin(i,j);
end
end
end
6.Inverse DCT:
function b=becidct2(s)
[M,N]=size(s);
for x=1:M

35
for y=1:N
q=0;
for u=1:M
for v=1:N
if (u==1&&v==1)
c=1/(sqrt(M*N));
elseif ((u~=1&&v==1)||(u==1&&v~=1))
c=sqrt(2/(M*N));
elseif (u~=1&&v~=1)
c=2/(sqrt(M*N));
end
q=q+(c*(s(u,v)*((cos((pi*((2*x)-1)*(u-1))/(2*M)))*(cos((pi*((2*y)-1)*(v-1))/(2*N))))));
b(x,y)=q;
end
end
end
end
end
Result: JPEG standard for image compression is implemented practically.

Input image

out put JPEG compressed image

36

10. LINEAR CONVOLUTION


Aim:
To perform the linear convolution operation for the given sequences.
Equipment Required:
1.TMS 320 DSK 6713 Trainer
2.Power Adopter
3.USB cable
4.Code Composer studio software.

Procedure:
Open Code Composer Studio, make sure the DSP kit is turned on.
Start a new project using Project-new pull down menu, save it in a
separate directory(c:\ti\myprojects) with name lconv.pjt.
Add the source files conv.c

to the project using Projectadd files to project pull down menu.

Add the linker command file hello.cmd .


(Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd)
Add the run time support library file rts6700.lib
(Path: c:\ti\c6000\cgtools\lib\rts6700.lib)
Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
Build the program using the Project-Build pull down menu or by
clicking the shortcut icon on the left side of program window.
Load the program(lconv.out) in program memory of DSP chip using the
File-load program pull down menu.
To View output graphically
Select view graph time and frequency.

37

C PROGRAM TO IMPLEMENT LINEAR CONVOLUTION:


/* prg to implement linear convolution */
#include<stdio.h>
#define LENGHT1 6

/*Lenght of i/p samples sequence*/

#define LENGHT2 4

/*Lenght of impulse response Co-efficients */

int x[2*LENGHT1-1]={1,2,3,4,5,6,0,0,0,0,0};
Samples*/

/*Input Signal

int h[2*LENGHT1-1]={1,2,3,4,0,0,0,0,0,0,0};
efficients*/

/*Impulse Response Co-

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

Result:
The linear convolution operation for the given input sequence is performed
practically
Input:

Output:

x[n] = {1, 2, 3, 4}
h[k] = {1, 2, 3, 4}

y[r] = { 1, 4, 10, 20, 25, 24, 16}.

38

Configure the graphical window as shown below

39

11. Circular Convolution


Aim:
To perform the circular convolution operation for given input sequences.
Equipment Required:
1.TMS 320 DSK 6713 Trainer
2.Power Adopter
3.USB cable
4.Code Composer studio software.

Procedure:
Open Code Composer Studio, make sure the DSP kit is turned on.
Start a new project using Project-new pull down menu, save it in a
separate directory(c:\ti\myprojects) with name cir conv.pjt.
Add the source files Circular Convolution.C

to the project using Projectadd files to project pull down menu.

Add the linker command file hello.cmd .


(Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd)
Add the run time support library file rts6700.lib
(Path: c:\ti\c6000\cgtools\lib\rts6700.lib)
Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
Build the program using the Project-Build pull down menu or by
clicking the shortcut icon on the left side of program window.
Load the program(lconv.out) in program memory of DSP chip using the
File-load program pull down menu.

40

Program to Implement 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 the first sequence\n");

scanf("%d",&m);

printf("

enter the length of the 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)
equal*/

/*If length of both sequences are not

if(m>n)

/* Pad the smaller sequence with zero*/

41
{

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++)
n)*/

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++)

/*folding h(n) to h(-

42
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];

/*displaying the result*/

printf("

the circular convolution is\n");

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

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

Result:
The Circular convolution operation for the given sequence is observed practically
IN PUT:

x[4]={3, 2, 1,0}, h[4]={1, 1, 0,0}

OUT PUT:

y[4]={3, 5, 3,0}

43

12. Fast Fourier Transforms (FFT)


Aim:
To perform the FFT operation for the given input sequence.

Equipment Required:
1.TMS 320 DSK 6713 Trainer
2.Power Adopter
3.USB cable
4.Code Composer studio software.

C PROGRAM TO IMPLEMENT FFT:


Main.c (fft 256.c):
#include <math.h>
#define PTS 64

//# of points for FFT

#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n);

//FFT prototype

float iobuffer[PTS];

//as input and output buffer

float x1[PTS];

//intermediate buffer

short i;
variable

//general purpose index

short buffercount = 0;
iobuffer

//number of new samples in

short flag = 0;
iobuffer full

//set to 1 by ISR when

COMPLEX w[PTS];
in w

//twiddle constants stored

COMPLEX samples[PTS];

//primary working buffer

44
main()
{
for (i = 0 ; i<PTS ; i++)
in w

// set up twiddle constants

{
w[i].real = cos(2*PI*i/(PTS*2.0)); //Re component of twiddle
constants
w[i].imag =-sin(2*PI*i/(PTS*2.0)); //Im component of twiddle
constants
}
for (i = 0 ; i < PTS ; i++)

//swap buffers

{
iobuffer[i] =

sin(2*PI*10*i/64.0);/*10-

> freq,

64 -> sampling freq*/


samples[i].real=0.0;
samples[i].imag=0.0;
}
for (i = 0 ; i < PTS ; i++)

//swap buffers

{
samples[i].real=iobuffer[i]; //buffer with new data
}
for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0;

//imag components = 0

45

FFT(samples,PTS);

//call function FFT.c

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

//compute magnitude

{
x1[i] = sqrt(samples[i].real*samples[i].real
+ samples[i].imag*samples[i].imag);
}

//end of main

fft.c:
#define PTS 64

//# of points for FFT

typedef struct {float real,imag;} COMPLEX;


extern COMPLEX w[PTS];
in w

//twiddle constants stored

void FFT(COMPLEX *Y, int N)

//input sample array, # of points

{
COMPLEX temp1,temp2;

//temporary storage variables

int i,j,k;

//loop counter variables

int upper_leg, lower_leg;


leg
int leg_diff;
leg
int num_stages = 0;
int index, step;
constant
i = 1;

//index of upper/lower butterfly

//difference between upper/lower

//number of FFT stages (iterations)


//index/step through twiddle

//log(base2) of N points= # of stages

46
do
{
num_stages +=1;
i = i*2;
}while (i!=N);
leg_diff = N/2;
step = (PTS*2)/N;

//difference between upper&lower legs


//step between values in twiddle.h

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

//for N-point FFT

{
index = 0;
for (j = 0; j < leg_diff; j++)
{
for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff))
{
lower_leg = upper_leg+leg_diff;
temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real;
temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag;
temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real;
temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag;
(Y[lower_leg]).real = temp2.real*(w[index]).real
-temp2.imag*(w[index]).imag;
(Y[lower_leg]).imag = temp2.real*(w[index]).imag
+temp2.imag*(w[index]).real;
(Y[upper_leg]).real = temp1.real;
(Y[upper_leg]).imag = temp1.imag;
}
index += step;

47
}
leg_diff = leg_diff/2;
step *= 2;
}
j = 0;
for (i = 1; i < (N-1); i++)
resequencing data
{
k = N/2;
while (k <= j)
{
j = j - k;
k = k/2;
}
j = j + k;
if (i<j)
{
temp1.real = (Y[j]).real;
temp1.imag = (Y[j]).imag;
(Y[j]).real = (Y[i]).real;
(Y[j]).imag = (Y[i]).imag;
(Y[i]).real = temp1.real;
(Y[i]).imag = temp1.imag;
}
}
return;
}

//bit reversal for

48

PROCEEDURE:
Open Code Composer Studio, make sure the DSP kit is turned on.
Start a new project using Project-new pull down menu, save it in a
separate directory(c:\ti\myprojects) with name FFT.pjt.
Add the source files FFT256.c and FFT.C in the project using
Projectadd files to project pull down menu.
Add the linker command file hello.cmd
Add the rts file rts6700.lib
Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
Load the program in program memory of DSP chip using the File-load program
pull down menu.
Run the program and observe output using graph utility.

Result:
The operation of FFT for the given input is observed practically.

49

Graphical representations

Input:

Output:

50

13. DISCRETE FOURIER TRANSFORM (DFT)


Aim:
To perform the DFT operation for the given input sequence.
Equipment Required:
1. TMS 320 DSK 6713 Trainer
2. Power Adopter
3. USB cable
4. Code Composer studio software.

Source Code DFT:


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
structcomp
{
floatR,I;
};
typedefstructcompcmplx;
/*functionprototypesusedinDFTandIDFT*/
voidadd_comp_num(cmplxa,cmplxb,cmplx*c);
voidget_input(cmplx*inp,intsz);
voidput_data(cmplx*,int);
voidmul_comp_num(cmplxa,cmplxb,cmplx*c);
voidcomp_dft(cmplx*,cmplx*,intsz);
voidput_comp_num(cmplx);
voidcomp_Idft(cmplx*x1,cmplx*y1,intsz);

51
voidmain(void)
{
cmplx*x,*y,p,q,r,*ix;
intsize;
printf("\nEnterthesizeofinputsamples:");
scanf("%d",&size);
/*allocatememoryforinputandoutputvariables*/
x=(cmplx*)malloc(size*sizeof(cmplx));
y=(cmplx*)malloc(size*sizeof(cmplx));
ix=(cmplx*)malloc(size*sizeof(cmplx));
/*gettheinputdatafromtheinteractivescreen*/
get_input(x,size);
/*computeDFTanddiaplaytheoutpuut*/
comp_dft(x,y,size);
put_data(y,size);
/*computeIDFTandseethattheoutputissameasinput*/
comp_Idft(y,ix,size);
put_data(ix,size);
}
voidcomp_Idft(cmplx*x1,cmplx*y1,intsz)
{
inti,j,k,n,N;
floatarg;
cmplxt,ag,res,p,q;
N=sz;

52
for(n=0;n<sz;n++)
{
res.R=0;
res.I=0;
t.R=0;
t.I=0;
for(k=0;k<sz;k++)
{
arg=(2.0*(22.0/7.0)*n*k)/(float)N;
ag.R=cos(arg);
ag.I=sin(arg);
/*printf("\theanglevalue");
*/
/*put_comp_num(ag);*/
p.R=(x1+k)>R;
p.I=(x1+k)>I;
q.R=res.R;
q.I=res.I;
mul_comp_num(p,ag,&t);
/*printf("\nmultiplicationvalue");
*/
put_comp_num(t);
add_comp_num(t,q,&res);
/*printf("\ntheadditionvalue");
*/

53
/*put_comp_num(res);*/
}
printf("\n\niteration%d",k);
(y1+n)>R=res.R/N;
(y1+n)>I=res.I/N;
}
return;
}
voidcomp_dft(cmplx*x1,cmplx*y1,intsz)
{
inti,j,k,n,N;
floatarg;
cmplxt,ag,res,p,q;
N=sz;
for(k=0;k<sz;k++)
{
res.R=0;
res.I=0;
t.R=0;
t.I=0;
for(n=0;n<sz;n++)
{
arg=(2.0*(22.0/7.0)*n*k)/(float)N;
ag.R=cos(arg);
ag.I=sin(arg);

54
/*printf("\theanglevalue");
*/
/*put_comp_num(ag);*/
p.R=(x1+n)>R;
p.I=(x1+n)>I;
q.R=res.R;
q.I=res.I;
mul_comp_num(p,ag,&t);
/*printf("\nmultiplicationvalue");
*/
put_comp_num(t);
add_comp_num(t,q,&res);
/*printf("\ntheadditionvalue");
*/
/*put_comp_num(res);*/
}
printf("\n\niteration%d",k);
(y1+k)>R=res.R;
(y1+k)>I=res.I;
}
return;
}
voidput_data(cmplx*ot,intsz)
{
inti;

55
printf("\noutputdata\n");
for(i=0;i<sz;i++)
printf("\n%4.1f+j%4.1f",(ot+i)>R,(ot+i)>I);
return;
}
voidget_input(cmplx*inp,intsz)
{
floatre,im;
inti;
printf("\nEntertheinputsampleofsize%d",sz);
for(i=0;i<sz;i++)
{
scanf("\n%f",&re);
printf("+j");
scanf("%f",&im);
(inp+i)>R=re;
(inp+i)>I=im;
}
return;
}
voidadd_comp_num(cmplxa,cmplxb,cmplx*c)
{
c>R=a.R+b.R;
c>I=a.I+b.I;
}

56
voidmul_comp_num(cmplxa,cmplxb,cmplx*c)
{
c>R=a.R*b.Ra.I*b.I;
c>I=a.I*b.R+a.R*b.I;
}
voidput_comp_num(cmplxt)
{
printf("\n%f+j%f",t.R,t.I);
return;
}

Result:
The DFT operation is performed practically using CC Studio.

Potrebbero piacerti anche