📄 poly_phase.c
字号:
/* * $Log: poly_phase.c,v $ * Revision 1.1 2000/05/03 14:30:04 bjc97r * Initial revision * * */char *_poly_phase_id = "$Id: poly_phase.c,v 1.1 2000/05/03 14:30:04 bjc97r Exp $";#include <stdio.h>#include <stdlib.h>#include <math.h>#include "walsh.h"#include "ogold.h"char *PPClass_text[] = { "None", "Zadoff-Chu", "Frank", "OGold", "Walsh", "QOGold", "QWalsh"};char *PPClass_text1 = "nzfowOW";void frank_seq( float phase[], int N, int p ) /* Generate a Frank sequence of length N. The generated code phase sequence is stored in phase[k], k=0..(N-1) sqrt(N) is the order, p is coprime to sqrt(N) */{ int i, j; N = sqrt(N); for( i = 0; i < N; i++ ) { for( j = 0; j < N; j++ ) { phase[i+N*j] = 2.*M_PI/N*((p*i*j)%N); } }}void zadoff_chu_seq( float phase[], int N, int p ) /* Generate a Zadoff-Chu sequence of length N. The generated code phase sequence is stored in phase[k], k=0..(N-1) N is the order, p is coprime to N */{ int i; if (N & 1) { /* Odd N */ for( i = 0; i < N; i++ ) { phase[i] = M_PI/N*p*i*(i+1); } } else { /* Even N */ for( i = 0; i < N; i++ ) { phase[i] = M_PI/N*p*i*i; } }}void circular_shift( float val[], int N, int k ) /* Do a circular shift val[0..(N-1)] by k. */{ int i; float *temp; temp = malloc( N*sizeof(float) ); memcpy( temp, val, N*sizeof(float) ); for( i = 0; i < k; i++ ) val[i] = temp[N-k+i]; for( i = 0; i < (N-k); i++ ) val[k+i] = temp[i]; free(temp);}void circular_shift2( float dest[], float src[], int N, int k ) /* Do a circular shift src[0..(N-1)] by k and store the result at dest[]. */{ int i; for( i = 0; i < k; i++ ) dest[i] = src[N-k+i]; for( i = 0; i < (N-k); i++ ) dest[k+i] = src[i];}void qwalsh( float phase[], int N, int index ) /* Generate quadratic Walsh codes using the reverse sequences as quadrature sequences. N is the size, index is the walsh index */{ int i; Walsh *id; int *code = (int*) malloc( N * sizeof(int) ); float PI1Q = M_PI / 4.; float PI3Q = 3. * M_PI / 4.; id = walsh_create( index, 0); for( i = 0; i < N; i++ ) code[i] = walsh( id ); walsh_free( id ); for( i = 0; i < N; i++ ) { phase[i] = code[i] ? PI1Q : PI3Q; if ( !code[N-i-1] ) phase[i] *= -1.; } free( code );}void qogold( float phase[], int N, int deg, int p0, int p1, int index ) /* Generate quadratic OGold codes using the reverse sequences as quadrature sequences. N is the size, index is the ogold index */{ int i; OGold *id; int *code = (int*) malloc( N * sizeof(int) ); float PI1Q = M_PI / 4.; float PI3Q = 3. * M_PI / 4.; id = ogold_create( (unsigned) deg, (unsigned long)p0, (unsigned long)p1, (unsigned long)index ); for( i = 0; i < N; i++ ) code[i] = ogold( id ); ogold_free( id ); for( i = 0; i < N; i++ ) { phase[i] = code[i] ? PI1Q : PI3Q; if ( !code[N-i-1] ) phase[i] *= -1.; } free( code );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -