You are on page 1of 17

1. 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 Co mposer 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.

Program to Implement Circular Convolution: #include <stdio.h> #include <conio.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(m>n) { for(i=n;i<m;i++) h[i]=0; n=m; } /* Pad the smaller sequence with zero*/ /*If length of both sequences are not

for(i=m;i<n;i++) x[i]=0; m=n; } y[0]=0; a[0]=h[0]; for(j=1;j<n;j++) a[j]=h[n-j]; /*Circular convolution*/ for(i=0;i<n;i++) y[0]+=x[i]*a[i]; for(k=1;k<n;k++) { y[k]=0; /*circular shift*/ for(j=1;j<n;j++) x2[j]=a[j-1]; x2[0]=a[n-1]; for(i=0;i<n;i++) { a[i]=x2[i]; y[k]+=x[i]*x2[i]; } } /*displaying the result*/ /*folding h(n) to h(-n)*/

printf(" the circular convolution is\n"); for(i=0;i<n;i++) printf("%d \t",y[i]); getch(); } 13. DISCRETE FOURIER TRANSFORM (DFT) Aim: To perform the DFT ope ration 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> 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);

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;

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("\ the angle value"); */ /*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("\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+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<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);

/*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;

printf("\n out put data \n"); for(i=0;i<sz;i++) printf("\n %4.1f+j%4.1f",(ot+i)->R,(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;i<sz;i++) { scanf("\n%f",&re); printf("+j"); scanf("%f",&im); (inp+i) ->R=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; }

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;

} /* prg to implement linear convolution */ #include <stdio.h> #include <conio.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}; /*Input Signal Samples*/ int h[2*LENGHT1-1]={1,2,3,4,0,0,0,0,0,0,0}; /*Impulse Response Coefficients*/ 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]); getch(); }

//sine8_buf Sine_ 1khz generation. Output buffer plotted within CCS

#include "dsk6713_aic23.h" Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; int loop = 0; short gain = 10; short sine_table[8]={0,707,1000,707,0,-707,-1000,-707};//sine values short out_buffer[256]; const short BUFFERLENGTH = 256; int i = 0; //output buffer //size of output buffer //for buffer count

//support file for codec,DSK //set sampling rate //table index //gain factor

interrupt void c_int11() {

//interrupt service routine

output_sample(sine_table[loop]*gain);//output sine values out_buffer[i] = sine_table[loop]*gain; i++; buffer count if(i==BUFFERLENGTH) i=0; if (loop < 7) ++loop; else loop = 0; return; //return from interrupt } //check for end of table //reinit table index //output to buffer //increment

//if @ bottom reinit count

void main() {

comm_intr(); while(1); } . Thc hin mch iu ch PSK trn kit C6713 //BPSK #include "DSK6713_aic23.h" Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //infinite loop

//init DSK, codec, McBSP

#include <math.h> //Initialization: int i_BPSK; int j_BPSK; int k; int masked_value, output; int out_buffer[256]; int i=0; //Data table for BPSK int data_BPSK[2][4]={0, 1000, 0, -1000, 0, -1000, 0, 1000}; //180 degree //0 degree

interrupt void c_int11() { int sample_data;

//interrupt service routine

if (i_BPSK==64) //determines when to get new input { sample_data = input_sample(); //inputs data i_BPSK=0; j_BPSK=0; }

masked_value = sample_data & 0x0001; output = data_BPSK[masked_value][j_BPSK]; output_sample(output*10); out_buffer[i++] = output*10; if (i==256) i = 0; j_BPSK++; //repeated output counter

if (j_BPSK==4) { j_BPSK=0; sample_data = sample_data >> 1; } i_BPSK++; return; }

void main()

{ i_BPSK=64; j_BPSK=0; comm_intr(); while(1); //infinite loop QPSK //QPSK #include "DSK6713_aic23.h" Uint32 fs=DSK6713_AIC23_FREQ_8KHZ;

#include <math.h> //Initialization: int i_QPSK; int j_QPSK; int k; int masked_value, output; int out_buffer[256]; int i=0; //Data table for QPSK int data_QPSK[4][4]={0, 1000, 0, -1000, 1000, 0,-1000,0, // 90 degree 0, -1000, 0, 1000,//180 degree -1000,0,1000,0};// 270 degree interrupt void c_int11() //interrupt service routine //0 degree

{ int sample_data;

if (i_QPSK==32) {

//determines when to get new input

sample_data = input_sample(); i_QPSK=0; j_QPSK=0; }

//inputs data

masked_value = sample_data & 0x0003; output = data_QPSK[masked_value][j_QPSK]; output_sample(output*10); out_buffer[i++] = output*10; if (i==256) i = 0; j_QPSK++; //repeated output counter

if (j_QPSK==4) { j_QPSK=0; sample_data = sample_data >> 2; } i_QPSK++; return;

void main() { i_QPSK=32; j_QPSK=0; comm_intr(); while(1); } Thc hin mch iu ch PAM trn kit C6713 DSK //infinite loop

You might also like