discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss-gnuradio] acoustic packet detection block


From: Raman O
Subject: [Discuss-gnuradio] acoustic packet detection block
Date: Tue, 6 Jul 2010 17:41:10 +0530 (IST)

Hello,

  I am implementing transceiver based on acoustic waves. Now I have started with receiver. Input to the receiver is from audio_alsa_source. I have written a block  named packet_detect based on sync_decimator to accept samples from alsa_source.

Within the packet_detect block , I have been able to detect start of the frame. Next how can I buffer the data beyond frame start point (ignoring all the earlier samples) and pass it to the next higher blocks for processing.

I have pasted packet_detect code below, Please help me.

Thanks in advance
Raman

short pkd_detected=0;
packetdetection::packetdetection(size_t item_size, size_t nitems_per_block)
  : gr_sync_decimator ("packetdetection",
          gr_make_io_signature(1,1, item_size),
          gr_make_io_signature(1,1,item_size * nitems_per_block),
          nitems_per_block  )
{
    d_offset=0;
    d_sigma1=0;
    d_sigma2=0;
}

 
/* ----------- transformation process : Phi -------------- */

int
packetdetection::work (int noutput_items,
           gr_vector_const_void_star &input_items,
           gr_vector_void_star &output_items)
{
  size_t block_size = output_signature()->sizeof_stream_item (0);
 
  const float *inbuf = ( const float*) input_items[0];
  float *outbuf = (float*) output_items[0];
  unsigned int i,j,k,itemsize;
  float alpha1=0.125,alpha2=0.875,temp;
 
  itemsize=block_size/sizeof(float);
 

      if(!pkd_detected){
     d_sigma1=*inbuf;
     for(i=1;i<noutput_items * itemsize;i++) {//for i=2:M
       temp=inbuf[i];
        d_sigma2=alpha1*temp*temp + alpha2*d_sigma1 ;  //sigma(i)=alpha*Y(i)*Y(i)+(1-alpha)*sigma(i-1);
        d_sigma1=d_sigma2;
        if( d_sigma2>0.08){
       
        pkd_detected=1;
        printf("packet detected at %d \n",i);
        for(k=0;k<(noutput_items *itemsize-i);k++){
            outbuf[k] = inbuf[i];
        }
        d_offset+=k;
       
        d_sigma1=0,d_sigma2=0;
         return noutput_items;
        }
       
     }
     return noutput_items;
     
      }
      else{
   
    for(j=d_offset,i=0;j<(noutput_items * itemsize-d_offset);j++,i++){
      outbuf[j] = inbuf[i];
    }
    d_offset+=i;
    return noutput_items;
   
      }
    
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]