diff options
Diffstat (limited to 'gnuradio-core/src/lib/viterbi')
-rw-r--r-- | gnuradio-core/src/lib/viterbi/.gitignore | 6 | ||||
-rw-r--r-- | gnuradio-core/src/lib/viterbi/Makefile.am | 46 | ||||
-rw-r--r-- | gnuradio-core/src/lib/viterbi/decode.cc | 20 | ||||
-rw-r--r-- | gnuradio-core/src/lib/viterbi/encode.cc | 14 | ||||
-rw-r--r-- | gnuradio-core/src/lib/viterbi/metrics.c | 30 | ||||
-rw-r--r-- | gnuradio-core/src/lib/viterbi/tab.c | 8 | ||||
-rw-r--r-- | gnuradio-core/src/lib/viterbi/viterbi.c | 56 | ||||
-rw-r--r-- | gnuradio-core/src/lib/viterbi/viterbi.h | 10 |
8 files changed, 69 insertions, 121 deletions
diff --git a/gnuradio-core/src/lib/viterbi/.gitignore b/gnuradio-core/src/lib/viterbi/.gitignore deleted file mode 100644 index 85bb5cc04..000000000 --- a/gnuradio-core/src/lib/viterbi/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/Makefile -/Makefile.in -/.libs -/.deps -/encode -/decode diff --git a/gnuradio-core/src/lib/viterbi/Makefile.am b/gnuradio-core/src/lib/viterbi/Makefile.am deleted file mode 100644 index 7e65880b3..000000000 --- a/gnuradio-core/src/lib/viterbi/Makefile.am +++ /dev/null @@ -1,46 +0,0 @@ -# -# Copyright 2008 Free Software Foundation, Inc. -# -# 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. -# - -include $(top_srcdir)/Makefile.common - -LIBS = -lm - -AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(GRUEL_INCLUDES) \ - -I$(top_srcdir)/gnuradio-core/src/lib/general \ - $(WITH_INCLUDES) - -noinst_LTLIBRARIES = libviterbi.la - -libviterbi_la_SOURCES = \ - metrics.c \ - tab.c \ - viterbi.c - -noinst_HEADERS = \ - viterbi.h - -noinst_PROGRAMS = encode decode - -encode_SOURCES = encode.cc - -encode_LDADD = libviterbi.la - -decode_SOURCES = decode.cc - -decode_LDADD = libviterbi.la diff --git a/gnuradio-core/src/lib/viterbi/decode.cc b/gnuradio-core/src/lib/viterbi/decode.cc index 6580e4d66..368e69713 100644 --- a/gnuradio-core/src/lib/viterbi/decode.cc +++ b/gnuradio-core/src/lib/viterbi/decode.cc @@ -1,19 +1,19 @@ /* -*- 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, @@ -22,7 +22,7 @@ /* * This is a minimal example demonstrating how to call the Viterbi decoder - * in continuous streaming mode. It accepts data on stdin and writes to + * in continuous streaming mode. It accepts data on stdin and writes to * stdout. * */ @@ -55,12 +55,12 @@ int main() struct viterbi_state state0[64]; struct viterbi_state state1[64]; unsigned char viterbi_in[16]; - viterbi_chunks_init(state0); + 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 @@ -71,7 +71,7 @@ int main() // Every four symbols, perform the butterfly2 operation if ((count % 4) == 3) { - viterbi_butterfly2(viterbi_in, mettab, state0, state1); + viterbi_butterfly2(viterbi_in, mettab, state0, state1); // Every sixteen symbols, perform the readback operation if ((count > 64) && (count % 16) == 11) { @@ -79,9 +79,9 @@ int main() fwrite(out++, 1, 1, stdout); } } - + count++; - } + } } return 0; diff --git a/gnuradio-core/src/lib/viterbi/encode.cc b/gnuradio-core/src/lib/viterbi/encode.cc index 01acb3987..83a85fcac 100644 --- a/gnuradio-core/src/lib/viterbi/encode.cc +++ b/gnuradio-core/src/lib/viterbi/encode.cc @@ -1,19 +1,19 @@ /* -*- 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, @@ -22,9 +22,9 @@ /* * This is a minimal example demonstrating how to call the ECC encoder - * in continuous streaming mode. It accepts data on stdin and writes to + * in continuous streaming mode. It accepts data on stdin and writes to * stdout. - * + * * FIXME: This does not flush the final bits out of the encoder. * */ @@ -43,7 +43,7 @@ int main() unsigned char encoder_state = 0; unsigned char data[MAXCHUNKSIZE]; unsigned char syms[MAXENCSIZE]; - + while (!feof(stdin)) { unsigned int n = fread(data, 1, MAXCHUNKSIZE, stdin); encoder_state = encode(syms, data, n, encoder_state); diff --git a/gnuradio-core/src/lib/viterbi/metrics.c b/gnuradio-core/src/lib/viterbi/metrics.c index 77c6a63c8..0d91c301f 100644 --- a/gnuradio-core/src/lib/viterbi/metrics.c +++ b/gnuradio-core/src/lib/viterbi/metrics.c @@ -1,26 +1,26 @@ /* * Copyright 1995 Phil Karn, KA9Q * 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. */ -/* +/* * Generate metric tables for a soft-decision convolutional decoder * assuming gaussian noise on a PSK channel. * @@ -48,7 +48,7 @@ extern double erf(double x); /* Normal function integrated from -Inf to x. Range: 0-1 */ #define normal(x) (0.5 + 0.5*erf((x)/M_SQRT2)) -/* Logarithm base 2 */ +/* Logarithm base 2 */ #define gr_log2(x) (log(x)*M_LOG2E) /* Generate log-likelihood metrics for 8-bit soft quantized channel @@ -65,33 +65,33 @@ gen_met(int mettab[2][256], /* Metric table, [sent sym][rx symbol] */ int s,bit; double metrics[2][256]; double p0,p1; - + /* Es/N0 as power ratio */ esn0 = pow(10.,esn0/10); - + noise = 0.5/esn0; /* only half the noise for BPSK */ noise = sqrt(noise); /* noise/signal Voltage ratio */ - + /* Zero is a special value, since this sample includes all * lower samples that were clipped to this value, i.e., it - * takes the whole lower tail of the curve + * takes the whole lower tail of the curve */ p1 = normal(((0-OFFSET+0.5)/amp - 1)/noise); /* P(s|1) */ - + /* Prob of this value occurring for a 0-bit */ /* P(s|0) */ p0 = normal(((0-OFFSET+0.5)/amp + 1)/noise); metrics[0][0] = gr_log2(2*p0/(p1+p0)) - bias; metrics[1][0] = gr_log2(2*p1/(p1+p0)) - bias; - + for(s=1;s<255;s++){ /* P(s|1), prob of receiving s given 1 transmitted */ p1 = normal(((s-OFFSET+0.5)/amp - 1)/noise) - normal(((s-OFFSET-0.5)/amp - 1)/noise); - + /* P(s|0), prob of receiving s given 0 transmitted */ p0 = normal(((s-OFFSET+0.5)/amp + 1)/noise) - normal(((s-OFFSET-0.5)/amp + 1)/noise); - + #ifdef notdef printf("P(%d|1) = %lg, P(%d|0) = %lg\n",s,p1,s,p0); #endif @@ -103,7 +103,7 @@ gen_met(int mettab[2][256], /* Metric table, [sent sym][rx symbol] */ p1 = 1 - normal(((255-OFFSET-0.5)/amp - 1)/noise); /* P(s|0) */ p0 = 1 - normal(((255-OFFSET-0.5)/amp + 1)/noise); - + metrics[0][255] = gr_log2(2*p0/(p1+p0)) - bias; metrics[1][255] = gr_log2(2*p1/(p1+p0)) - bias; #ifdef notdef diff --git a/gnuradio-core/src/lib/viterbi/tab.c b/gnuradio-core/src/lib/viterbi/tab.c index 1133c6308..1c135acfe 100644 --- a/gnuradio-core/src/lib/viterbi/tab.c +++ b/gnuradio-core/src/lib/viterbi/tab.c @@ -1,19 +1,19 @@ /* * Copyright 1995 Phil Karn, KA9Q * 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, diff --git a/gnuradio-core/src/lib/viterbi/viterbi.c b/gnuradio-core/src/lib/viterbi/viterbi.c index 9f5c1e72a..fc8886603 100644 --- a/gnuradio-core/src/lib/viterbi/viterbi.c +++ b/gnuradio-core/src/lib/viterbi/viterbi.c @@ -1,26 +1,26 @@ /* * Copyright 1995 Phil Karn, KA9Q * 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. */ -/* +/* * Viterbi decoder for K=7 rate=1/2 convolutional code * Some modifications from original Karn code by Matt Ettus */ @@ -94,7 +94,7 @@ encode(unsigned char *symbols, unsigned char encstate) { int i; - + while(nbytes-- != 0){ for(i=7;i>=0;i--){ encstate = (encstate << 1) | ((*data >> i) & 1); @@ -103,7 +103,7 @@ encode(unsigned char *symbols, } data++; } - + return encstate; } @@ -120,16 +120,16 @@ viterbi(unsigned long *metric, /* Final path metric (returned value) */ long bestmetric; int beststate,i; struct viterbi_state state0[64],state1[64],*state,*next; - + state = state0; next = state1; - + /* Initialize starting metrics to prefer 0 state */ state[0].metric = 0; for(i=1;i<64;i++) state[i].metric = -999999; state[0].path = 0; - + for(bitcnt = 0;bitcnt < nbits;bitcnt++){ /* Read input symbol pair and compute all possible branch * metrics @@ -173,7 +173,7 @@ viterbi(unsigned long *metric, /* Final path metric (returned value) */ BUTTERFLY(29,0); BUTTERFLY(30,2); BUTTERFLY(31,3); - + /* Swap current and next states */ if(bitcnt & 1){ state = state0; @@ -205,7 +205,7 @@ viterbi(unsigned long *metric, /* Final path metric (returned value) */ #endif *data++ = state[beststate].path >> 24; } - + } /* Output remaining bits from 0 state */ // ETTUS Find best state instead @@ -219,7 +219,7 @@ viterbi(unsigned long *metric, /* Final path metric (returned value) */ } if((i = bitcnt % 8) != 6) state[beststate].path <<= 6-i; - + *data++ = state[beststate].path >> 24; *data++ = state[beststate].path >> 16; *data++ = state[beststate].path >> 8; @@ -245,7 +245,7 @@ viterbi_butterfly8(unsigned char *symbols, int mettab[2][256], struct viterbi_st { unsigned int bitcnt; int mets[4]; - + struct viterbi_state *state, *next; state = state0; next = state1; @@ -257,8 +257,8 @@ viterbi_butterfly8(unsigned char *symbols, int mettab[2][256], struct viterbi_st mets[2] = mettab[1][symbols[0]] + mettab[0][symbols[1]]; mets[3] = mettab[1][symbols[0]] + mettab[1][symbols[1]]; symbols += 2; - - // These macro calls were generated by genbut.c + + // These macro calls were generated by genbut.c BUTTERFLY(0,0);BUTTERFLY(1,1);BUTTERFLY(2,3);BUTTERFLY(3,2); BUTTERFLY(4,3);BUTTERFLY(5,2);BUTTERFLY(6,0);BUTTERFLY(7,1); BUTTERFLY(8,0);BUTTERFLY(9,1);BUTTERFLY(10,3);BUTTERFLY(11,2); @@ -267,7 +267,7 @@ viterbi_butterfly8(unsigned char *symbols, int mettab[2][256], struct viterbi_st BUTTERFLY(20,1);BUTTERFLY(21,0);BUTTERFLY(22,2);BUTTERFLY(23,3); BUTTERFLY(24,2);BUTTERFLY(25,3);BUTTERFLY(26,1);BUTTERFLY(27,0); BUTTERFLY(28,1);BUTTERFLY(29,0);BUTTERFLY(30,2);BUTTERFLY(31,3); - + // Swap current and next states if(bitcnt & 1){ state = state0; @@ -284,19 +284,19 @@ viterbi_butterfly2(unsigned char *symbols, int mettab[2][256], struct viterbi_st { //unsigned int bitcnt; int mets[4]; - + struct viterbi_state *state, *next; state = state0; next = state1; // Operate on 4 symbols (2 bits) at a time - + // Read input symbol pair and compute all possible branch metrics mets[0] = mettab[0][symbols[0]] + mettab[0][symbols[1]]; mets[1] = mettab[0][symbols[0]] + mettab[1][symbols[1]]; mets[2] = mettab[1][symbols[0]] + mettab[0][symbols[1]]; mets[3] = mettab[1][symbols[0]] + mettab[1][symbols[1]]; - - // These macro calls were generated by genbut.c + + // These macro calls were generated by genbut.c BUTTERFLY(0,0);BUTTERFLY(1,1);BUTTERFLY(2,3);BUTTERFLY(3,2); BUTTERFLY(4,3);BUTTERFLY(5,2);BUTTERFLY(6,0);BUTTERFLY(7,1); BUTTERFLY(8,0);BUTTERFLY(9,1);BUTTERFLY(10,3);BUTTERFLY(11,2); @@ -305,17 +305,17 @@ viterbi_butterfly2(unsigned char *symbols, int mettab[2][256], struct viterbi_st BUTTERFLY(20,1);BUTTERFLY(21,0);BUTTERFLY(22,2);BUTTERFLY(23,3); BUTTERFLY(24,2);BUTTERFLY(25,3);BUTTERFLY(26,1);BUTTERFLY(27,0); BUTTERFLY(28,1);BUTTERFLY(29,0);BUTTERFLY(30,2);BUTTERFLY(31,3); - + state = state1; next = state0; - + // Read input symbol pair and compute all possible branch metrics mets[0] = mettab[0][symbols[2]] + mettab[0][symbols[3]]; mets[1] = mettab[0][symbols[2]] + mettab[1][symbols[3]]; mets[2] = mettab[1][symbols[2]] + mettab[0][symbols[3]]; mets[3] = mettab[1][symbols[2]] + mettab[1][symbols[3]]; - - // These macro calls were generated by genbut.c + + // These macro calls were generated by genbut.c BUTTERFLY(0,0);BUTTERFLY(1,1);BUTTERFLY(2,3);BUTTERFLY(3,2); BUTTERFLY(4,3);BUTTERFLY(5,2);BUTTERFLY(6,0);BUTTERFLY(7,1); BUTTERFLY(8,0);BUTTERFLY(9,1);BUTTERFLY(10,3);BUTTERFLY(11,2); @@ -328,13 +328,13 @@ viterbi_butterfly2(unsigned char *symbols, int mettab[2][256], struct viterbi_st unsigned char viterbi_get_output(struct viterbi_state *state, unsigned char *outbuf) { - // Produce output every 8 bits once path memory is full + // Produce output every 8 bits once path memory is full // if((bitcnt % 8) == 5 && bitcnt > 32) { - + // Find current best path unsigned int i,beststate; int bestmetric; - + bestmetric = state[0].metric; beststate = 0; for(i=1;i<64;i++) diff --git a/gnuradio-core/src/lib/viterbi/viterbi.h b/gnuradio-core/src/lib/viterbi/viterbi.h index 3a3ea5615..bcdbe116d 100644 --- a/gnuradio-core/src/lib/viterbi/viterbi.h +++ b/gnuradio-core/src/lib/viterbi/viterbi.h @@ -1,18 +1,18 @@ /* * 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, @@ -46,7 +46,7 @@ GR_CORE_API void viterbi_chunks_init(struct viterbi_state* state); GR_CORE_API void -viterbi_butterfly2(unsigned char *symbols, int mettab[2][256], +viterbi_butterfly2(unsigned char *symbols, int mettab[2][256], struct viterbi_state *state0, struct viterbi_state *state1); GR_CORE_API unsigned char |