fdmdv_get_test_bits & fdmdv_mod working, can rx on Octave demod OK
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 1 May 2012 04:26:16 +0000 (04:26 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 1 May 2012 04:26:16 +0000 (04:26 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@387 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/README_fdmdv.txt
codec2-dev/src/Makefile.am
codec2-dev/src/Makefile.in
codec2-dev/src/fdmdv.c
codec2-dev/src/fdmdv_demod.c
codec2-dev/src/fdmdv_get_test_bits.c [new file with mode: 0644]
codec2-dev/src/fdmdv_mod.c

index 8adae6db13a9a4ee32d80ecb7863e7afb374cb1a..459801ccded1bcb23b906f0100fe3fbc11f22e97 100644 (file)
@@ -41,6 +41,16 @@ TODO
     [ ] maybe in ascii art
 [ ] blog posts(s)
 [ ] Codec 2 web page update
+[ ] examples of various combinations of fdmdv demos
+    $ ./fdmdv_get_test_bits test.c2 1400
+    $ ./fdmdv_mod test.c2 test.raw
+    $ play -r 8000 -s -2 test.raw
+    
+    Two seconds of test frame data out of sound device: 
+       $ ./fdmdv_get_test_bits - 2800 | ./fdmdv_mod - - | play -t raw -r 8000 -s -2 -
+
+[ ] PAPR idea
+    + automatically weak phases to reduce PAPR, e.g. slow variations in freq...
 
 Tests
 
index 9658671681e2096bf2745436d4b075a3e5748149..a2230685f02d79c6f10e7a507fb713e55fe7bb8f 100644 (file)
@@ -122,7 +122,7 @@ libcodec2_la_LDFLAGS = $(LIBS)
 library_includedir = $(prefix)/include
 library_include_HEADERS        = codec2.h
 
-bin_PROGRAMS = c2demo c2enc c2dec c2sim fdmdv_mod fdmdv_demod
+bin_PROGRAMS = c2demo c2enc c2dec c2sim fdmdv_get_test_bits fdmdv_mod fdmdv_demod
 
 c2demo_SOURCES = c2demo.c
 c2demo_LDADD = $(lib_LTLIBRARIES) 
@@ -140,6 +140,9 @@ c2sim_SOURCES = c2sim.c
 c2sim_LDADD = $(lib_LTLIBRARIES) 
 c2sim_LDFLAGS = $(LIBS)
 
+fdmdv_get_test_bits_SOURCES = fdmdv_get_test_bits.c fdmdv.c fft.c kiss_fft.c
+fdmdv_get_test_bits_LDFLAGS = $(LIBS)
+
 fdmdv_mod_SOURCES = fdmdv_mod.c fdmdv.c fft.c kiss_fft.c
 fdmdv_mod_LDFLAGS = $(LIBS)
 
index bc5269d6b080b3e7aec72f26f7987f3a9a73ceec..8e3e2d796cb4cbe0bbabbf0fa098ac7e238e1363 100644 (file)
@@ -40,7 +40,8 @@ build_triplet = @build@
 host_triplet = @host@
 noinst_PROGRAMS = generate_codebook$(EXEEXT) genlspdtcb$(EXEEXT)
 bin_PROGRAMS = c2demo$(EXEEXT) c2enc$(EXEEXT) c2dec$(EXEEXT) \
-       c2sim$(EXEEXT) fdmdv_mod$(EXEEXT) fdmdv_demod$(EXEEXT)
+       c2sim$(EXEEXT) fdmdv_get_test_bits$(EXEEXT) fdmdv_mod$(EXEEXT) \
+       fdmdv_demod$(EXEEXT)
 subdir = src
 DIST_COMMON = $(library_include_HEADERS) $(srcdir)/Makefile.am \
        $(srcdir)/Makefile.in
@@ -91,6 +92,10 @@ am_fdmdv_demod_OBJECTS = fdmdv_demod.$(OBJEXT) fdmdv.$(OBJEXT) \
        fft.$(OBJEXT) kiss_fft.$(OBJEXT) octave.$(OBJEXT)
 fdmdv_demod_OBJECTS = $(am_fdmdv_demod_OBJECTS)
 fdmdv_demod_LDADD = $(LDADD)
+am_fdmdv_get_test_bits_OBJECTS = fdmdv_get_test_bits.$(OBJEXT) \
+       fdmdv.$(OBJEXT) fft.$(OBJEXT) kiss_fft.$(OBJEXT)
+fdmdv_get_test_bits_OBJECTS = $(am_fdmdv_get_test_bits_OBJECTS)
+fdmdv_get_test_bits_LDADD = $(LDADD)
 am_fdmdv_mod_OBJECTS = fdmdv_mod.$(OBJEXT) fdmdv.$(OBJEXT) \
        fft.$(OBJEXT) kiss_fft.$(OBJEXT)
 fdmdv_mod_OBJECTS = $(am_fdmdv_mod_OBJECTS)
@@ -114,11 +119,12 @@ LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
        $(AM_LDFLAGS) $(LDFLAGS) -o $@
 SOURCES = $(libcodec2_la_SOURCES) $(c2dec_SOURCES) $(c2demo_SOURCES) \
        $(c2enc_SOURCES) $(c2sim_SOURCES) $(fdmdv_demod_SOURCES) \
-       $(fdmdv_mod_SOURCES) generate_codebook.c genlspdtcb.c
+       $(fdmdv_get_test_bits_SOURCES) $(fdmdv_mod_SOURCES) \
+       generate_codebook.c genlspdtcb.c
 DIST_SOURCES = $(libcodec2_la_SOURCES) $(c2dec_SOURCES) \
        $(c2demo_SOURCES) $(c2enc_SOURCES) $(c2sim_SOURCES) \
-       $(fdmdv_demod_SOURCES) $(fdmdv_mod_SOURCES) \
-       generate_codebook.c genlspdtcb.c
+       $(fdmdv_demod_SOURCES) $(fdmdv_get_test_bits_SOURCES) \
+       $(fdmdv_mod_SOURCES) generate_codebook.c genlspdtcb.c
 library_includeHEADERS_INSTALL = $(INSTALL_HEADER)
 HEADERS = $(library_include_HEADERS)
 ETAGS = etags
@@ -321,6 +327,8 @@ c2dec_LDFLAGS = $(LIBS)
 c2sim_SOURCES = c2sim.c
 c2sim_LDADD = $(lib_LTLIBRARIES) 
 c2sim_LDFLAGS = $(LIBS)
+fdmdv_get_test_bits_SOURCES = fdmdv_get_test_bits.c fdmdv.c fft.c kiss_fft.c
+fdmdv_get_test_bits_LDFLAGS = $(LIBS)
 fdmdv_mod_SOURCES = fdmdv_mod.c fdmdv.c fft.c kiss_fft.c
 fdmdv_mod_LDFLAGS = $(LIBS)
 fdmdv_demod_SOURCES = fdmdv_demod.c fdmdv.c fft.c kiss_fft.c octave.c
@@ -437,6 +445,9 @@ c2sim$(EXEEXT): $(c2sim_OBJECTS) $(c2sim_DEPENDENCIES)
 fdmdv_demod$(EXEEXT): $(fdmdv_demod_OBJECTS) $(fdmdv_demod_DEPENDENCIES) 
        @rm -f fdmdv_demod$(EXEEXT)
        $(LINK) $(fdmdv_demod_LDFLAGS) $(fdmdv_demod_OBJECTS) $(fdmdv_demod_LDADD) $(LIBS)
+fdmdv_get_test_bits$(EXEEXT): $(fdmdv_get_test_bits_OBJECTS) $(fdmdv_get_test_bits_DEPENDENCIES) 
+       @rm -f fdmdv_get_test_bits$(EXEEXT)
+       $(LINK) $(fdmdv_get_test_bits_LDFLAGS) $(fdmdv_get_test_bits_OBJECTS) $(fdmdv_get_test_bits_LDADD) $(LIBS)
 fdmdv_mod$(EXEEXT): $(fdmdv_mod_OBJECTS) $(fdmdv_mod_DEPENDENCIES) 
        @rm -f fdmdv_mod$(EXEEXT)
        $(LINK) $(fdmdv_mod_LDFLAGS) $(fdmdv_mod_OBJECTS) $(fdmdv_mod_LDADD) $(LIBS)
@@ -459,6 +470,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/c2sim.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdmdv.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdmdv_demod.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdmdv_get_test_bits.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdmdv_mod.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fft.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generate_codebook.Po@am__quote@
index 51348920654c695ceae34c5141c269a470c21e12..f0501ddecbfd902ddde936fca179b93b7836d568 100644 (file)
@@ -427,7 +427,9 @@ void fdm_upconvert(COMP tx_fdm[], COMP tx_baseband[NC+1][M], COMP phase_tx[], CO
 
   FDMDV modulator, take a frame of FDMDV_BITS_PER_FRAME bits and
   generates a frame of FDMDV_SAMPLES_PER_FRAME modulated symbols.
-  Sync bit is returned to aid alignment of your next frame.
+  Sync bit is returned to aid alignment of your next frame.  It is the
+  sync_bit (pilot bit) value that will be used for the next frame of
+  mosulatedsamples.
 
 \*---------------------------------------------------------------------------*/
 
index 996d2fea8dc62ca56d8b49170a39cec0b9e7505a..d91715dc368e0d1265ce970e2b9ebc04cb8aa2d4 100644 (file)
@@ -42,9 +42,9 @@
 #define BITS_PER_CODEC_FRAME (2*FDMDV_BITS_PER_FRAME)
 #define BYTES_PER_CODEC_FRAME (BITS_PER_CODEC_FRAME/8)
 
-/* lof of information we want to sump to Octave */
+/* lof of information we want to dump to Octave */
 
-#define MAX_FRAMES 50*60
+#define MAX_FRAMES 50*60 /* 1 minute at 50 symbols/s */
 
 void dump_to_octave(struct FDMDV *fdmdv, FILE *f);
 
diff --git a/codec2-dev/src/fdmdv_get_test_bits.c b/codec2-dev/src/fdmdv_get_test_bits.c
new file mode 100644 (file)
index 0000000..e3120e9
--- /dev/null
@@ -0,0 +1,100 @@
+/*---------------------------------------------------------------------------*\
+                                                                             
+  FILE........: fdmdv_get_test_bits.c
+  AUTHOR......: David Rowe  
+  DATE CREATED: 1 May 2012
+                                                                             
+  Generates a file of packed test bits, useful for input to fdmdv_mod.
+
+\*---------------------------------------------------------------------------*/
+
+
+/*
+  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, 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 <errno.h>
+
+#include "fdmdv.h"
+
+#define BITS_PER_CODEC_FRAME (2*FDMDV_BITS_PER_FRAME)
+#define BYTES_PER_CODEC_FRAME (BITS_PER_CODEC_FRAME/8)
+
+int main(int argc, char *argv[])
+{
+    FILE         *fout;
+    struct FDMDV *fdmdv;
+    char          packed_bits[BYTES_PER_CODEC_FRAME];
+    int           tx_bits[2*FDMDV_BITS_PER_FRAME];
+    int           n, i, bit, byte;
+    int           numBits, nCodecFrames;
+
+    if (argc < 3) {
+       printf("usage: %s OutputBitFile numBits\n", argv[0]);
+       printf("e.g    %s test.c2 1400\n", argv[0]);
+       exit(1);
+    }
+
+    if (strcmp(argv[1], "-") == 0) fout = stdout;
+    else if ( (fout = fopen(argv[1],"wb")) == NULL ) {
+       fprintf(stderr, "Error opening output bit file: %s: %s.\n",
+         argv[1], strerror(errno));
+       exit(1);
+    }
+
+    numBits = atoi(argv[2]);
+    nCodecFrames = numBits/BITS_PER_CODEC_FRAME;
+
+    fdmdv = fdmdv_create();
+
+    for(n=0; n<nCodecFrames; n++) {
+
+       fdmdv_get_test_bits(fdmdv, tx_bits);
+       fdmdv_get_test_bits(fdmdv, &tx_bits[FDMDV_BITS_PER_FRAME]);
+       
+       /* pack bits, MSB received first  */
+
+       bit = 7; byte = 0;
+       memset(packed_bits, 0, BYTES_PER_CODEC_FRAME);
+       for(i=0; i<BITS_PER_CODEC_FRAME; i++) {
+           packed_bits[byte] |= (tx_bits[i] << bit);
+           bit--;
+           if (bit < 0) {
+               bit = 7;
+               byte++;
+           }
+       }
+       assert(byte == BYTES_PER_CODEC_FRAME);
+
+       fwrite(packed_bits, sizeof(char), BYTES_PER_CODEC_FRAME, fout);
+       /* if this is in a pipeline, we probably don't want the usual
+          buffering to occur */
+
+        if (fout == stdout) fflush(stdout);
+    }
+
+    fclose(fout);
+    fdmdv_destroy(fdmdv);
+
+    return 0;
+}
+
index 65732526c8b94b4d3796e119d3df36587eaa3fd6..bce6b53c88a00c8e93514cc3ba3018c677124a7c 100644 (file)
@@ -95,10 +95,10 @@ int main(int argc, char *argv[])
        /* modulate even and odd frames */
 
        fdmdv_mod(fdmdv, tx_fdm, tx_bits, &sync_bit);
-       assert(sync_bit == 0);
+       assert(sync_bit == 1);
 
        fdmdv_mod(fdmdv, &tx_fdm[FDMDV_SAMPLES_PER_FRAME], &tx_bits[FDMDV_BITS_PER_FRAME], &sync_bit);
-       assert(sync_bit == 1);
+       assert(sync_bit == 0);
 
        /* scale and save to disk as shorts */