1 /*
2 *
3 * Copyright (c) 2005 The Regents of the University of California. All
4 * rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * - Neither the name of the University nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 */
30
31 /*
32 * test program determines max autocorrelation for different seed values
33 */
34
35 #include "ar.h"
36
37 int main(int argc, char **argv)
38 {
39 int i,j;
40 int chirp_len = CHIRP_CHIPS*MOD_FACTOR*RANGE_FACTOR;
41 int test_code = 57;
42
43 int16_t *bpsk = g_new(int16_t,chirp_len);
44 int16_t *bpsk2 = g_new(int16_t,chirp_len);
45 float *f_input;
46 float *f_input2;
47 float *correl;
48 complex *fft_input;
49 complex *fft_input2;
50 complex *fft_correl;
51 f_input = g_new(float,chirp_len);
52 f_input2 = g_new(float,chirp_len);
53 correl = g_new(float,chirp_len);
54 fft_input = g_new(complex,chirp_len);
55 fft_input2 = g_new(complex,chirp_len);
56 fft_correl = g_new(complex,chirp_len);
57
58 /* generate 0 rate */
59 ar_pn_generate_chirp(bpsk2, chirp_len, test_code, 0, 1.0);
60 for (j=0; j<chirp_len; j++)
61 f_input2[j] = (float)bpsk2[j];
62 nl_fft(f_input2, fft_input2, chirp_len);
63
64 for (i=8192-100; i<8192+100; i++) {
65 ar_pn_generate_chirp(bpsk, chirp_len, test_code, 0,
66 i / 8192.0);
67
68 /* convert to float */
69 for (j=0; j<chirp_len; j++)
70 f_input[j] = (float)bpsk[j];
71
72 nl_fft(f_input, fft_input, chirp_len);
73 nl_fd_correl(fft_correl, correl, fft_input, fft_input2, chirp_len);
74
75 int max_ind = 0;
76 float max = 0;
77 for (j=0; j<chirp_len; j++) {
78 if (fabs(correl[j]) > max) {
79 max = fabs(correl[j]);
80 max_ind = j;
81 }
82 }
83
84 int start = (max_ind + 5) % chirp_len;
85 int stop = (max_ind - 5 + chirp_len) % chirp_len;
86
87 float mean = 0;
88 int count = 0;
89 for (j=start; ; ) {
90 if (fabsf(correl[j]) > 300) {
91 mean += correl[j];
92 count++;
93 }
94 j++;
95 if (j == stop) break;
96 if (j == chirp_len) j = 0;
97 }
98 mean /= (float)count;
99
100 float variance = 0;
101 count = 0;
102 for (j=start; ; ) {
103 if (fabsf(correl[j]) > 300) {
104 variance += sqrf((correl[j] - mean));
105 count++;
106 }
107 j++;
108 if (j == stop) break;
109 if (j == chirp_len) j = 0;
110 }
111 variance /= (float)count;
112 float sigma = sqrtf(variance);
113
114 float frac = fabs(correl[max_ind]) / sigma;
115 printf ("%f\t%f\t%f\t%f\t%d\n", i / 8192.0, correl[max_ind], sigma, frac, max_ind);
116
117 if (i == 8192) {
118 fprintf(stderr, "#h correl lc\n");
119 for (j=0; j<chirp_len; j++) {
120 fprintf(stderr, "%f %f\n", correl[j], logf(fabsf(correl[j])));
121 }
122 }
123 }
124
125 return 0;
126 }
127
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.