3 * Copyright 2008 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
24 * This is a minimal example demonstrating how to call the Viterbi decoder
25 * in continuous streaming mode. It accepts data on stdin and writes to
37 #define MAXCHUNKSIZE 4096
38 #define MAXENCSIZE MAXCHUNKSIZE*16
42 unsigned char data[MAXCHUNKSIZE];
43 signed char syms[MAXENCSIZE];
46 // Initialize metric table
51 float esn0 = RATE*pow(10.0, ebn0/10);
52 gen_met(mettab, amp, esn0, 0.0, 4);
54 // Initialize decoder state
55 struct viterbi_state state0[64];
56 struct viterbi_state state1[64];
57 unsigned char viterbi_in[16];
58 viterbi_chunks_init(state0);
60 while (!feof(stdin)) {
61 unsigned int n = fread(syms, 1, MAXENCSIZE, stdin);
62 unsigned char *out = data;
64 for (unsigned int i = 0; i < n; i++) {
66 // FIXME: This implements hard decoding by slicing the input stream
67 unsigned char sym = syms[i] > 0 ? -amp : amp;
69 // Write the symbol to the decoder input
70 viterbi_in[count % 4] = sym;
72 // Every four symbols, perform the butterfly2 operation
73 if ((count % 4) == 3) {
74 viterbi_butterfly2(viterbi_in, mettab, state0, state1);
76 // Every sixteen symbols, perform the readback operation
77 if ((count > 64) && (count % 16) == 11) {
78 viterbi_get_output(state0, out);
79 fwrite(out++, 1, 1, stdout);