Пример #1
0
/* Function "encodeQPSK"    
**  Description:   encode message using QPSDK pi/4 modulation 
**
** INPUT : 
**         message      the input message
**         size         the imput message size
** OUTPUT:
**        signal        the modulation signal
** 
*/
extern void encodeQPSK(short message[], double signal[], int size)
{
 double Ik[HALF_BUFF_SIZE], Qk[HALF_BUFF_SIZE];
 double Isam[SAMPLE_RANGE], Qsam[SAMPLE_RANGE];
 int i, j, halfsize, Sample_Range;
 double oldI, oldQ, newI, newQ;
 int replicate_carrier;
 short tbc1, tbc2;
 short NORMALIZATION = 10;
 
 halfsize     = size >> 1;
 Sample_Range = NUM_SAMPLES * halfsize;
 
 // Remap to {-1, 1}
 for(i = 0; i < size; ++i)
   message[i] = (message[i] << 1) - 1;
 
 oldI = 1;
 oldQ = 0;

 // Returns the phase shifts for pi/4 DQPSK from the input binary data stream 
 for(i = 0; i < halfsize; ++i)
 {
    tbc1 = message[i * 2];
    tbc2 = message[i * 2 + 1];
    
    newI = ( oldI * tbc1 - oldQ * tbc2) * multFact;
    newQ = ( oldQ * tbc1 + oldI * tbc2) * multFact;
	    
    oldI = newI;
    oldQ = newQ;
    
    Ik[i] = newI;
    Qk[i] = newQ;
  } 

 j = 0;

 for(i = 0; i < Sample_Range; ++i)
  if( i % NUM_SAMPLES == 0 )
   {
     Isam[i] = Ik[j];    
     Qsam[i] = Qk[j];
     j = j + 1;
   }
  else
     Isam[i] = Qsam[i] = 0;
 
 fir_filter( Isam, Sample_Range );
 fir_filter( Qsam, Sample_Range );

 // Upmix with carrier
 for(j = 0; j < Sample_Range; ++j)
 {
   replicate_carrier = j % CARRIER_SIZE;
   signal[j] = ( Isam[j] * Icarrier[replicate_carrier] + Qsam[j] * Qcarrier[replicate_carrier] ) * NORMALIZATION;
 }
}
int main (){
	double y[N];
	double b[MAX_TAP] = {
		3.558363, -0.542859, -0.928322, -0.993428, 4.643953, -5.909149, 1.722120, -1.854375,
		-1.967672, -2.170269, 0.673272, 0.182548, -4.812593, 0.818270, 0.889598, 0.322937,
		-0.430576, -4.259421, -0.983597, 4.285341, -2.333795, 1.856496, -4.711222, -0.517585,
		-8.376492, -1.440117, -6.255069, -0.000203, 0.881922, 6.955272, -0.209273, 5.219892 };
	
	double x[N] = {
		0.286381, 0.310398, 0.732308, 0.301956, 0.053523, 0.431617, 0.999498, 0.801469,
		0.639967, 0.293192, 0.404720, 0.823173, 0.695269, 0.744480, 0.676903, 0.968651,
		0.524716, 0.843609, 0.562026, 0.297492, 0.384924, 0.379665, 0.087916, 0.535140,
		0.224908, 0.136965, 0.186164, 0.811894, 0.010466, 0.754323, 0.227373, 0.296848,
		0.064720, 0.959681, 0.598804, 0.118243, 0.391298, 0.598302, 0.919712, 0.031265,
		0.891494, 0.324432, 0.854438, 0.586763, 0.068912, 0.531341, 0.555414, 0.593628,
		0.374950, 0.117441, 0.891120, 0.759874, 0.497106, 0.979036, 0.295014, 0.722014,
		0.116001, 0.481178, 0.533908, 0.126467, 0.235500, 0.761281, 0.423315, 0.300220 };

	int i;
	
	fir_filter(y,b,x,N,TAP);
	printf("Result data:\n");
	for(i=0; i < N; i++) // unroll this for (64 times) !!
		printf("%f %f\n", (double)i, y[i]);
	printf("end\n");
	return 0;
}
Пример #3
0
int main(){
    float input_data;
    int32 output_data;
    //Configure hardware
    codec_init();
    fir_init(banda1,banda2,banda3,banda4,banda5);

    while(1){
        //Processing data
        if(DSK6713_DIP_get(3)==0){
            //Initialize processing
            leds_output(LED_STATE_ACTIVE);

            while(DSK6713_DIP_get(3)==0){
                input_data = codec_read();
                output_data = fir_filter(input_data);
                codec_write(output_data);
            }
        }
        //Waiting
        else{
            leds_output(LED_STATE_WATING);
        }
    }
}
/**
 * Resample
 *
 * @note When downsampling, the input count must be divisible by rate ratio
 *
 * @param rs   Resampler
 * @param outv Output samples
 * @param outc Output sample count (in/out)
 * @param inv  Input samples
 * @param inc  Input sample count
 *
 * @return 0 if success, otherwise error code
 */
int auresamp(struct auresamp *rs, int16_t *outv, size_t *outc,
	     const int16_t *inv, size_t inc)
{
	size_t incc, outcc;

	if (!rs || !rs->resample || !outv || !outc || !inv)
		return EINVAL;

	incc = inc / rs->ich;

	if (rs->up) {
		outcc = incc * rs->ratio;

		if (*outc < outcc * rs->och)
			return ENOMEM;

		rs->resample(outv, inv, inc, rs->ratio);

		*outc = outcc * rs->och;

		fir_filter(&rs->fir, outv, outv, *outc, rs->och,
			   rs->tapv, rs->tapc);
	}
	else {
		outcc = incc / rs->ratio;

		if (*outc < outcc * rs->och || *outc < inc)
			return ENOMEM;

		fir_filter(&rs->fir, outv, inv, inc, rs->ich,
			   rs->tapv, rs->tapc);

		rs->resample(outv, outv, inc, rs->ratio);

		*outc = outcc * rs->och;
	}

	return 0;
}
Пример #5
0
int main()
{
    double x;
    struct FirStruct fs;
    int i;

    init_fir(&fs, 100.0 * 30.0 * 60.0);

    for (i = 0; i < 1000000; i++) {
        x = sin(2.0 * M_PI * (double) i / 4000) + sin(2.0 * M_PI * (double) i / 8000);
        printf("%g %g\n", x, fir_filter(x, &fs));
    }
    return (0);
}
Пример #6
0
/* Function "decodeQPSK"    
**  Description:   decode signal  using QPSDK pi/4 modulation  
**
** INPUT : 
**        signal        the modulation signal (Received)
**        size          signal size
** OUTPUT:
**         message      the transmitted message
** 
*/
extern void decodeQPSK(double signal[], short message[], int size)
{
 int i, j, replicate_carrier;
 double Irec[SAMPLE_RANGE], Qrec[SAMPLE_RANGE];
 double Ik[HALF_BUFF_SIZE], Qk[HALF_BUFF_SIZE];
 FILE *file; 

 for(j = 0; j < size; ++j)
 {
    replicate_carrier = j % CARRIER_SIZE;
    Irec[j] = signal[j] * Icarrier[replicate_carrier]; 
    Qrec[j] = signal[j] * Qcarrier[replicate_carrier];  
 }

 fir_filter(Irec, size);
 fir_filter(Qrec, size);
  
 file = fopen("plot.txt", "w"); 

 i = 0;
 for(j = NUM_TAPS; j < size; j +=NUM_SAMPLES )
 {
  Ik[i] = Irec[j];
  Qk[i] = Qrec[j];
  fprintf(file, "%g  %g\n", Ik[i], Qk[i]);
  ++i;
 }

 fclose(file);	  
 
 // Loop through and decode the phases  
 for(j = 1; j < HALF_BUFF_SIZE; ++j)
  {
    message[(j << 1) - 2] = (Qk[j] * Qk[j-1] + Ik[j] * Ik[j-1]) > 0;
    message[(j << 1) - 1] = (Ik[j-1] * Qk[j] - Ik[j] * Qk[j-1]) > 0;
  } 
}