mrog.c
上传用户:thinkst802
上传日期:2013-02-03
资源大小:2k
文件大小:2k
源码类别:

源码/资料

开发平台:

C/C++

  1. /*
  2.  * $Log: mrog.c,v $
  3.  * Revision 1.1  2000/05/03 14:30:04  bjc97r
  4.  * Initial revision
  5.  *
  6.  */
  7. char *_mrog_id = "$Id: mrog.c,v 1.1 2000/05/03 14:30:04 bjc97r Exp $";
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include "mrog.h"
  11. // It create an Multi-Rate Orthogonal Gold(MROG) code generator with
  12. // the given connection polynomials and for the given index'th code.
  13. // The MROG generator is returned.
  14. Mrog *mrog_create( unsigned deg, unsigned long poly0, unsigned long poly1,
  15.    unsigned index )
  16. {
  17.   Mrog *mrog;
  18.   int   bindex; /* base ogold index */
  19.   if ( deg > 31 ) {
  20.     fprintf(stderr, "mrog_create: ..cannot handle deg > 31n");
  21.     return NULL; /* too big degree of polynomial */
  22.   }
  23.   mrog = (Mrog*) malloc( sizeof(Mrog) );
  24.   bindex = index & ( (1<<deg) - 1 ); /* last deg bits of the index */
  25.   mrog->id = ogold_create( deg, poly0, poly1, bindex );
  26.   mrog->period   = 1 << deg; /* 2^deg */
  27.   mrog->og_cnt   = 1;        /* 1..period */
  28.   mrog->ext_code = index >> deg; /* upper part of the index */
  29.   mrog->ext_cnt  = 0;        /* 0.. */
  30.   mrog->ext      = 0;        /* 0 or 1 */
  31.   return mrog;
  32. }
  33. void mrog_free( Mrog *mrog )
  34. {
  35.   ogold_free( mrog->id );
  36.   free( (void*) mrog );
  37. }
  38. // mrog() gives the next multi-rate orthogonal Gold code sequence.
  39. char mrog( Mrog *id )
  40. {
  41.   char seq;
  42.   
  43.   seq = id->ext ^ ogold( id->id );
  44.   if ( id->og_cnt == id->period ) {
  45.     /* ogold code cycles at this point. update extension modifier */
  46.     unsigned long dump;
  47.     char          tmp;
  48.     id->og_cnt = 1;
  49.     id->ext_cnt++;
  50.     /* Sylvester construction or Hadamard transform of the original
  51.        orthogonal Gold code sequence */
  52.     dump = id->ext_cnt & id->ext_code;
  53.     tmp = 0;
  54.     for( tmp = 0; dump; dump >>= 1 ) {
  55.       tmp ^= dump & 1;
  56.     }
  57.     id->ext = tmp;
  58.   }
  59.   else {
  60.     id->og_cnt++;
  61.   }
  62.   return seq;
  63. }