diff options
author | jcorgan | 2008-04-15 21:31:29 +0000 |
---|---|---|
committer | jcorgan | 2008-04-15 21:31:29 +0000 |
commit | a52f9a19581901beabc9111917965b9817231014 (patch) | |
tree | 5e12980ed7d22dbc8c0f963579e3855b88df5897 /gnuradio-core/src/lib/viterbi/decode.cc | |
parent | 42b48770e756f1c082f5dfc9e757fafe69263496 (diff) | |
download | gnuradio-a52f9a19581901beabc9111917965b9817231014.tar.gz gnuradio-a52f9a19581901beabc9111917965b9817231014.tar.bz2 gnuradio-a52f9a19581901beabc9111917965b9817231014.zip |
Merged r8195:8205 from jcorgan/ecc into trunk. Adds convolutional encoder
and decoder corresponding to the R=1/2, K=7 CCSDS standard ("Voyager").
This code is a GNU Radio wrapper around a 1995-era KA9Q portable-C
implementation, and is designed for continuous streaming data, not packets.
The encoder takes MSB packed bytes and outputs channel symbols 0 or 1.
The decoder uses soft-decision Viterbi decoding on a floating point stream of
(possibly noise corrupted) [1.0, 1.0] symbols, and outputs MSB packed
decoded bytes.
Benchmarking on a 2.16 GHz Intel Core 2 Duo shows 4.7 Mbps decoding rate at
100% CPU usage (single core). (There is a newer KA9Q library that implements
SIMD speed ups with correspondingly faster performance.)
The KA9Q library is placed into src/lib/viterbi. It could use some cleanup,
file/function renaming, and refactoring, or even replacement with the newer
libfec code that is available.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8206 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gnuradio-core/src/lib/viterbi/decode.cc')
-rw-r--r-- | gnuradio-core/src/lib/viterbi/decode.cc | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/gnuradio-core/src/lib/viterbi/decode.cc b/gnuradio-core/src/lib/viterbi/decode.cc new file mode 100644 index 000000000..6580e4d66 --- /dev/null +++ b/gnuradio-core/src/lib/viterbi/decode.cc @@ -0,0 +1,88 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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. + * + * GNU Radio 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. + */ + +/* + * This is a minimal example demonstrating how to call the Viterbi decoder + * in continuous streaming mode. It accepts data on stdin and writes to + * stdout. + * + */ + +extern "C" { +#include "viterbi.h" +} + +#include <cstdio> +#include <cmath> + +#define MAXCHUNKSIZE 4096 +#define MAXENCSIZE MAXCHUNKSIZE*16 + +int main() +{ + unsigned char data[MAXCHUNKSIZE]; + signed char syms[MAXENCSIZE]; + int count = 0; + + // Initialize metric table + int mettab[2][256]; + int amp = 100; + float RATE=0.5; + float ebn0 = 12.0; + float esn0 = RATE*pow(10.0, ebn0/10); + gen_met(mettab, amp, esn0, 0.0, 4); + + // Initialize decoder state + struct viterbi_state state0[64]; + struct viterbi_state state1[64]; + unsigned char viterbi_in[16]; + viterbi_chunks_init(state0); + + while (!feof(stdin)) { + unsigned int n = fread(syms, 1, MAXENCSIZE, stdin); + unsigned char *out = data; + + for (unsigned int i = 0; i < n; i++) { + + // FIXME: This implements hard decoding by slicing the input stream + unsigned char sym = syms[i] > 0 ? -amp : amp; + + // Write the symbol to the decoder input + viterbi_in[count % 4] = sym; + + // Every four symbols, perform the butterfly2 operation + if ((count % 4) == 3) { + viterbi_butterfly2(viterbi_in, mettab, state0, state1); + + // Every sixteen symbols, perform the readback operation + if ((count > 64) && (count % 16) == 11) { + viterbi_get_output(state0, out); + fwrite(out++, 1, 1, stdout); + } + } + + count++; + } + } + + return 0; +} |