📄 test_ogold.c
字号:
/* * $Log: test_ogold.c,v $ * Revision 1.1 2000/05/03 14:30:04 bjc97r * Initial revision * */char *id = "$Id: test_ogold.c,v 1.1 2000/05/03 14:30:04 bjc97r Exp $";#include <stdio.h>#include <stdlib.h>#include "ogold.h"int main( int argc, char *argv[] ) /* This program shows how to use ogold*() functions to generate OGold codes */{ unsigned deg; unsigned long poly0, poly1; OGold *pn00, *pn01; OGold *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 OGold 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 OGold sequences using " "the above polynomials.\n" "The index for the first OGold sequence is '1'.\n" "The index for the second OGold sequence are '5'.\n"); printf("\n1st column: offset\n"); printf("2nd column: autocorrelations of the first OGold sequence\n"); printf("3rd column: autocorrelations of the second OGold sequence\n"); printf("4th column: cross-correlations between the two OGold sequences\n\n"); pn_size = 1 << deg; pn00 = ogold_create( deg, poly0, poly1, 1); pn01 = ogold_create( deg, poly0, poly1, 1); pn10 = ogold_create( deg, poly0, poly1, 5); pn11 = ogold_create( deg, poly0, poly1, 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=ogold(pn00)) == ogold(pn01) ) ? +1 : -1; acorr1 += ( ogold(pn10) == (c1=ogold(pn11)) ) ? +1 : -1; xcorr += ( c0 == c1 ) ? +1 : -1; } printf("%10d %10ld %10ld %10ld\n", offset, acorr0, acorr1, xcorr ); /* increment the offset. */ ogold(pn01); ogold(pn11); } puts(""); ogold_free(pn00); ogold_free(pn01); ogold_free(pn10); ogold_free(pn11); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -