diff --git a/build.rs b/build.rs index e7dcf5b18a34ba186d08d37db7393a491b40a7c1..ddb0e6d3b54039cfc385696c53c4032d42c300f4 100644 --- a/build.rs +++ b/build.rs @@ -3,6 +3,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { println!("cargo:rerun-if-changed=src/codec2/fsk.c"); println!("cargo:rerun-if-changed=src/codec2/mpdecode_core.c"); + println!("cargo:rerun-if-changed=src/codec2/kiss_fft.c"); + println!("cargo:rerun-if-changed=src/codec2/kiss_fftr.c"); + println!("cargo:rerun-if-changed=src/codec2/modem_probe.c"); + println!("cargo:rerun-if-changed=src/codec2/modem_stats.c"); cc::Build::new() .file("src/codec2/fsk.c") @@ -11,7 +15,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { .file("src/codec2/kiss_fftr.c") .file("src/codec2/modem_probe.c") .file("src/codec2/modem_stats.c") - .file("src/codec2/octave.c") .extra_warnings(false) .compile("fsk"); diff --git a/src/codec2/modem_probe.c b/src/codec2/modem_probe.c index d74039f4926c3d5167f71466d47d5a4d51656952..fb7c75e212bc81e8239e3669e493d78cd26d7322 100644 --- a/src/codec2/modem_probe.c +++ b/src/codec2/modem_probe.c @@ -32,7 +32,6 @@ #include <string.h> #include "comp.h" -#include "octave.h" #define TRACE_I 1 #define TRACE_F 2 @@ -95,43 +94,6 @@ void *gather_data(datlink *d, size_t *len) { return newbuf; } -/* Dump all of the traces into a nice octave-able dump file */ -void modem_probe_close_int() { - if (run == NULL) return; - - probe_trace_info *cur, *next; - cur = first_trace; - FILE *dumpfile = fopen(run, "w"); - void *dbuf; - size_t len; - - while (cur != NULL) { - dbuf = gather_data(cur->data, &len); - switch (cur->type) { - case TRACE_I: - octave_save_int(dumpfile, cur->name, (int32_t *)dbuf, 1, - len / sizeof(int32_t)); - break; - case TRACE_F: - octave_save_float(dumpfile, cur->name, (float *)dbuf, 1, - len / sizeof(float), 10); - break; - case TRACE_C: - octave_save_complex(dumpfile, cur->name, (COMP *)dbuf, 1, - len / sizeof(COMP), 10); - break; - } - next = cur->next; - free(cur); - free(dbuf); - cur = next; - } - - fclose(dumpfile); - free(run); - free(mod); -} - /* Look up or create a trace by name */ probe_trace_info *modem_probe_get_trace(char *tracename) { probe_trace_info *cur, *npti; diff --git a/src/codec2/mpdecode_core.c b/src/codec2/mpdecode_core.c index 22f9e9a9f82c113cab414f2ae2b4f0a813250897..2795dc672616e6c3bb19ffcccc4969a25e4bb341 100644 --- a/src/codec2/mpdecode_core.c +++ b/src/codec2/mpdecode_core.c @@ -55,59 +55,6 @@ struct v_node { float initial_value; struct v_sub_node *subs; }; - -void encode(struct LDPC *ldpc, unsigned char ibits[], unsigned char pbits[]) { - unsigned int p, i, tmp, par, prev = 0; - int ind; - uint16_t *H_rows = ldpc->H_rows; - - for (p = 0; p < ldpc->NumberParityBits; p++) { - par = 0; - - for (i = 0; i < ldpc->max_row_weight; i++) { - ind = H_rows[p + i * ldpc->NumberParityBits]; - if (ind) par = par + ibits[ind - 1]; - } - - tmp = par + prev; - - tmp &= 1; // only retain the lsb - prev = tmp; - pbits[p] = tmp; - } -} - -#ifdef USE_ORIGINAL_PHI0 -/* Phi function */ -static float phi0(float x) { - float z; - - if (x > 10) - return (0); - else if (x < 9.08e-5) - return (10); - else if (x > 9) - return (1.6881e-4); - /* return( 1.4970e-004 ); */ - else if (x > 8) - return (4.5887e-4); - /* return( 4.0694e-004 ); */ - else if (x > 7) - return (1.2473e-3); - /* return( 1.1062e-003 ); */ - else if (x > 6) - return (3.3906e-3); - /* return( 3.0069e-003 ); */ - else if (x > 5) - return (9.2168e-3); - /* return( 8.1736e-003 ); */ - else { - z = (float)exp(x); - return ((float)log((z + 1) / (z - 1))); - } -} -#endif - /* Values for linear approximation (DecoderType=5) */ #define AJIAN -0.24904163195436 @@ -130,69 +77,6 @@ static float max_star0(float delta1, float delta2) { return (delta1 - AJIAN * (diff + TJIAN)); } -void sd_to_llr(float llr[], float sd[], int n) { - double sum, mean, sign, sumsq, estvar, estEsN0, x; - int i; - - /* convert SD samples to LLRs -------------------------------*/ - - sum = 0.0; - for (i = 0; i < n; i++) sum += fabs(sd[i]); - mean = sum / n; - - /* find variance from +/-1 symbol position */ - - sum = sumsq = 0.0; - for (i = 0; i < n; i++) { - sign = (sd[i] > 0.0L) - (sd[i] < 0.0L); - x = ((double)sd[i] / mean - sign); - sum += x; - sumsq += x * x; - } - estvar = (n * sumsq - sum * sum) / (n * (n - 1)); - // fprintf(stderr, "mean: %f var: %f\n", mean, estvar); - - estEsN0 = 1.0 / (2.0L * estvar + 1E-3); - for (i = 0; i < n; i++) llr[i] = 4.0L * estEsN0 * sd[i]; -} - -/* - Determine symbol likelihood from received QPSK symbols. - - Notes: - - 1) We assume fading[] is real, it is also possible to compute - with complex fading, see CML library Demod2D.c source code. - 2) Using floats instead of doubles, for stm32. - Testing shows good BERs with floats. -*/ - -void Demod2D(float symbol_likelihood[], /* output, M*number_symbols */ - COMP r[], /* received QPSK symbols, number_symbols */ - COMP S_matrix[], /* constellation of size M */ - float EsNo, - float fading[], /* real fading values, number_symbols */ - float mean_amp, int number_symbols) { - int M = QPSK_CONSTELLATION_SIZE; - int i, j; - float tempsr, tempsi, Er, Ei; - - /* determine output */ - - for (i = 0; i < number_symbols; i++) { /* go through each received symbol */ - for (j = 0; j < M; j++) { /* each postulated symbol */ - tempsr = fading[i] * S_matrix[j].real / mean_amp; - tempsi = fading[i] * S_matrix[j].imag / mean_amp; - Er = r[i].real / mean_amp - tempsr; - Ei = r[i].imag / mean_amp - tempsi; - symbol_likelihood[i * M + j] = -EsNo * (Er * Er + Ei * Ei); - // printf("symbol_likelihood[%d][%d] = %f\n", - // i,j,symbol_likelihood[i*M+j]); - } - // exit(0); - } -} - void Somap(float bit_likelihood[], /* number_bits, bps*number_symbols */ float symbol_likelihood[], /* M*number_symbols */ int M, /* constellation size */ diff --git a/src/codec2/mpdecode_core.h b/src/codec2/mpdecode_core.h index 95ead46056ea057c1b39454529425eecb55cfa4a..af4edc964e237d1985f1309db884a4a172385249 100644 --- a/src/codec2/mpdecode_core.h +++ b/src/codec2/mpdecode_core.h @@ -15,37 +15,6 @@ #include "comp.h" -struct LDPC { - char name[32]; - int max_iter; - int dec_type; - int q_scale_factor; - int r_scale_factor; - int CodeLength; - int NumberParityBits; - int NumberRowsHcols; - int max_row_weight; - int max_col_weight; - - uint16_t *H_rows; - uint16_t *H_cols; - - /* these two are fixed to code params */ - int ldpc_data_bits_per_frame; - int ldpc_coded_bits_per_frame; - - /* support for partial use of data bits in codeword and unequal protection - * schemes */ - int protection_mode; - int data_bits_per_frame; - int coded_bits_per_frame; -}; - -void encode(struct LDPC *ldpc, unsigned char ibits[], unsigned char pbits[]); - -int run_ldpc_decoder(struct LDPC *ldpc, uint8_t out_char[], float input[], - int *parityCheckCount); - void sd_to_llr(float llr[], float sd[], int n); void Demod2D(float symbol_likelihood[], COMP r[], COMP S_matrix[], float EsNo, float fading[], float mean_amp, int number_symbols); @@ -56,6 +25,4 @@ void symbols_to_llrs(float llr[], COMP rx_qpsk_symbols[], float rx_amps[], void fsk_rx_filt_to_llrs(float llr[], float rx_filt[], float v_est, float SNRest, int M, int nsyms); -void ldpc_print_info(struct LDPC *ldpc); - #endif diff --git a/src/codec2/octave.c b/src/codec2/octave.c deleted file mode 100644 index c57bae14712505335f16f225100abac3041b2936..0000000000000000000000000000000000000000 --- a/src/codec2/octave.c +++ /dev/null @@ -1,141 +0,0 @@ -/*---------------------------------------------------------------------------*\ - - FILE........: octave.c - AUTHOR......: David Rowe - DATE CREATED: April 28 2012 - - Functions to save C arrays in GNU Octave matrix format. The output text - file can be directly read into Octave using "load filename". - -\*---------------------------------------------------------------------------*/ - -/* - Copyright (C) 2012 David Rowe - - All rights reserved. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1, as - published by the Free Software Foundation. This program 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 Lesser General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "octave.h" - -#include <stdarg.h> -#include <stdio.h> - -#ifdef ARM_MATH_CM4 -#include "Trace.h" -#endif - -#define OCTAVE_BUFSIZE 2048 - -void flush_buffer(FILE* f, char* buffer, size_t* buf_idx_ptr) { -#ifdef ARM_MATH_CM4 - trace_write(buffer, *buf_idx_ptr); -#else - fwrite(buffer, *buf_idx_ptr, 1, f); -#endif - *buf_idx_ptr = 0; -} - -void handle_buffer(FILE* f, char* buffer, const size_t max_buf, - size_t* buf_idx_ptr, size_t l) { - *buf_idx_ptr += l; - if (*buf_idx_ptr > max_buf - 64) { - flush_buffer(f, buffer, buf_idx_ptr); - } -} - -signed int printf_buffer(FILE* f, char* buffer, const size_t max_buf, - size_t* buf_idx_ptr, const char* pFormat, ...) { - va_list ap; - signed int rc; - - va_start(ap, pFormat); - rc = vsnprintf(&buffer[*buf_idx_ptr], max_buf - *buf_idx_ptr, pFormat, ap); - va_end(ap); - if (rc > 0) { - handle_buffer(f, buffer, max_buf, buf_idx_ptr, rc); - } - return rc; -} - -void printf_header(FILE* f, char* buffer, const size_t max_buf, - size_t* buf_idx_ptr, const char* name, const char* dtype, - int rows, int cols, int isFloat) { -#ifdef ARM_MATH_CM4 - printf_buffer(f, buffer, OCTAVE_BUFSIZE, buf_idx_ptr, "# hex: %s\n", - isFloat ? "true" : "false"); -#endif - printf_buffer(f, buffer, OCTAVE_BUFSIZE, buf_idx_ptr, "# name: %s\n", name); - printf_buffer(f, buffer, OCTAVE_BUFSIZE, buf_idx_ptr, "# type: %s\n", dtype); - printf_buffer(f, buffer, OCTAVE_BUFSIZE, buf_idx_ptr, "# rows: %d\n", rows); - printf_buffer(f, buffer, OCTAVE_BUFSIZE, buf_idx_ptr, "# columns: %d\n", - cols); -} -void octave_save_int(FILE* f, char name[], int data[], int rows, int cols) { - int r, c; - char buffer[OCTAVE_BUFSIZE]; - size_t buf_idx = 0; - - printf_header(f, buffer, OCTAVE_BUFSIZE, &buf_idx, name, "matrix", rows, cols, - 0); - - for (r = 0; r < rows; r++) { - for (c = 0; c < cols; c++) - printf_buffer(f, buffer, OCTAVE_BUFSIZE, &buf_idx, " %d", - data[r * cols + c]); - printf_buffer(f, buffer, OCTAVE_BUFSIZE, &buf_idx, "\n"); - } - - printf_buffer(f, buffer, OCTAVE_BUFSIZE, &buf_idx, "\n\n"); - flush_buffer(f, buffer, &buf_idx); -} - -void octave_save_float(FILE* f, char name[], float data[], int rows, int cols, - int col_len) { - int r, c; - char buffer[OCTAVE_BUFSIZE]; - size_t buf_idx = 0; - - printf_header(f, buffer, OCTAVE_BUFSIZE, &buf_idx, name, "matrix", rows, cols, - 1); - - for (r = 0; r < rows; r++) { - for (c = 0; c < cols; c++) - printf_buffer(f, buffer, OCTAVE_BUFSIZE, &buf_idx, " %f", - data[r * col_len + c]); - printf_buffer(f, buffer, OCTAVE_BUFSIZE, &buf_idx, "\n"); - } - - printf_buffer(f, buffer, OCTAVE_BUFSIZE, &buf_idx, "\n\n"); - flush_buffer(f, buffer, &buf_idx); -} - -void octave_save_complex(FILE* f, char name[], COMP data[], int rows, int cols, - int col_len) { - int r, c; - char buffer[OCTAVE_BUFSIZE]; - size_t buf_idx = 0; - - printf_header(f, buffer, OCTAVE_BUFSIZE, &buf_idx, name, "complex matrix", - rows, cols, 1); - - for (r = 0; r < rows; r++) { - for (c = 0; c < cols; c++) { - printf_buffer(f, buffer, OCTAVE_BUFSIZE, &buf_idx, " (%f,%f)", - data[r * col_len + c].real, data[r * col_len + c].imag); - } - printf_buffer(f, buffer, OCTAVE_BUFSIZE, &buf_idx, "\n"); - } - printf_buffer(f, buffer, OCTAVE_BUFSIZE, &buf_idx, "\n\n"); - flush_buffer(f, buffer, &buf_idx); -} diff --git a/src/codec2/octave.h b/src/codec2/octave.h deleted file mode 100644 index 8ecac9c4bd754c8c0d0b548b9fbad8df1044608a..0000000000000000000000000000000000000000 --- a/src/codec2/octave.h +++ /dev/null @@ -1,42 +0,0 @@ -/*---------------------------------------------------------------------------*\ - - FILE........: octave.h - AUTHOR......: David Rowe - DATE CREATED: April 28 2012 - - Functions to save C arrays in Octave matrix format. the output text - file can be directly read into octave using "load filename". - -\*---------------------------------------------------------------------------*/ - -/* - Copyright (C) 2012 David Rowe - - All rights reserved. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2.1, as - published by the Free Software Foundation. This program 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 Lesser General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef __OCTAVE__ -#define __OCTAVE__ - -#include <stdio.h> - -#include "comp.h" - -void octave_save_int(FILE *f, char name[], int data[], int rows, int cols); -void octave_save_float(FILE *f, char name[], float data[], int rows, int cols, - int col_len); -void octave_save_complex(FILE *f, char name[], COMP data[], int rows, int cols, - int col_len); - -#endif