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