📄 test_lkasami.c
字号:
/* * $Log: test_lkasami.c,v $ * Revision 1.1 2000/05/03 14:30:04 bjc97r * Initial revision * */char *id = "$Id: test_lkasami.c,v 1.1 2000/05/03 14:30:04 bjc97r Exp $";#include <stdio.h>#include <stdlib.h>#include <string.h>#include "lkasami.h"#include "gf.h"#include "u2long.h"#define SZ_BUF 128int main( int argc, char *argv[] ){ unsigned deg; char poly0[SZ_BUF]; unsigned long poly1; u2long pn_size; u2long offset; if ( argc != 3 ) { fprintf(stderr, "%s: deg poly\n", argv[0] ); fprintf(stderr, " Try, for example,\n" ); fprintf(stderr, " %s 6 0103\n", argv[0] ); fprintf(stderr, " %s 20 04000011\n", argv[0] ); fprintf(stderr, " %s 36 01000000004001\n", argv[0] ); exit(1); } deg = atoi( argv[1] ); if ( deg < 4 ) { fprintf(stderr, "deg should be greater than 4\n"); exit(1); } strncpy( poly0, argv[2], SZ_BUF ); poly1 = find_longsubpoly( deg, poly0 ); /* Print the header. */ printf("The entered long Kasami code specification is\n\n"); printf(" degree : %d\n", deg); printf(" poly0(octal): %s\n", poly0 ); printf(" poly1(octal): 0%lo\n\n", poly1 ); printf("This program generates two Kasami sequences using " "the above polynomials.\n" "The seeds for the first Kasami sequence are '1' and '1'.\n" "The seeds for the second Kasami sequence are '1' and '5'.\n"); printf("\n1st column: offset in hexadecimal format\n"); printf("2nd column: autocorrelations of the first Kasami sequence\n"); printf("3rd column: autocorrelations of the second Kasami sequence\n"); printf("4th column: cross-correlations between the two Kasami sequences\n"); puts(""); pn_size.h = 0; pn_size.l = 1; u2long_lshift( &pn_size, deg ); u2long_dec( &pn_size ); for ( offset.h = 0, offset.l = 0; u2long_cmp(offset,pn_size) < 0; u2long_inc(&offset) ) { u2long i; long acorr0, acorr1, xcorr; LKasami *pn00, *pn01; LKasami *pn10, *pn11; LKasami *pnx0, *pnx1; pn00 = lkasami_create( deg, poly0, 1 ); pn01 = lkasami_create( deg, poly0, 1 ); pn10 = lkasami_create( deg, poly0, 5 ); pn11 = lkasami_create( deg, poly0, 5 ); pnx0 = lkasami_create( deg, poly0, 1 ); pnx1 = lkasami_create( deg, poly0, 5 ); /* Apply the offset. */ for( i.h=0, i.l=0; u2long_cmp(i,offset) < 0; u2long_inc(&i) ) { lkasami(pn01); lkasami(pn11); lkasami(pnx1); } acorr0 = acorr1 = xcorr = 0; for ( i.h=0, i.l=0; u2long_cmp(i,pn_size) < 0; u2long_inc(&i) ) { acorr0 += ( lkasami(pn00) == lkasami(pn01) ) ? +1 : -1; acorr1 += ( lkasami(pn10) == lkasami(pn11) ) ? +1 : -1; xcorr += ( lkasami(pnx0) == lkasami(pnx1) ) ? +1 : -1; } printf("%08lx:%08lx %10ld %10ld %10ld\n", offset.h, offset.l, acorr0, acorr1, xcorr ); lkasami_free(pn00); lkasami_free(pn01); lkasami_free(pn10); lkasami_free(pn10); lkasami_free(pnx0); lkasami_free(pnx1); } puts(""); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -