DSPRelated.com

Correlation on DSP KIT TMS320C6713 Simulator

December 15, 2010 Coded in C++ for the TI C67x
#include <stdio.h>
#include <math.h>

double pi=3.14159;

float x[50],y[50];
float r[100];

void correlation(float *x,float *y, int nx, int ny);

int main()
{   
   

int ii;
for(ii=0;ii<50  ;ii++)
 {
	 x[ii]=sin(2.0*pi*ii*3/50);
 	 y[ii]=sin(2.0*pi*ii*3/50);

 }

correlation(x,y,50,50);

printf("Complete.\n");

return 0;
}

void correlation(float *x,float *y, int nx, int ny)
{
	int n=50,delay=0,maxdelay=50;
	int i,j;
   double mx,my,sx,sy,sxy,denom;
  
   
   /* Calculate the mean of the two series x[], y[] */
   mx = 0;
   my = 0;   
	   for (i=0;i<n;i++) 
		   {
			  mx += x[i];
			  my += y[i];
		   }
   mx /= n;
   my /= n;

   /* Calculate the denominator */
   sx = 0;
   sy = 0;
	   for (i=0;i<n;i++) 
		   {
			  sx += (x[i] - mx) * (x[i] - mx);
			  sy += (y[i] - my) * (y[i] - my);
		   }
   denom = sqrt(sx*sy);

   /* Calculate the correlation series */
   for (delay=-maxdelay;delay<maxdelay;delay++) 
	   {
		  sxy = 0;
			  for (i=0;i<n;i++) 
				  {
					 j = i + delay;
	 if (j < 0 || j >= n)
						continue;
	 else
						sxy += (x[i] - mx) * (y[j] - my);
					 // Or should it be (?)
					/* if (j < 0 || j >= n)
						sxy += (x[i] - mx) * (-my);
					 else
						sxy += (x[i] - mx) * (y[j] - my);*/
					 
				  }
r[delay+maxdelay]= ( sxy / denom);

Constant complexity rectangular QAM demodulator

Vashishth November 14, 2010 Coded in C for the TI C67x
% N is the size of the constellation.
% v is the input data.
% For details email me.
void function_qam()
{

co=0;
 m=0;

for(q=0; q<N; q++)

        {

 a=v[m];// a holds the real part
 b=v[m+1];// b holds the imaginary part

 d=a-onern[max];  %onern stores the negative real axis points and onein stores the negative imag axis points. eg for 256 QAM, each will store 0 to -8 as an array.
 l=d;         //l stores the distance
 s=(d-l);
 if(l<max-1) % max is the maximum value that the 1-d coordinate can take.
       {

if(d>0){
 if(s<=.5)
       {
 hi=max-l;
 flagtwo=1;
       }
 else
 {
 hi=max-l-1;
 flagtwo=1;
 }
      }
	  else
	  {
	  hi=max;
	  flagtwo=1;
	  }
        
      }

 if(l==max-1)
 {
 hi=1;
 flagtwo=1;
 }
 if(l==max)//
 {
 flagone=1;
 hi=1;
 } 

 if(l>max)
        {
		if(d<2*max)
		{

 if(s<=.5)
 {
 hi=l-max;
 flagone=1;
 }
 else
 {
 hi=l-max+1;
 flagone=1;
 }
        }
		else
		{
		hi=max;
		flagone=1;
		}
       
          
        }

 de=b-onein[max];
 le=de;         //l stores the distance
 se=(de-le);

 if(le<max-1)
      {

	  if(de>0)
	  {
 if(se<=.5)
 {
 hm=max-le;
 flagfour=1;
 }
 else
 {
 hm=max-le-1;
 flagfour=1;
 }
      
      }
	  else
	  {
	  hm=max;
	  flagfour=1;
      }
      
      
      }

 if(le==max-1)
 {
 hm=1;
 flagfour=1;
 }
 if(le==max)
 {
 flagthree=1;
 hm=1;
 }

 if(le>max)
     {

if(de<2*max){

 if(se<=.5)
 {
 hm=le-max;
 flagthree=1;
 }
 else
 {
 hm=le-max+1;
 flagthree=1;
 }
    }
	else
	{
	hm=max;
	flagthree=1;
	}
    
       
    
    }

 if(flagone==1)
 {
  vv[m]=hi;  // now v[m] holds one x coordinate of the qam mapping and v[m+1] holds the y coordinate
 }
 
 else
 {
 vv[m]= 100-hi;
 }

 
 if(flagthree==1)
  {
 vv[m+1]=hm;  
  }
		else
		{
 vv[m+1]= 100-hm;
        }

flagone=0;
flagtwo=0;
flagthree=0;
flagfour=0;
        r=0;
        
        
          
           output[co]= valuetable[ vv[m] ][ vv[m+1] ] ;
       
       
          
          
                        
      m = m+ 2;
	  
	  co = co+ 1;
                
                
                 }

  for(t=0;t<(N/2);t++)
  {
   p[t] = (output[t]);
 
  }

 

}

Using EMIF expansion port as digital output

David Valencia October 27, 20107 comments Coded in C for the TI C67x
/*      David Valencia at DSPRelated.com

        This example shows how to use the External Memory Interface
        expansion port of Spectrum Digital DSK6713 card as
        a set of digital imputs
        The use of buffer ICs is mandatory, as these pins can't deliver
        too much current        */

#define OUTPUT 0xA0000000  // EMIF ADDRESS (updated 3/11/2010)

int *output = (int*)OUTPUT; // Declare a pointer to EMIF's address

void main()
{
        // To see how the value is written to the EMIF pins,
        // you may prefer to run the program step-by-step

        // Write a 32-bit digital value to the pins
        *output = 0x48120A00; // Test value
}