/* * Copyright (c) 2019-2020, Dmitry (DiSlord) dislordlive@gmail.com * Based on TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com * All rights reserved. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3, or (at your option) * any later version. * * The software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, * Boston, MA 02110-1301, USA. */ #include "nanovna.h" #ifdef USE_VARIABLE_OFFSET static int16_t sincos_tbl[AUDIO_SAMPLES_COUNT][2]; void generate_DSP_Table(int offset){ float audio_freq = AUDIO_ADC_FREQ; // N = offset * AUDIO_SAMPLES_COUNT / audio_freq; should be integer // AUDIO_SAMPLES_COUNT = N * audio_freq / offset; N - minimum integer value for get integer AUDIO_SAMPLES_COUNT // Bandwidth on one step = audio_freq / AUDIO_SAMPLES_COUNT float step = offset / audio_freq; float w = step/2; for (int i=0; i>4); // acc_samp_c+= (int32_t)(samp_c>>4); // acc_ref_s += (int32_t)( ref_s>>4); // acc_ref_c += (int32_t)( ref_c>>4); } #endif void calculate_gamma(float *gamma) { // calculate reflection coeff. by samp divide by ref #if 0 measure_t rs = acc_ref_s; measure_t rc = acc_ref_c; measure_t rr = rs * rs + rc * rc; measure_t ss = acc_samp_s; measure_t sc = acc_samp_c; gamma[0] = (sc * rc + ss * rs) / rr; gamma[1] = (ss * rc - sc * rs) / rr; #else measure_t rs_rc = (measure_t) acc_ref_s / acc_ref_c; measure_t sc_rc = (measure_t)acc_samp_c / acc_ref_c; measure_t ss_rc = (measure_t)acc_samp_s / acc_ref_c; measure_t rr = rs_rc * rs_rc + 1.0f; gamma[0] = (sc_rc + ss_rc * rs_rc) / rr; gamma[1] = (ss_rc - sc_rc * rs_rc) / rr; #endif } void fetch_amplitude(float *gamma) { gamma[0] = acc_samp_s * 1e-9; gamma[1] = acc_samp_c * 1e-9; } void fetch_amplitude_ref(float *gamma) { gamma[0] = acc_ref_s * 1e-9; gamma[1] = acc_ref_c * 1e-9; } void reset_dsp_accumerator(void) { acc_ref_s = 0; acc_ref_c = 0; acc_samp_s = 0; acc_samp_c = 0; }