first pass at tofdm.c
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 11 Jun 2017 22:14:09 +0000 (22:14 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 11 Jun 2017 22:14:09 +0000 (22:14 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3170 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/unittest/CMakeLists.txt
codec2-dev/unittest/tofdm.c [new file with mode: 0644]

index c358f0443b8eeaf8936498588e660fc931088716..c45706ca896588449241fdb7f6de4f5e393a5051 100644 (file)
@@ -13,12 +13,6 @@ target_link_libraries(extract codec2)
 add_executable(vqtrain vqtrain.c)
 target_link_libraries(vqtrain codec2)
 
-add_executable(genphdata genphdata.c)
-target_link_libraries(genphdata codec2)
-
-add_executable(genampdata genampdata.c)
-target_link_libraries(genampdata codec2)
-
 add_executable(polar2rect polar2rect.c)
 target_link_libraries(polar2rect codec2)
 
@@ -30,9 +24,6 @@ set(CODEBOOKS ../src/codebook.c ../src/codebookd.c ../src/codebookvq.c ../src/co
 add_executable(tnlp tnlp.c ../src/sine.c ../src/nlp.c ../src/kiss_fft.c ../src/dump.c)
 target_link_libraries(tnlp codec2)
 
-add_executable(tinterp tinterp.c ../src/sine.c ../src/kiss_fft.c ../src/interp.c ../src/lpc.c ../src/lsp.c ../src/quantise.c ${CODEBOOKS} ../src/dump.c)
-target_link_libraries(tinterp codec2)
-
 add_executable(tquant tquant.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/kiss_fft.c ${CODEBOOKS})
 target_link_libraries(tquant codec2)
 
@@ -63,15 +54,15 @@ target_link_libraries(tfmfsk m)
 add_executable(tdeframer tdeframer.c)
 target_link_libraries(tdeframer m codec2)
 
+add_executable(tofdm tofdm.c ../src/ofdm.c ../src/octave.c)
+target_link_libraries(tofdm m)
+
 add_executable(tfreedv_data_channel tfreedv_data_channel.c)
 target_link_libraries(tfreedv_data_channel codec2)
 
 add_executable(create_interleaver create_interleaver.c)
 target_link_libraries(create_interleaver codec2)
 
-add_executable(tlspsens tlspsens.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/kiss_fft.c ../src/codec2.c ../src/sine.c ../src/nlp.c ../src/pack.c ../src/interp.c ../src/postfilter.c ../src/phase.c ${CODEBOOKS})
-target_link_libraries(tlspsens codec2)
-
 add_executable(tprede tprede.c ../src/lpc.c)
 target_link_libraries(tprede codec2)
 
diff --git a/codec2-dev/unittest/tofdm.c b/codec2-dev/unittest/tofdm.c
new file mode 100644 (file)
index 0000000..b1fdb35
--- /dev/null
@@ -0,0 +1,103 @@
+/*---------------------------------------------------------------------------*\
+
+  FILE........: tcohpsk.c
+  AUTHORS.....: David Rowe & Steve Sampson
+  DATE CREATED: June 2017
+
+  Tests for the C version of the OFDM modem.  This program
+  outputs a file of Octave vectors that are loaded and automatically
+  tested against the Octave version of the modem by the Octave script
+  tofdm.m
+
+\*---------------------------------------------------------------------------*/
+
+/*
+  Copyright (C) 2017 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, 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 <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <complex.h>
+
+#include "ofdm_internal.h"
+#include "codec2_ofdm.h"
+#include "octave.h"
+#include "test_bits_ofdm.h"
+
+#define FRAMES 10
+
+int main(int argc, char *argv[])
+{
+    struct OFDM   *ofdm;
+    int            tx_bits[OFDM_BITSPERFRAME];    /* one frame of input bits */
+    COMP           tx[OFDM_SAMPLESPERFRAME];      /* one frame of tx samples */
+
+    int            tx_bits_log[OFDM_BITSPERFRAME*FRAMES];
+    COMP           tx_log[OFDM_SAMPLESPERFRAME*FRAMES];
+
+    FILE          *fout;
+    int            i,f;
+
+    ofdm = ofdm_create(); assert(ofdm != NULL);
+
+    /* Main Loop ---------------------------------------------------------------------*/
+
+    for(f=0; f<FRAMES; f++) {
+
+       /* --------------------------------------------------------*\
+                                 Mod
+       \*---------------------------------------------------------*/
+
+        /* todo: add a longer sequence of test bits through
+           ofdm_get/put test bits functin similat to cohpsk/fdmdv */
+
+        ofdm_mod(ofdm, (COMP*)tx, test_bits_ofdm);
+
+        /* tx vector logging */
+
+       memcpy(&tx_bits_log[OFDM_BITSPERFRAME*f], test_bits_ofdm, sizeof(int)*OFDM_BITSPERFRAME);
+       memcpy(&tx_log[OFDM_SAMPLESPERFRAME*f], tx, sizeof(COMP)*OFDM_SAMPLESPERFRAME);
+    }
+
+    /* --------------------------------------------------------*\
+                               Demod
+    \*---------------------------------------------------------*/
+
+    for(f=0; f<FRAMES; f++) {
+        /* todo: run demod and log states as it runs */
+    }
+
+    /*---------------------------------------------------------*\
+               Dump logs to Octave file for evaluation
+                      by tofdm.m Octave script
+    \*---------------------------------------------------------*/
+
+    fout = fopen("tofdm_out.txt","wt");
+    assert(fout != NULL);
+    fprintf(fout, "# Created by tofdm.c\n");
+    octave_save_complex(fout, "W_c", (COMP*)ofdm->W, OFDM_M, OFDM_NC + 2, OFDM_NC + 2);
+    octave_save_int(fout, "tx_bits_log_c", tx_bits_log, 1, OFDM_BITSPERFRAME*FRAMES);
+    octave_save_complex(fout, "tx_log_c", (COMP*)tx_log, 1, OFDM_BITSPERFRAME*FRAMES,  OFDM_SAMPLESPERFRAME*FRAMES);
+    fclose(fout);
+
+    ofdm_destroy(ofdm);
+
+    return 0;
+}
+