FreeCalypso > hg > freecalypso-tools
view rfcal/vcxo-manual/genparams.c @ 221:a46a68500517
rvinterf/Makefile: install include files in /opt/freecalypso/include/rvinterf
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 20 May 2017 20:04:35 +0000 |
parents | 3eb53be9e667 |
children |
line wrap: on
line source
#include <math.h> #include <stdio.h> #include <stdlib.h> #include "meas.h" struct meas meas[4]; float lin_a, lin_b, lin_a2, lin_b2; float dac_min, dac_max, dac_init; float Psi_sta, Psi_st; write_output(filename) char *filename; { FILE *outf; if (filename) { outf = fopen(filename, "w"); if (!outf) { perror(filename); exit(1); } } else outf = stdout; fputs("rf_table afcparams\n\n", outf); /* Psi parameters */ fprintf(outf, "%10u\t# Psi_sta_inv\n", (unsigned)(1.0f / Psi_sta)); fprintf(outf, "%10u\t# Psi_st\n", (unsigned)(Psi_st * 65536.0f)); fprintf(outf, "%10u\t# Psi_st_32\n", (unsigned)(Psi_st * 65536.0f * 65536.0f)); fprintf(outf, "%10u\t# Psi_st_inv\n\n", (unsigned)(1.0f / Psi_st)); /* DAC settings */ fprintf(outf, "%10d\t# DAC_INIT * 8\n", (int)(dac_init * 8.0f)); fprintf(outf, "%10d\t# DAC_MIN * 8\n", (int)(dac_min * 8.0f)); fprintf(outf, "%10d\t# DAC_MAX * 8\n", (int)(dac_max * 8.0f)); fprintf(outf, "%10d\t# snr_thr\n", 2560); /* rfpw 10 setting in a comment line */ fprintf(outf, "\n# DAC_INIT: rfpw 10 %d\n", (int)dac_init); if (filename) fclose(outf); } main(argc, argv) char **argv; { if (argc < 2 || argc > 3) { fprintf(stderr, "usage: %s meas-file [outfile]\n", argv[0]); exit(1); } read_meas_file(argv[1], meas, 4); /* first linear approximation */ lin_a = (float)(meas[1].freq_offset - meas[0].freq_offset) / (float)(meas[1].dac_value - meas[0].dac_value); lin_b = (float)meas[1].freq_offset - lin_a * meas[1].dac_value; /* second linear approximation */ lin_a2 = (float)(meas[3].freq_offset - meas[2].freq_offset) / (float)(meas[3].dac_value - meas[2].dac_value); lin_b2 = (float)meas[3].freq_offset - lin_a2 * meas[3].dac_value; /* DAC settings */ dac_min = (-13500.0f - lin_b) / lin_a; dac_max = (13500.0f - lin_b) / lin_a; dac_init = -lin_b2 / lin_a2; /* Psi computations */ Psi_sta = 2.0f * (float)M_PI * (float)(meas[1].freq_offset - meas[0].freq_offset) / ((float)(meas[1].dac_value - meas[0].dac_value) * 270833.0f); Psi_st = Psi_sta * 0.8f; /* spit it all out */ write_output(argv[2]); exit(0); }