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