⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_gold.c

📁 伪随机gold序列产生程序
💻 C
字号:
/* * $Log: test_gold.c,v $ * Revision 1.1  2000/05/03 14:30:04  bjc97r * Initial revision * */char *id = "$Id: test_gold.c,v 1.1 2000/05/03 14:30:04 bjc97r Exp $";#include <stdio.h>#include <stdlib.h>#include "gold.h"int main( int argc, char *argv[] )  /* This program shows how to use gold*() functions to generate     Gold codes */{  unsigned deg;  ulong poly0, poly1;  Gold *pn00, *pn01;  Gold *pn10, *pn11;  unsigned pn_size;  unsigned offset;  if ( argc != 4 ) {    fprintf(stderr, "%s: deg poly poly1\n", argv[0] );    fprintf(stderr, " Try, for example,\n" );    fprintf(stderr, "   %s 5 045 075\n", argv[0] );    fprintf(stderr, "   %s 23 040000041 040404041\n", argv[0] );    exit(1);  }  deg = atoi( argv[1] );  if ( deg < 2 ) {    fprintf(stderr, "deg should be greater than 2\n");    exit(1);  }  poly0 = strtoul( argv[2], (char**)NULL, 0 );  if ( poly0 < 7 ) {    fprintf(stderr, "poly(%s) is invalid polynomial!\n", argv[2] );    exit(1);  }  poly1 = strtoul( argv[3], (char**)NULL, 0 );  if ( poly1 < 7 ) {    fprintf(stderr, "poly1(%s) is invalid polynomial!\n", argv[3] );    exit(1);  }  // Print the header.  printf("The entered Gold code specification is\n\n");  printf("  degree      : %d\n", deg);  printf("  poly0(octal): 0%lo\n",   poly0 );  printf("  poly1(octal): 0%lo\n\n", poly1 );  printf("This program generates two Gold sequences using "	 "the above polynomials.\n"	 "The seeds for the first  Gold sequence are '1' and '1'.\n"	 "The seeds for the second Gold sequence are '1' and '5'.\n");  printf("\n1st column: offset\n");  printf("2nd column: autocorrelations of the first  Gold sequence\n");  printf("3rd column: autocorrelations of the second Gold sequence\n");  printf("4th column: cross-correlations between the two Gold sequences\n\n");  pn_size = (1 << deg) -1;  pn00 = gold_create( deg, poly0, poly1, 1, 1);  pn01 = gold_create( deg, poly0, poly1, 1, 1);  pn10 = gold_create( deg, poly0, poly1, 1, 5);  pn11 = gold_create( deg, poly0, poly1, 1, 5);  for ( offset = 0; offset < pn_size; offset++ ) {     int i;    long acorr0, acorr1, xcorr;    char c0, c1;    acorr0 = acorr1 = xcorr = 0;    for ( i=0; i < pn_size; i++ ) {      acorr0 += ( (c0=gold(pn00)) == gold(pn01) ) ? +1 : -1;      acorr1 += ( gold(pn10) == (c1=gold(pn11)) ) ? +1 : -1;      xcorr  += ( c0 == c1 ) ? +1 : -1;    }    printf("%10d %10ld %10ld %10ld\n", offset, acorr0, acorr1, xcorr );    // increment the offset.    gold(pn01);    gold(pn11);  }  puts("");  gold_free(pn00);    gold_free(pn01);  gold_free(pn10);    gold_free(pn11);  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -