FreeCalypso > hg > fc-rfcal-tools
annotate vcxo-manual/genparams.c @ 0:bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 20 May 2017 18:49:35 +0000 |
parents | |
children |
rev | line source |
---|---|
0
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <math.h> |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <stdio.h> |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <stdlib.h> |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include "meas.h" |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 struct meas meas[4]; |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 float lin_a, lin_b, lin_a2, lin_b2; |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 float dac_min, dac_max, dac_init; |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 float Psi_sta, Psi_st; |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 write_output(filename) |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 char *filename; |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 { |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 FILE *outf; |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 if (filename) { |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 outf = fopen(filename, "w"); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 if (!outf) { |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 perror(filename); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 exit(1); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 } |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 } else |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 outf = stdout; |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 fputs("rf_table afcparams\n\n", outf); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 /* Psi parameters */ |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 fprintf(outf, "%10u\t# Psi_sta_inv\n", (unsigned)(1.0f / Psi_sta)); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 fprintf(outf, "%10u\t# Psi_st\n", (unsigned)(Psi_st * 65536.0f)); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 fprintf(outf, "%10u\t# Psi_st_32\n", |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 (unsigned)(Psi_st * 65536.0f * 65536.0f)); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 fprintf(outf, "%10u\t# Psi_st_inv\n\n", (unsigned)(1.0f / Psi_st)); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 /* DAC settings */ |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 fprintf(outf, "%10d\t# DAC_INIT * 8\n", (int)(dac_init * 8.0f)); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 fprintf(outf, "%10d\t# DAC_MIN * 8\n", (int)(dac_min * 8.0f)); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 fprintf(outf, "%10d\t# DAC_MAX * 8\n", (int)(dac_max * 8.0f)); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 fprintf(outf, "%10d\t# snr_thr\n", 2560); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 /* rfpw 10 setting in a comment line */ |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 fprintf(outf, "\n# DAC_INIT: rfpw 10 %d\n", (int)dac_init); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (filename) |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 fclose(outf); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 main(argc, argv) |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 char **argv; |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 { |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (argc < 2 || argc > 3) { |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 fprintf(stderr, "usage: %s meas-file [outfile]\n", argv[0]); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(1); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 read_meas_file(argv[1], meas, 4); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 /* first linear approximation */ |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 lin_a = (float)(meas[1].freq_offset - meas[0].freq_offset) / |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 (float)(meas[1].dac_value - meas[0].dac_value); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 lin_b = (float)meas[1].freq_offset - lin_a * meas[1].dac_value; |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 /* second linear approximation */ |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 lin_a2 = (float)(meas[3].freq_offset - meas[2].freq_offset) / |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 (float)(meas[3].dac_value - meas[2].dac_value); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 lin_b2 = (float)meas[3].freq_offset - lin_a2 * meas[3].dac_value; |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 /* DAC settings */ |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 dac_min = (-13500.0f - lin_b) / lin_a; |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 dac_max = (13500.0f - lin_b) / lin_a; |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 dac_init = -lin_b2 / lin_a2; |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 /* Psi computations */ |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 Psi_sta = 2.0f * (float)M_PI * |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 (float)(meas[1].freq_offset - meas[0].freq_offset) / |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 ((float)(meas[1].dac_value - meas[0].dac_value) * 270833.0f); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 Psi_st = Psi_sta * 0.8f; |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 /* spit it all out */ |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 write_output(argv[2]); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 exit(0); |
bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 } |