Home >Documents >c6713 Dsp Lab

c6713 Dsp Lab

Date post:01-Jun-2018
Category:
View:226 times
Download:3 times
Share this document with a friend
Transcript:
  • 8/9/2019 c6713 Dsp Lab

    1/58

     

    L B M NU L

    Prepared by:

    T.Krishna Chaitanya M.Tech. 

    M.Suneel M.Tech. 

    Department of Electronics & Communications Engineering,

    Bapatla Engineering College,

    Bapatla.

  • 8/9/2019 c6713 Dsp Lab

    2/58

    CONTENTS

    Page.No:

    INTRODUCTION TO TMS320C6713 DSK 1

    LIST PROGRAMS:

    1. MAT lab program to perform Edge detection using Prewitt operator 8

    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

  • 8/9/2019 c6713 Dsp Lab

    3/58

    1

    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 andtest applications for the C6713. The DSK consists of a C6713-based printed circuit boardthat will serve as a hardware reference design for TI’s customers’ products. Withextensive 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

  • 8/9/2019 c6713 Dsp Lab

    4/58

    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 thedevelopment of your own C6713-based products. In addition to providing a reference forinterfacing 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 menuUse StartProgramsTexas InstrumentsCode Composer StudioCode Composer

    Studio C6713 DSK ToolsC6713 DSK Diagnostic Utilities

    •  The below Screen will appear

    •  Select   Start  Select 6713 DSK Diagnostic Utility Icon from Desktop

    •  The Screen Look like as below

    •  Select Start Option

  • 8/9/2019 c6713 Dsp Lab

    5/58

    3

    •  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 Explorerand 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 supportsthe DSK platform

    Respond to the dialog boxes as the installation program runs.

  • 8/9/2019 c6713 Dsp Lab

    6/58

    4

    The Installation program automatically configures CC Studio IDE for operationwith your DSK and creates a CCStudio IDE DSK icon on your desktop. To install, followthese 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) 

  • 8/9/2019 c6713 Dsp Lab

    7/58

    5

    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

  • 8/9/2019 c6713 Dsp Lab

    8/58

    6

    4. To Add r ts6700.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 fi les

    Project   Add files to Project  hello.cmd

    Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd

    Note: Select Linker Command f ile(*.cmd) in Type of files

  • 8/9/2019 c6713 Dsp Lab

    9/58

    7

    5. To Compi le:

    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.

  • 8/9/2019 c6713 Dsp Lab

    10/58

    8

    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

  • 8/9/2019 c6713 Dsp Lab

    11/58

    9

    for i=1:m

    for j=1:n

    if h1(i,j)

  • 8/9/2019 c6713 Dsp Lab

    12/58

    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 

  • 8/9/2019 c6713 Dsp Lab

    13/58

    11

    2. Edge detection using Roberts’s 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)

  • 8/9/2019 c6713 Dsp Lab

    14/58

    12

    if h2(i,j)

  • 8/9/2019 c6713 Dsp Lab

    15/58

    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

  • 8/9/2019 c6713 Dsp Lab

    16/58

    14

    for i=1:m

    for j=1:n

    if h1(i,j)

  • 8/9/2019 c6713 Dsp Lab

    17/58

    15

    end

    end

    figure,imshow(~h,[]);

    Result: Edge detection using Sobel operator is implemented practically.

    Input image Out put edge detected image

  • 8/9/2019 c6713 Dsp Lab

    18/58

    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)

  • 8/9/2019 c6713 Dsp Lab

    19/58

    17

    end

    figure,imshow(~h1,[]);

    Result:  The Point detection is implemented practically.

    Input image Out put point detected image

  • 8/9/2019 c6713 Dsp Lab

    20/58

    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

  • 8/9/2019 c6713 Dsp Lab

    21/58

    19

    for i=1:m

    for j=1:n

    if h1(i,j)

  • 8/9/2019 c6713 Dsp Lab

    22/58

    20

    end

    end

    figure,imshow(~h,[]);

    Result: Line detection using Sobel operator is implemented practically…

    Input image out put line detected image

  • 8/9/2019 c6713 Dsp Lab

    23/58

    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

  • 8/9/2019 c6713 Dsp Lab

    24/58

    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}. 

  • 8/9/2019 c6713 Dsp Lab

    25/58

    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

    function c=udft(x) 

    % x=[1 1 2 2 3 3]; 

    N=length(x); 

    sum=0; 

    c=[]; 

    for k=0:N‐1 

    t=1 

    for n=0:N‐1 

    R=x(t)*exp(‐ j*2*pi*n*k/N); 

    sum=sum+R; 

    t=t+1; 

    end 

    c=[c;sum] 

    sum=0; 

    end 

    % Inverse

     DFT

     

    function  c=Uidft(x) 

    %x=[1,2,3,4] 

    N=length(x); 

  • 8/9/2019 c6713 Dsp Lab

    26/58

    24

    sum=0; 

    c=[]; 

    for n=0:N‐1 

    t=1; 

    for k=0:N‐1 

    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=[1 1 2 2 3 3]  c= 12.0000 ‐1.5000 + 2.5981i ‐1.5000 + 

    0.8660i 

    0 ‐ 0.0000i ‐1.5000 ‐ 0.8660i  ‐1.5000 ‐

    2.5981i 

    IDFT 

    x =  c= 12.0000 ‐1.5000 + 2.5981i ‐1.5000 + 0.8660i  c= 1 1 2 2  3 3 

    0 ‐ 0.0000i ‐1.5000 ‐ 0.8660i  ‐1.5000 ‐ 2.5981i 

  • 8/9/2019 c6713 Dsp Lab

    27/58

    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

  • 8/9/2019 c6713 Dsp Lab

    28/58

    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..

  • 8/9/2019 c6713 Dsp Lab

    29/58

    27

    Input sequence:

    a =

    16 2 3 13

    5 11 10 8

    9 7 6 12

    4 14 15 1

    DCT out put:

    s =

    34.0000 0.0000 -0.0000 -0.0000

    0.0000 -0.0000 13.5140 0.0000

    -0.0000 3.3785 0.0000 2.9302

    -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 8.0000

    9.0000 7.0000 6.0000 12.0000

    4.0000 14.0000 15.0000 1.0000

  • 8/9/2019 c6713 Dsp Lab

    30/58

    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,[]);

  • 8/9/2019 c6713 Dsp Lab

    31/58

    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:((j-

    1)*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))));

  • 8/9/2019 c6713 Dsp Lab

    32/58

    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=[];

  • 8/9/2019 c6713 Dsp Lab

    33/58

    31

     b(1:8,1:8)=a(8:-1:1,8:-1:1);

    y=[];

    while (i

  • 8/9/2019 c6713 Dsp Lab

    34/58

    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/9/2019 c6713 Dsp Lab

    35/58

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

  • 8/9/2019 c6713 Dsp Lab

    36/58

    34

    k2=1;

    i=8;

     j=1;

     b=b(8:-1:1,8:-1:1);

    fin=b;

    while (i

  • 8/9/2019 c6713 Dsp Lab

    37/58

    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

  • 8/9/2019 c6713 Dsp Lab

    38/58

    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 aseparate 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 byclicking the shortcut icon on the left side of program window.

      Build the program using the ‘Project-Build’ pull down menu or byclicking 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 graphicallySelect view graph time and frequency.

  • 8/9/2019 c6713 Dsp Lab

    39/58

    37

    ‘C’ PROGRAM TO IMPLEMENT LINEAR CONVOLUTION:

    /* prg to implement linear convolution */

    #include

    #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}; /*Input Signal

    Samples*/

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

    efficients*/

    int y[LENGHT1+LENGHT2-1];

     main()

    {

    int i=0,j;

    for(i=0;i

  • 8/9/2019 c6713 Dsp Lab

    40/58

    38

    Configure the graphical window as shown below

  • 8/9/2019 c6713 Dsp Lab

    41/58

    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 aseparate directory(c:\ti\myprojects) with name ci r  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 byclicking the shortcut icon on the left side of program window.

      Build the program using the ‘Project-Build’ pull down menu or byclicking 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.

  • 8/9/2019 c6713 Dsp Lab

    42/58

    40

    Program to Implement Circular Convolution:

    #i ncl ude

    i nt m, n, x[ 30] , h[ 30] , y[ 30] , i , j , t emp[ 30] , k, x2[ 30] , a[ 30] ;

    voi d mai n( )

    {

    pr i nt f ( " ent er t he l engt h of t he f i r st sequence\ n") ;

    scanf ( "%d" , &m) ;

    pr i nt f ( " ent er t he l engt h of t he second sequence\ n") ;

    scanf ( "%d" , &n) ;

    pr i nt f ( " ent er t he f i r st sequence\ n") ;

    f or( i =0; i

  • 8/9/2019 c6713 Dsp Lab

    43/58

    41

    {

    f or( i =n; i

  • 8/9/2019 c6713 Dsp Lab

    44/58

    42

    y[k] =0;

    / *ci r cul ar shi f t * /

    f or ( j =1; j

  • 8/9/2019 c6713 Dsp Lab

    45/58

    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

    #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; //general purpose index

    variable

    short buffercount = 0; //number of new samples in

    iobuffer

    short flag = 0; //set to 1 by ISR when

    iobuffer full

    COMPLEX w[PTS]; //twiddle constants stored

    in w

    COMPLEX samples[PTS]; //primary working buffer

  • 8/9/2019 c6713 Dsp Lab

    46/58

    44

     main()

    {

    for (i = 0 ; i 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

  • 8/9/2019 c6713 Dsp Lab

    47/58

    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]; //twiddle constants stored

    in w

    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; //index of upper/lower butterfly

    leg

    int leg_diff; //difference between upper/lower

    leg

    int num_stages = 0; //number of FFT stages (iterations)

    int index, step; //index/step through twiddle

    constant

    i = 1; //log(base2) of N points= # of stages

  • 8/9/2019 c6713 Dsp Lab

    48/58

    46

    do

    {

    num_stages +=1;

    i = i*2;

    }while (i!=N);

    leg_diff = N/2; //difference between upper&lower legs

    step = (PTS*2)/N; //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;

  • 8/9/2019 c6713 Dsp Lab

    49/58

    47

    }

    leg_diff = leg_diff/2;

    step *= 2;

    }

    j = 0;

    for (i = 1; i < (N-1); i++) //bit reversal for

    resequencing data

    {

    k = N/2;

    while (k

  • 8/9/2019 c6713 Dsp Lab

    50/58

    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 aseparate 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 byclicking 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.

  • 8/9/2019 c6713 Dsp Lab

    51/58

    49

    Graphical representations

    Input:

    Output:

  • 8/9/2019 c6713 Dsp Lab

    52/58

    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 

    #include 

    #include 

    struct comp 

    float R,I; 

    }; 

    typedef  struct comp cmplx; 

    /* function prototypes used in DFT and IDFT*/ 

    void add_comp_num(cmplx a,cmplx b,cmplx *c); 

    void get_input(cmplx *inp,int sz); 

    void put_data(cmplx *,int ); 

    void mul_comp_num(cmplx a,cmplx b,cmplx *c); 

    void comp_dft(cmplx *,cmplx *,int sz); 

    void put_comp_num(cmplx ); 

    void comp_Idft(cmplx *x1,cmplx *y1,int sz); 

  • 8/9/2019 c6713 Dsp Lab

    53/58

    51

    void main(void) 

    cmplx *x,*y,p,q,r,*ix; 

    int size;

     

    printf  ("\n Enter the size of  input samples :"); 

    scanf("%d",&size); 

    /* allocate memory for input and output variables */ 

    x=(cmplx *) malloc(size* sizeof(cmplx)); 

    y=(cmplx *) malloc(size* sizeof(cmplx)); 

    ix=(cmplx *)

     malloc(size*

     sizeof(cmplx));

     

    /* get the input data from the interactive screen */ 

    get_input(x,size); 

    /* compute DFT and diaplay the out puut */ 

    comp_dft(x,y,size); 

    put_data(y,size); 

    /* compute

     IDFT

     and

     see

     that

     the

     out

     put

     is

     same

     as

     input

     */

     

    comp_Idft(y,ix,size); 

    put_data(ix,size); 

    void comp_Idft(cmplx *x1,cmplx *y1,int sz) 

    int i,j,k,n,N;

     

    float arg; 

    cmplx t,ag,res,p,q; 

    N=sz; 

  • 8/9/2019 c6713 Dsp Lab

    54/58

    52

    for(n=0;nI;

     

    q.R=res.R; 

    q.I=res.I; 

    mul_comp_num(p,ag,&t); 

    /*printf("\n multiplication value"); 

    */ 

    put_comp_num(t); 

    add_comp_num(t,q,&res); 

    /*printf("\n the addition value"); 

    */ 

  • 8/9/2019 c6713 Dsp Lab

    55/58

    53

    /*put_comp_num(res);*/ 

    printf("\n\n iteration %d",k); 

    (y1+n)‐>R=res.R/N;

     

    (y1+n)‐>I=res.I/N; 

    return; 

    void comp_dft(cmplx *x1,cmplx *y1,int sz) 

    int i,j,k,n,N; 

    float arg; 

    cmplx t,ag,res,p,q; 

    N=sz; 

    for(k=0;k

  • 8/9/2019 c6713 Dsp Lab

    56/58

    54

    /*printf("\ the angle value"); 

    */ 

    /*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("\n multiplication value"); 

    */ 

    put_comp_num(t); 

    add_comp_num(t,q,&res); 

    /*printf("\n the addition value"); 

    */ 

    /*put_comp_num(res);*/ 

    printf("\n\n iteration %d",k); 

    (y1+k)‐>R=res.R; 

    (y1+k)‐>I=res.I; 

    return; 

    void put_data(cmplx *ot,int sz) 

    int i; 

  • 8/9/2019 c6713 Dsp Lab

    57/58

    55

    printf("\n out put data \n"); 

    for(i=0;iR,(ot+i)‐>I); 

    return; 

    void get_input(cmplx *inp,int sz) 

    float re,im; 

    int i; 

    printf("\n Enter

     the

     input

     sample

     of 

     size

     %d",sz);

     

    for(i=0;iR=re;

     

    (inp+i)‐>I=im; 

    return; 

    void add_comp_num(cmplx a,cmplx b,cmplx *c) 

    c‐>R=a.R+b.R; 

    c‐>I=a.I+b.I; 

  • 8/9/2019 c6713 Dsp Lab

    58/58

    56

    void mul_comp_num(cmplx a,cmplx b,cmplx *c) 

    c‐>R=a.R*b.R‐a.I*b.I; 

    c‐>I=a.I*b.R+a.R*b.I;

     

    void put_comp_num(cmplx t) 

    printf("\n %f+j%f",t.R,t.I); 

    return; 

    Result: 

    The DFT operation is performed practically using CC Studio.

Embed Size (px)
Recommended