diff options
author | jaseg <git-bigdata-wsl-arch@jaseg.de> | 2020-03-04 17:10:31 +0100 |
---|---|---|
committer | jaseg <git-bigdata-wsl-arch@jaseg.de> | 2020-03-04 17:10:31 +0100 |
commit | d9b26d16c063aec32b70287ff861a1f23642a9f2 (patch) | |
tree | 6259bd8509ea2e442e21c4d68c61098cdf7ae19d /controller/fw/tools/freq_meas_test.c | |
parent | 4d80111cad6891cd0e1d5da59e83222d39933e41 (diff) | |
download | master-thesis-d9b26d16c063aec32b70287ff861a1f23642a9f2.tar.gz master-thesis-d9b26d16c063aec32b70287ff861a1f23642a9f2.tar.bz2 master-thesis-d9b26d16c063aec32b70287ff861a1f23642a9f2.zip |
Fix frequency measurement simulation
Diffstat (limited to 'controller/fw/tools/freq_meas_test.c')
-rw-r--r-- | controller/fw/tools/freq_meas_test.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/controller/fw/tools/freq_meas_test.c b/controller/fw/tools/freq_meas_test.c index 01b4963..df3e39d 100644 --- a/controller/fw/tools/freq_meas_test.c +++ b/controller/fw/tools/freq_meas_test.c @@ -1,4 +1,6 @@ +#include <stdint.h> +#include <math.h> #include <unistd.h> #include <stdio.h> #include <string.h> @@ -13,7 +15,7 @@ void print_usage(void); void print_usage() { - fprintf(stderr, "Usage: freq_meas_test [test_data.bin]"); + fprintf(stderr, "Usage: freq_meas_test [test_data.bin]\n"); } int main(int argc, char **argv) { @@ -46,6 +48,7 @@ int main(int argc, char **argv) { return 2; } + fprintf(stderr, "Reading %zd samples test data...", st.st_size/sizeof(float)); size_t nread = 0; while (nread < st.st_size) { ssize_t rc = read(fd, buf, st.st_size - nread); @@ -54,41 +57,48 @@ int main(int argc, char **argv) { continue; if (rc < 0) { - fprintf(stderr, "Error reading test data: %s\n", strerror(errno)); + fprintf(stderr, "\nError reading test data: %s\n", strerror(errno)); return 2; } if (rc == 0) { - fprintf(stderr, "Error reading test data: Unexpected end of file\n"); + fprintf(stderr, "\nError reading test data: Unexpected end of file\n"); return 2; } nread += rc; } + fprintf(stderr, " done.\n"); size_t n_samples = st.st_size / sizeof(float); float *buf_f = (float *)buf; - uint16_t *sim_adc_buf = calloc(sizeof(uint16_t), n_samples); + int16_t *sim_adc_buf = calloc(sizeof(int16_t), n_samples); if (!sim_adc_buf) { fprintf(stderr, "Error allocating memory\n"); return 2; } + fprintf(stderr, "Converting and truncating test data..."); for (size_t i=0; i<n_samples; i++) - sim_adc_buf[i] = 2048 + buf_f[i] * 2047; + /* Note on scaling: We can't simply scale by 0x8000 (1/2 full range) here. Our test data is nominally 1Vp-p but + * certain tests such as the interharmonics one can have some samples exceeding that range. */ + sim_adc_buf[i] = buf_f[i] * (0x4000-1); + fprintf(stderr, " done.\n"); - for (size_t i=0; i<n_samples; i+=FMEAS_FFT_LEN) { + fprintf(stderr, "Starting simulation.\n"); - float out; - int rc = adc_buf_measure_freq(sim_adc_buf + i, &out); - if (rc) { - fprintf(stderr, "Simulation error in iteration %zd at position %zd: %d\n", i/FMEAS_FFT_LEN, i, rc); - return 3; - } + size_t iterations = (n_samples-FMEAS_FFT_LEN)/(FMEAS_FFT_LEN/2); + for (size_t i=0; i<iterations; i++) { - printf("%09zd %015f\n", i, out); - } + fprintf(stderr, "Iteration %zd/%zd\n", i, iterations); + float res = NAN; + int rc = adc_buf_measure_freq(sim_adc_buf + i*(FMEAS_FFT_LEN/2), &res); + if (rc) + printf("ERROR: Simulation error in iteration %zd at position %zd: %d\n", i, i*(FMEAS_FFT_LEN/2), rc); + printf("%09zd %12f\n", i, res); + } + return 0; } |