Ejemplo n.º 1
0
static void
processSignalData( RCCWorker * self  )
{
  State *myState = self->memories[0];  

  RCCPort
    *in_if = &self->ports[MIXER_COMPLEX_IN_IF],
    *in_dds = &self->ports[MIXER_COMPLEX_IN_DDS],
    *out = &self->ports[MIXER_COMPLEX_OUT];

  Mixer_complexOutIq 
    *outData = (Mixer_complexOutIq*)out->current.data,
    *in_ifData = (Mixer_complexOutIq*)in_if->current.data, 
    *in_ddsData = (Mixer_complexOutIq*)in_dds->current.data;

  // We get vectors from both the dds and the if inputs, we can only process
  // the based on the shortest vector
  unsigned int len = min( byteLen2Complex(in_if->input.length)-myState->curIfIndex,
			  byteLen2Complex(in_dds->input.length)-myState->curDdsIndex);
  len = min(len, byteLen2Complex(out->output.length));



  // DDS * IF = out  -> (a+bi)(c+di) = (ac - bd) + (bc + ad)i  : (if.I + if.Q)(dds.I + dds.Q)
  unsigned int n;
  for ( n=0; n<len; n++ ) {
    double dtmp = ( Uscale(in_ifData->data[myState->curIfIndex].I) * Uscale(in_ddsData->data[myState->curDdsIndex].I) ) 
      - ( Uscale(in_ifData->data[myState->curIfIndex].Q) * Uscale(in_ddsData->data[myState->curDdsIndex].Q) );
    outData->data[n].I = Scale( dtmp );

    dtmp = ( Uscale(in_ifData->data[myState->curIfIndex].Q) * Uscale(in_ddsData->data[myState->curDdsIndex].I) ) 
      + ( Uscale(in_ifData->data[myState->curIfIndex].I) * Uscale(in_ddsData->data[myState->curDdsIndex].Q) );
    outData->data[n].Q = Scale( dtmp );

    myState->curDdsIndex++;
    myState->curIfIndex++;

  }
  
  // Figure out who to advance
  if ( myState->curIfIndex >= byteLen2Complex(in_if->input.length) ) {
    self->container.advance( in_if, 0);
    myState->curIfIndex = 0;
  }
  if ( myState->curDdsIndex >= byteLen2Complex(in_dds->input.length) ) {
    self->container.advance( in_dds, 0);
    myState->curDdsIndex = 0;
  }

  // Always advance the output
  self->container.advance( out, 0);  

}
Ejemplo n.º 2
0
static double
apply_filter( double taps[],  int16_t *input )
{
  unsigned	i = 0;
  double	
    acum0 = 0,
    acum1 = 0,
    acum2 = 0,
    acum3 = 0;
  unsigned	n = (NTAPS / UnRoll) * UnRoll;
  for (i = 0; i < n; i += UnRoll){
    acum0 += taps[i + 0] * Uscale( input[i + 0] );
    acum1 += taps[i + 1] * Uscale( input[i + 1] );
    acum2 += taps[i + 2] * Uscale( input[i + 2] );
    acum3 += taps[i + 3] * Uscale( input[i + 3] );
  }
  for (; i < NTAPS; i++)
    acum0 += taps[i] * Uscale( input[i] );
  return (acum0 + acum1 + acum2 + acum3);
}
Ejemplo n.º 3
0
static RCCResult
start(RCCWorker *self) {
  Comparator_realProperties *p = self->properties;
  MyState *s = self->memories[0];

  s->deviation = Uscale( p->deviation );

  // We do this since a single failure will turn this to a false but we still
  // want to run the entire test to generate the output files for debug and 
  // analysis
  p->passed = 1;

  return RCC_OK;
}
Ejemplo n.º 4
0
static RCCResult
run(RCCWorker *self, RCCBoolean timedOut, RCCBoolean *newRunCondition) {
  (void)timedOut;(void)newRunCondition;
  MyState *s = self->memories[0];
  Cic_hpfilter_complexProperties *p = self->properties;

 RCCPort
   *in = &self->ports[CIC_HPFILTER_COMPLEX_IN],
   *out = &self->ports[CIC_HPFILTER_COMPLEX_OUT];
   
 Cic_hpfilter_complexInIq
   *inData = in->current.data,
   *outData = out->current.data;
 
 out->output.u.operation = in->input.u.operation;
 out->output.length = in->input.length;
 switch( in->input.u.operation ) {

 case CIC_HPFILTER_COMPLEX_IN_IQ:
   {
     unsigned out_idx = 0;
     unsigned len = byteLen2Complex(in->input.length);
     unsigned i, samp;

#ifndef NDEBUG
      printf("%s got %zu bytes of data\n", __FILE__,  in->input.length);
#endif

     // We may need to generate more output data from the last input
     unsigned max_out = byteLen2Complex(out->current.maxLength);
     if ( s->remainder ) {
       for ( i=0; (i<s->remainder) && (out_idx<max_out); i++, out_idx++ ) {
	 outData->data[out_idx].I = s->fast_acc[II][STAGES];
	 outData->data[out_idx].Q = s->fast_acc[QQ][STAGES];
       }
       s->remainder -= i;
       if ( out_idx >= max_out ) {
	 return sendOutput( self, s, out, s->input_idx, byteLen2Complex(in->input.length));
       }
     }

     len = min(len,max_out);
     for ( samp=s->input_idx; samp<len; samp++ ) {

       // I
       s->slow_acc[II][0] = inData->data[samp].I;
       s->fast_acc[II][0] = s->fast_acc[II][0] + s->slow_acc[II][STAGES];
       for ( i=0; i<STAGES; i++ ) {
	 s->slow_acc[II][i+1] = s->slow_acc[II][i] - s->slow_del[II][i];
	 s->slow_del[II][i] = s->slow_acc[II][i];
       }
       for ( i=1; i<=STAGES; i++ ) {
	 s->fast_acc[II][i] = s->fast_acc[II][i] + s->fast_acc[II][i-1];       
       }

       // Q
       s->slow_acc[QQ][0] = inData->data[samp].Q;
       s->fast_acc[QQ][0] = s->fast_acc[QQ][0] + s->slow_acc[QQ][STAGES];
       for ( i=0; i<STAGES; i++ ) {
	 s->slow_acc[QQ][i+1] = s->slow_acc[QQ][i] - s->slow_del[QQ][i];
	 s->slow_del[QQ][i] = s->slow_acc[QQ][i];
       }
       for ( i=1; i<=STAGES; i++ ) {
	 s->fast_acc[QQ][i] = s->fast_acc[QQ][i] + s->fast_acc[QQ][i-1];       
       }

       // Generate the interpolated output 
       // We are not really interpolating here, just copying the last calculated value
       for ( i=0; i<p->M; i++, out_idx++ ) {
	 if ( out_idx  >= max_out ) {
	   s->remainder = p->M-i;
	   return sendOutput( self, s, out, samp,  byteLen2Complex(in->input.length));
	 }
	 double gain = Gain( p->gain);
	 outData->data[out_idx].I = Scale( Uscale(s->fast_acc[II][STAGES]) * gain);
	 outData->data[out_idx].Q = Scale( Uscale(s->fast_acc[QQ][STAGES]) * gain);	 
	 double v = scabs( outData->data[out_idx].I, outData->data[out_idx].Q );
	 if ( v > Uscale( p->peakDetect ) ) {
	    p->peakDetect = Scale( v );
	 }
       }
     }
     return sendOutput( self, s, out, samp, byteLen2Complex(in->input.length));
   }
   break;  

 case CIC_HPFILTER_COMPLEX_IN_SYNC:
   sync( self  );
 case CIC_HPFILTER_COMPLEX_IN_TIME:
   self->container.send( out, &in->current, in->input.u.operation, in->input.length);
   break;

 }

 return RCC_OK;
}