Power spectrum density (PSD) using TMS320C67XX/TMS320C6713 KIT 

Aim:To find the Power spectrum density (PSD) using TMS320C67XX/TMS320C6713 KIT

SOFTARE REQUIREMENTS:

Operating System – Windows XP

Constructor - Simulator

Software – Code Composer Studio3.1v,  6713DSK Diagnostics.

HARDARE REQUIREMENTS:

TMS320C6713DSP KIT  

USB cable  

Power Supply +5v 

Procedure:  

  1. Open code composer studio, make sure the DSP kit is turned on.
  2. Start a new project using ‘project-new’ pull down menu, save it in a separate directory (c:\ccstudio\myprojects) with the name ‘file name. pjt’.
  3. Add the source file of linear convolution to the project using ‘project-add files to project’ pull down menu.
  4. Add the linker command file ‘hello. cmd’ (c\ccstudio\tutorials\dsk6713\hello1\hello.cmd)
  5. Add the run time support library file rts6700.lib c-ccstudio\c6000\cgtools\lib\rts6700.lib)
  6. Compile program using the ‘project-compile’ pull down menu or by clicking the short cut icon on the left side of program window.
  7. Build the program using ‘project-build’ pull down menu or by clicking the icon on the left side of the program window.
  8. Load the program in program memory of  DSP chip using the ‘file-load program’ pull down menu.
  9. To view o/p graphically, select View -graph-time and frequency.

Program:

# include <math.h>  
#define PTS128 //# of points for FFT
#define PI 3.14159265358979
typedef struct {float real,imag;}COMPLEX
void FFT(COMPLEX Y, int n); float iobuffer[PTS];
float x1[PTS],x[PTS]; short i;
short buffercount = 0; shaort flag = 0;
COMPLEX w [PTS];  
w*/
COMPLEX samples[PTS];
main( )  
{
float j,sum=0.0; int n,k,i,a;
for (I = 0 ; i<PTS ; i++)  
{
/*FFT prototype*/
/*as input and output buffer*/  
/*intermediate buffer*/
/*general purpose index variable */  
/*number of new samples in iobuffer*/
/*set to 1 by ISR when iobuffer full*/  
/*twiddle constants stored in
/*primary working buffer*/
/*set up twiddle constants in w */  
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*/  
}  
/*Input signal X(n) */  
for(i=0,j=0;i<PTS;i++)  
{  
x[i] = sin(2*PI*5*i/PTS); /*Signal x(Fs)=sin(2*PI*f*i/Fs);*/
samples[i].real=0.0;  
samples[i].imag=0.0;  
}  
/*Auto Correlation of X(n)=R(t) */  
for(n=0;n<PTS;n++)  
{  
sum=0;  
for(k=0;k<PTS-n;k++)  
{
sum=sum+(x[k]*x[n+k]);  
}
iobuffer[n] = sum;  
}
/*FFT of R(t) */
for(i = 0 ; i < PTS ; i++)  
{
/*Auto Correlation R(t)*/
/*swap buffers*/  
samples[i].real=iobuffer[i]; /*buffer with new data*/  
}  
for(i = 0 ; I < PTS ; i++)
samples[i].imag = 0.0; FFT(samples,PTS);
/*Power Spectral Density */
for (i = 0 ; i < PTS ; i++)  
{
/*imag components = 0*/ /*call function FFT.c*/
/*compute magnitude*/  
x1[i] = sqrt(samples[i].real*samples[i].real  
+samples[i].imag*samples[i].imag);  
}  
} /*end of main*/
FFT SUBPROGRAM
#define PTS 64 /*number 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; int leg_diff;
int num_stages = 0; int index, step;
i = 1;
do  
{
num_stages += 1;  
i= i*2;
}
while (i! = N);  
leg_diff = N/2;  
lower legs*/
step = (PTS*2)/N;  
twiddle.h */
/*index of upper/lower butterfly leg*/  
/*difference between upper/lower leg */
/* number of FFT stages (iterations)  */  
/*index/step through twiddle constant */  
/* log(base2) of N points= # of stages */
/* difference between upper &amp;
/* step between values in
for (i= 0;i < num_stages; i++)  
{
index = 0;
for (j = 0; j < leg_diff; j++)  
{
 
/*for N-point FFT*/  
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;  
}  
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 <= 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;
}

Precautions:  

? Switch ON the computer only after connecting USB cable and  make sure the DSP kit is ON.  

?   Perform the diagnostic check before opening code composer  studio.  

?   All the connections must be tight.  

Result :  The power density spectrum is obtained and the graphs are plotted.

Viva questions:  

1.  Define power spectral Density?  

2.  What is the need for spectral estimation?  

3.  Determine the power spectrum density?  

4.  What is the relation between auto correlation & spectral density?  

5.  Give the estimation of auto correlation function & power density for  random Signals?  

6.  Explain power spectrum estimation using the Bartlett window?  

7.  Give the formula for PSD?