summaryrefslogtreecommitdiff
path: root/gr-trellis/src
diff options
context:
space:
mode:
Diffstat (limited to 'gr-trellis/src')
-rw-r--r--gr-trellis/src/Makefile.am22
-rw-r--r--gr-trellis/src/lib/Makefile.am97
-rw-r--r--gr-trellis/src/lib/Makefile.gen51
-rw-r--r--gr-trellis/src/lib/build_utils.py193
-rw-r--r--gr-trellis/src/lib/build_utils_codes.py52
-rw-r--r--gr-trellis/src/lib/fsm.cc149
-rw-r--r--gr-trellis/src/lib/fsm.h55
-rw-r--r--gr-trellis/src/lib/fsm.i49
-rw-r--r--gr-trellis/src/lib/generate_all.py33
-rw-r--r--gr-trellis/src/lib/generate_common.py66
-rw-r--r--gr-trellis/src/lib/trellis.i21
-rw-r--r--gr-trellis/src/lib/trellis_calc_metric.cc92
-rw-r--r--gr-trellis/src/lib/trellis_calc_metric.h34
-rw-r--r--gr-trellis/src/lib/trellis_encoder_XX.cc.t76
-rw-r--r--gr-trellis/src/lib/trellis_encoder_XX.h.t59
-rw-r--r--gr-trellis/src/lib/trellis_encoder_XX.i.t36
-rw-r--r--gr-trellis/src/lib/trellis_encoder_bb.cc76
-rw-r--r--gr-trellis/src/lib/trellis_encoder_bb.h59
-rw-r--r--gr-trellis/src/lib/trellis_encoder_bb.i36
-rw-r--r--gr-trellis/src/lib/trellis_encoder_bi.cc76
-rw-r--r--gr-trellis/src/lib/trellis_encoder_bi.h59
-rw-r--r--gr-trellis/src/lib/trellis_encoder_bi.i36
-rw-r--r--gr-trellis/src/lib/trellis_encoder_bs.cc76
-rw-r--r--gr-trellis/src/lib/trellis_encoder_bs.h59
-rw-r--r--gr-trellis/src/lib/trellis_encoder_bs.i36
-rw-r--r--gr-trellis/src/lib/trellis_encoder_ii.cc76
-rw-r--r--gr-trellis/src/lib/trellis_encoder_ii.h59
-rw-r--r--gr-trellis/src/lib/trellis_encoder_ii.i36
-rw-r--r--gr-trellis/src/lib/trellis_encoder_si.cc76
-rw-r--r--gr-trellis/src/lib/trellis_encoder_si.h59
-rw-r--r--gr-trellis/src/lib/trellis_encoder_si.i36
-rw-r--r--gr-trellis/src/lib/trellis_encoder_ss.cc76
-rw-r--r--gr-trellis/src/lib/trellis_encoder_ss.h59
-rw-r--r--gr-trellis/src/lib/trellis_encoder_ss.i36
-rw-r--r--gr-trellis/src/lib/trellis_generated.i34
-rw-r--r--gr-trellis/src/lib/trellis_metric_type.h31
-rw-r--r--gr-trellis/src/lib/trellis_metrics_X.cc.t96
-rw-r--r--gr-trellis/src/lib/trellis_metrics_X.h.t65
-rw-r--r--gr-trellis/src/lib/trellis_metrics_X.i.t39
-rw-r--r--gr-trellis/src/lib/trellis_metrics_c.cc96
-rw-r--r--gr-trellis/src/lib/trellis_metrics_c.h65
-rw-r--r--gr-trellis/src/lib/trellis_metrics_c.i39
-rw-r--r--gr-trellis/src/lib/trellis_metrics_f.cc96
-rw-r--r--gr-trellis/src/lib/trellis_metrics_f.h65
-rw-r--r--gr-trellis/src/lib/trellis_metrics_f.i39
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_X.cc.t167
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_X.h.t78
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_X.i.t49
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_b.cc167
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_b.h78
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_b.i49
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_combined_X.cc.t182
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_combined_X.h.t93
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_combined_X.i.t58
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_combined_b.cc182
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_combined_b.h93
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_combined_b.i58
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_combined_i.cc182
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_combined_i.h93
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_combined_i.i58
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_combined_s.cc182
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_combined_s.h93
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_combined_s.i58
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_i.cc167
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_i.h78
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_i.i49
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_s.cc167
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_s.h78
-rw-r--r--gr-trellis/src/lib/trellis_viterbi_s.i49
-rw-r--r--gr-trellis/src/python/Makefile.am32
-rwxr-xr-xgr-trellis/src/python/qa_trellis.py35
-rw-r--r--gr-trellis/src/python/run_tests.in45
72 files changed, 5396 insertions, 0 deletions
diff --git a/gr-trellis/src/Makefile.am b/gr-trellis/src/Makefile.am
new file mode 100644
index 000000000..122fc72c1
--- /dev/null
+++ b/gr-trellis/src/Makefile.am
@@ -0,0 +1,22 @@
+#
+# Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+
+SUBDIRS = lib python
diff --git a/gr-trellis/src/lib/Makefile.am b/gr-trellis/src/lib/Makefile.am
new file mode 100644
index 000000000..cc8fe3893
--- /dev/null
+++ b/gr-trellis/src/lib/Makefile.am
@@ -0,0 +1,97 @@
+#
+# Copyright 2004,2005,2006 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 2, 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., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+
+include $(top_srcdir)/Makefile.common
+
+include Makefile.gen
+
+# Install this stuff so that it ends up as the gnuradio.trellis module
+# This usually ends up at:
+# ${prefix}/lib/python${python_version}/site-packages/gnuradio
+
+ourpythondir = $(grpythondir)
+ourlibdir = $(grpyexecdir)
+
+INCLUDES = $(STD_DEFINES_AND_INCLUDES) $(PYTHON_CPPFLAGS)
+
+SWIGPYTHONARGS = $(SWIGPYTHONFLAGS) $(STD_DEFINES_AND_INCLUDES)
+
+ALL_IFILES = \
+ $(LOCAL_IFILES) \
+ $(NON_LOCAL_IFILES)
+
+NON_LOCAL_IFILES = \
+ $(top_srcdir)/gnuradio-core/src/lib/swig/gnuradio.i
+
+
+LOCAL_IFILES = \
+ trellis.i
+
+
+# These files are built by SWIG. The first is the C++ glue.
+# The second is the python wrapper that loads the _trellis shared library
+# and knows how to call our extensions.
+
+BUILT_SOURCES = \
+ trellis.cc \
+ trellis.py
+
+# This gets trellis.py installed in the right place
+ourpython_PYTHON = \
+ trellis.py
+
+ourlib_LTLIBRARIES = _trellis.la
+
+# These are the source files that go into the shared library
+_trellis_la_SOURCES = \
+ trellis.cc \
+ fsm.cc \
+ trellis_calc_metric.cc \
+ $(GENERATED_CC)
+
+# magic flags
+_trellis_la_LDFLAGS = -module -avoid-version
+
+# link the library against some comon swig runtime code and the
+# c++ standard library
+_trellis_la_LIBADD = \
+ $(PYTHON_LDFLAGS) \
+ $(GNURADIO_CORE_LIBS) \
+ -lstdc++
+
+trellis.cc trellis.py: trellis.i $(ALL_IFILES)
+ $(SWIG) $(SWIGPYTHONARGS) -module trellis -o trellis.cc $<
+
+# These headers get installed in ${prefix}/include/gnuradio
+grinclude_HEADERS = \
+ fsm.h \
+ trellis_metric_type.h \
+ trellis_calc_metric.h \
+ $(GENERATED_H)
+
+
+# These swig headers get installed in ${prefix}/include/gnuradio/swig
+swiginclude_HEADERS = \
+ $(LOCAL_IFILES)
+
+
+MOSTLYCLEANFILES = $(BUILT_SOURCES) *.pyc
+
diff --git a/gr-trellis/src/lib/Makefile.gen b/gr-trellis/src/lib/Makefile.gen
new file mode 100644
index 000000000..9c0ddf9ea
--- /dev/null
+++ b/gr-trellis/src/lib/Makefile.gen
@@ -0,0 +1,51 @@
+#
+# This file is machine generated. All edits will be overwritten
+#
+GENERATED_H = \
+ trellis_encoder_bb.h \
+ trellis_encoder_bi.h \
+ trellis_encoder_bs.h \
+ trellis_encoder_ii.h \
+ trellis_encoder_si.h \
+ trellis_encoder_ss.h \
+ trellis_metrics_c.h \
+ trellis_metrics_f.h \
+ trellis_viterbi_b.h \
+ trellis_viterbi_combined_b.h \
+ trellis_viterbi_combined_i.h \
+ trellis_viterbi_combined_s.h \
+ trellis_viterbi_i.h \
+ trellis_viterbi_s.h
+
+GENERATED_I = \
+ trellis_encoder_bb.i \
+ trellis_encoder_bi.i \
+ trellis_encoder_bs.i \
+ trellis_encoder_ii.i \
+ trellis_encoder_si.i \
+ trellis_encoder_ss.i \
+ trellis_metrics_c.i \
+ trellis_metrics_f.i \
+ trellis_viterbi_b.i \
+ trellis_viterbi_combined_b.i \
+ trellis_viterbi_combined_i.i \
+ trellis_viterbi_combined_s.i \
+ trellis_viterbi_i.i \
+ trellis_viterbi_s.i
+
+GENERATED_CC = \
+ trellis_encoder_bb.cc \
+ trellis_encoder_bi.cc \
+ trellis_encoder_bs.cc \
+ trellis_encoder_ii.cc \
+ trellis_encoder_si.cc \
+ trellis_encoder_ss.cc \
+ trellis_metrics_c.cc \
+ trellis_metrics_f.cc \
+ trellis_viterbi_b.cc \
+ trellis_viterbi_combined_b.cc \
+ trellis_viterbi_combined_i.cc \
+ trellis_viterbi_combined_s.cc \
+ trellis_viterbi_i.cc \
+ trellis_viterbi_s.cc
+
diff --git a/gr-trellis/src/lib/build_utils.py b/gr-trellis/src/lib/build_utils.py
new file mode 100644
index 000000000..a4e13047b
--- /dev/null
+++ b/gr-trellis/src/lib/build_utils.py
@@ -0,0 +1,193 @@
+#
+# Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+
+"""Misc utilities used at build time
+"""
+
+import re, os, os.path
+from build_utils_codes import *
+
+
+# set srcdir to the directory that contains Makefile.am
+try:
+ srcdir = os.environ['srcdir']
+except KeyError, e:
+ srcdir = "."
+srcdir = srcdir + '/'
+
+
+name_dict = {}
+
+def log_output_name (name):
+ (base, ext) = os.path.splitext (name)
+ ext = ext[1:] # drop the leading '.'
+
+ entry = name_dict.setdefault (ext, [])
+ entry.append (name)
+
+def open_and_log_name (name, dir):
+ f = open (name, dir)
+ log_output_name (name)
+ return f
+
+def expand_template (d, template_filename, extra = ""):
+ '''Given a dictionary D and a TEMPLATE_FILENAME, expand template into output file
+ '''
+ output_extension = extract_extension (template_filename)
+ template = open_src (template_filename, 'r')
+ output_name = d['NAME'] + extra + '.' + output_extension
+ log_output_name (output_name)
+ output = open (output_name, 'w')
+ do_substitution (d, template, output)
+ template.close ()
+ output.close ()
+
+def output_glue (dirname):
+ output_makefile_fragment ()
+ output_ifile_include (dirname)
+
+def output_makefile_fragment ():
+ f = open ('Makefile.gen', 'w')
+ f.write ('#\n# This file is machine generated. All edits will be overwritten\n#\n')
+ output_subfrag (f, 'h')
+ output_subfrag (f, 'i')
+ output_subfrag (f, 'cc')
+ f.close ()
+
+def output_ifile_include (dirname):
+ f = open ('%s_generated.i' % (dirname,), 'w')
+ f.write ('//\n// This file is machine generated. All edits will be overwritten\n//\n')
+ files = name_dict.setdefault ('i', [])
+ files.sort ()
+ f.write ('%{\n')
+ for file in files:
+ f.write ('#include <%s>\n' % (file[0:-1] + 'h',))
+ f.write ('%}\n\n')
+ for file in files:
+ f.write ('%%include <%s>\n' % (file,))
+
+def output_subfrag (f, ext):
+ files = name_dict.setdefault (ext, [])
+ files.sort ()
+ f.write ("GENERATED_%s =" % (ext.upper ()))
+ for file in files:
+ f.write (" \\\n\t%s" % (file,))
+ f.write ("\n\n")
+
+
+def extract_extension (template_name):
+ # template name is something like: GrFIRfilterXXX.h.t
+ # we return everything between the penultimate . and .t
+ mo = re.search (r'\.([a-z]+)\.t$', template_name)
+ if not mo:
+ raise ValueError, "Incorrectly formed template_name '%s'" % (template_name,)
+ return mo.group (1)
+
+def open_src (name, mode):
+ global srcdir
+ return open (os.path.join (srcdir, name), mode)
+
+def do_substitution (d, in_file, out_file):
+ def repl (match_obj):
+ key = match_obj.group (1)
+ # print key
+ return d[key]
+
+ inp = in_file.read ()
+ out = re.sub (r"@([a-zA-Z0-9_]+)@", repl, inp)
+ out_file.write (out)
+
+
+
+copyright = '''/* -*- c++ -*- */
+/*
+ * Copyright 2003,2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+'''
+
+def is_byte (code3):
+ if i_code (code3) == 'b' or o_code (code3) == 'b':
+ return '1'
+ else:
+ return '0'
+
+def is_short (code3):
+ if i_code (code3) == 's' or o_code (code3) == 's':
+ return '1'
+ else:
+ return '0'
+
+def is_int (code3):
+ if i_code (code3) == 'i' or o_code (code3) == 'i':
+ return '1'
+ else:
+ return '0'
+
+def is_float (code3):
+ if i_code (code3) == 'f' or o_code (code3) == 'f':
+ return '1'
+ else:
+ return '0'
+
+def is_complex (code3):
+ if i_code (code3) == 'c' or o_code (code3) == 'c':
+ return '1'
+ else:
+ return '0'
+
+
+
+
+def standard_dict (name, code3):
+ d = {}
+ d['NAME'] = name
+ d['GUARD_NAME'] = 'INCLUDED_%s_H' % name.upper ()
+ d['BASE_NAME'] = re.sub ('^trellis_', '', name)
+ d['SPTR_NAME'] = '%s_sptr' % name
+ d['WARNING'] = 'WARNING: this file is machine generated. Edits will be over written'
+ d['COPYRIGHT'] = copyright
+ d['TYPE'] = i_type (code3)
+ d['I_TYPE'] = i_type (code3)
+ d['O_TYPE'] = o_type (code3)
+ d['TAP_TYPE'] = tap_type (code3)
+ d['IS_BYTE'] = is_byte (code3)
+ d['IS_SHORT'] = is_short (code3)
+ d['IS_INT'] = is_int (code3)
+ d['IS_FLOAT'] = is_float (code3)
+ d['IS_COMPLEX'] = is_complex (code3)
+ return d
diff --git a/gr-trellis/src/lib/build_utils_codes.py b/gr-trellis/src/lib/build_utils_codes.py
new file mode 100644
index 000000000..f4215f2b4
--- /dev/null
+++ b/gr-trellis/src/lib/build_utils_codes.py
@@ -0,0 +1,52 @@
+#
+# Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+
+def i_code (code3):
+ return code3[0]
+
+def o_code (code3):
+ if len (code3) >= 2:
+ return code3[1]
+ else:
+ return code3[0]
+
+def tap_code (code3):
+ if len (code3) >= 3:
+ return code3[2]
+ else:
+ return code3[0]
+
+def i_type (code3):
+ return char_to_type[i_code (code3)]
+
+def o_type (code3):
+ return char_to_type[o_code (code3)]
+
+def tap_type (code3):
+ return char_to_type[tap_code (code3)]
+
+
+char_to_type = {}
+char_to_type['s'] = 'short'
+char_to_type['i'] = 'int'
+char_to_type['f'] = 'float'
+char_to_type['c'] = 'gr_complex'
+char_to_type['b'] = 'unsigned char'
diff --git a/gr-trellis/src/lib/fsm.cc b/gr-trellis/src/lib/fsm.cc
new file mode 100644
index 000000000..05d1589fe
--- /dev/null
+++ b/gr-trellis/src/lib/fsm.cc
@@ -0,0 +1,149 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2002 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <cstdio>
+#include <stdexcept>
+#include <cmath>
+#include "fsm.h"
+
+fsm::fsm()
+{
+ d_I=0;
+ d_S=0;
+ d_O=0;
+ d_NS.resize(0);
+ d_OS.resize(0);
+ d_PS.resize(0);
+ d_PI.resize(0);
+}
+
+fsm::fsm(const fsm &FSM)
+{
+ d_I=FSM.I();
+ d_S=FSM.S();
+ d_O=FSM.O();
+ d_NS=FSM.NS();
+ d_OS=FSM.OS();
+ d_PS=FSM.PS();
+ d_PI=FSM.PI();
+}
+
+fsm::fsm(const int I, const int S, const int O, const std::vector<int> &NS, const std::vector<int> &OS)
+{
+ d_I=I;
+ d_S=S;
+ d_O=O;
+ d_NS=NS;
+ d_OS=OS;
+ d_PS.resize(d_I*d_S);
+ d_PI.resize(d_I*d_S);
+
+ // generate the PS, PI tables for later use
+ for(int i=0;i<d_S;i++) {
+ int j=0;
+ for(int ii=0;ii<d_S;ii++) for(int jj=0;jj<d_I;jj++) {
+ if(d_NS[ii*d_I+jj]!=i) continue;
+ d_PS[i*d_I+j]=ii;
+ d_PI[i*d_I+j]=jj;
+ j++;
+ }
+ }
+}
+
+//######################################################################
+//# Read an FSM specification from a file.
+//# Format (hopefully will become more flexible in the future...):
+//# I S O (in the first line)
+//# blank line
+//# Next state matrix (S lines, each with I integers separated by spaces)
+//# blank line
+//# output symbol matrix (S lines, each with I integers separated by spaces)
+//# optional comments
+//######################################################################
+fsm::fsm(const char *name)
+{
+ FILE *fsmfile;
+
+ if((fsmfile=fopen(name,"r"))==NULL)
+ throw std::runtime_error ("file open error in fsm()");
+ //printf("file open error in fsm()\n");
+
+ fscanf(fsmfile,"%d %d %d\n",&d_I,&d_S,&d_O);
+ d_NS.resize(d_I*d_S);
+ d_OS.resize(d_I*d_S);
+ d_PS.resize(d_I*d_S);
+ d_PI.resize(d_I*d_S);
+
+ for(int i=0;i<d_S;i++) {
+ for(int j=0;j<d_I;j++) fscanf(fsmfile,"%d",&(d_NS[i*d_I+j]));
+ }
+ for(int i=0;i<d_S;i++) {
+ for(int j=0;j<d_I;j++) fscanf(fsmfile,"%d",&(d_OS[i*d_I+j]));
+ }
+
+ // generate the PS, PI tables for later use
+ for(int i=0;i<d_S;i++) {
+ int j=0;
+ for(int ii=0;ii<d_S;ii++) for(int jj=0;jj<d_I;jj++) {
+ if(d_NS[ii*d_I+jj]!=i) continue;
+ d_PS[i*d_I+j]=ii;
+ d_PI[i*d_I+j]=jj;
+ j++;
+ }
+ }
+}
+
+//######################################################################
+//# Automatically generate an FSM specification describing the
+//# ISI for a channel
+//# of length ch_length and a modulation of size mod_size
+//######################################################################
+fsm::fsm(const int mod_size, const int ch_length)
+{
+ d_I=mod_size;
+ d_S=(int) (pow(1.0*d_I,1.0*ch_length-1)+0.5);
+ d_O=d_S*d_I;
+
+ d_NS.resize(d_I*d_S);
+ d_OS.resize(d_I*d_S);
+ d_PS.resize(d_I*d_S);
+ d_PI.resize(d_I*d_S);
+
+ for(int s=0;s<d_S;s++) {
+ for(int i=0;i<d_I;i++) {
+ int t=i*d_S+s;
+ d_NS[s*d_I+i] = t/d_I;
+ d_OS[s*d_I+i] = t;
+ }
+ }
+
+ // generate the PS, PI tables for later use
+ for(int i=0;i<d_S;i++) {
+ int j=0;
+ for(int ii=0;ii<d_S;ii++) for(int jj=0;jj<d_I;jj++) {
+ if(d_NS[ii*d_I+jj]!=i) continue;
+ d_PS[i*d_I+j]=ii;
+ d_PI[i*d_I+j]=jj;
+ j++;
+ }
+ }
+}
diff --git a/gr-trellis/src/lib/fsm.h b/gr-trellis/src/lib/fsm.h
new file mode 100644
index 000000000..b5a8e0d5b
--- /dev/null
+++ b/gr-trellis/src/lib/fsm.h
@@ -0,0 +1,55 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2002 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef INCLUDED_TRELLIS_FSM_H
+#define INCLUDED_TRELLIS_FSM_H
+
+#include <vector>
+
+/*!
+ * \brief FSM class
+ */
+class fsm {
+private:
+ int d_I;
+ int d_S;
+ int d_O;
+ std::vector<int> d_NS;
+ std::vector<int> d_OS;
+ std::vector<int> d_PS;
+ std::vector<int> d_PI;
+public:
+ fsm();
+ fsm(const fsm &FSM);
+ fsm(const int I, const int S, const int O, const std::vector<int> &NS, const std::vector<int> &OS);
+ fsm(const char *name);
+ fsm(const int mod_size, const int ch_length);
+ int I () const { return d_I; }
+ int S () const { return d_S; }
+ int O () const { return d_O; }
+ const std::vector<int> & NS () const { return d_NS; }
+ const std::vector<int> & OS () const { return d_OS; }
+ const std::vector<int> & PS () const { return d_PS; }
+ const std::vector<int> & PI () const { return d_PI; }
+};
+
+#endif
diff --git a/gr-trellis/src/lib/fsm.i b/gr-trellis/src/lib/fsm.i
new file mode 100644
index 000000000..eda8aeefd
--- /dev/null
+++ b/gr-trellis/src/lib/fsm.i
@@ -0,0 +1,49 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2002 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+class fsm {
+private:
+ int d_I;
+ int d_S;
+ int d_O;
+ std::vector<int> d_NS;
+ std::vector<int> d_OS;
+ std::vector<int> d_PS;
+ std::vector<int> d_PI;
+public:
+ fsm();
+ fsm(const fsm &FSM);
+ fsm(const int I, const int S, const int O, const std::vector<int> &NS, const std::vector<int> &OS);
+ fsm(const char *name);
+ fsm(const int mod_size, const int ch_length);
+ int I () const { return d_I; }
+ int S () const { return d_S; }
+ int O () const { return d_O; }
+ const std::vector<int> & NS () const { return d_NS; }
+ const std::vector<int> & OS () const { return d_OS; }
+ const std::vector<int> & PS () const { return d_PS; }
+ const std::vector<int> & PI () const { return d_PI; }
+};
+
+
+
+
diff --git a/gr-trellis/src/lib/generate_all.py b/gr-trellis/src/lib/generate_all.py
new file mode 100644
index 000000000..766c4304f
--- /dev/null
+++ b/gr-trellis/src/lib/generate_all.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+#
+# Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+
+from build_utils import output_glue
+
+import generate_common
+
+def generate_all ():
+ generate_common.generate ()
+ output_glue ('trellis')
+
+
+if __name__ == '__main__':
+ generate_all ()
diff --git a/gr-trellis/src/lib/generate_common.py b/gr-trellis/src/lib/generate_common.py
new file mode 100644
index 000000000..c7bb6c865
--- /dev/null
+++ b/gr-trellis/src/lib/generate_common.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+#
+# Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+
+from build_utils import expand_template, standard_dict
+from build_utils_codes import *
+
+import re
+
+
+# regular blocks
+other_roots = [
+ 'trellis_encoder_XX',
+ 'trellis_metrics_X',
+ 'trellis_viterbi_X',
+ 'trellis_viterbi_combined_X',
+ ]
+other_signatures = (
+ ['bb','bs','bi','ss','si','ii'],
+ ['f','c'],
+ ['b','s','i'],
+ ['b','s','i'],
+ )
+
+
+
+def expand_h_cc_i (root, sig):
+ # root looks like 'gr_vector_sink_X'
+ name = re.sub ('X+', sig, root)
+ d = standard_dict (name, sig)
+ expand_template (d, root + '.h.t')
+ expand_template (d, root + '.cc.t')
+ expand_template (d, root + '.i.t')
+
+
+def generate ():
+ i=0
+ for r in other_roots :
+ for s in other_signatures[i]:
+ expand_h_cc_i (r, s)
+ i=i+1
+
+
+
+if __name__ == '__main__':
+ generate ()
+
+
diff --git a/gr-trellis/src/lib/trellis.i b/gr-trellis/src/lib/trellis.i
new file mode 100644
index 000000000..5dd781402
--- /dev/null
+++ b/gr-trellis/src/lib/trellis.i
@@ -0,0 +1,21 @@
+/* -*- c++ -*- */
+
+%feature("autodoc", "1"); // generate python docstrings
+
+%include "exception.i"
+%import "gnuradio.i" // the common stuff
+
+%{
+#include "gnuradio_swig_bug_workaround.h" // mandatory bug fix
+#include "fsm.h"
+#include <stdexcept>
+%}
+
+// ----------------------------------------------------------------
+
+%include "fsm.i"
+%include "trellis_metric_type.h"
+
+
+%include "trellis_generated.i"
+
diff --git a/gr-trellis/src/lib/trellis_calc_metric.cc b/gr-trellis/src/lib/trellis_calc_metric.cc
new file mode 100644
index 000000000..c6d2ce98c
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_calc_metric.cc
@@ -0,0 +1,92 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <float.h>
+#include <stdexcept>
+#include "trellis_calc_metric.h"
+
+// soft decisions (Eucledean distance squared)
+void calc_metric_f(const int O, const int D, const std::vector<float> &TABLE, const float *in, float *metric, trellis_metric_type_t type)
+{
+ float minm = FLT_MAX;
+ int minmi = 0;
+
+ switch (type){
+ case TRELLIS_EUCLIDEAN:
+ for(int o=0;o<O;o++) {
+ metric[o]=0.0;
+ for (int m=0;m<D;m++) {
+ float s=in[m]-TABLE[o*D+m];
+ metric[o]+=s*s;
+ }
+ }
+ break;
+ case TRELLIS_HARD_SYMBOL:
+ for(int o=0;o<O;o++) {
+ metric[o]=0.0;
+ for (int m=0;m<D;m++) {
+ float s=in[m]-TABLE[o*D+m];
+ metric[o]+=s*s;
+ }
+ if(metric[o]<minm) {
+ minm=metric[o];
+ minmi=o;
+ }
+ }
+ for(int o=0;o<O;o++) {
+ metric[o] = (o==minmi?0.0:1.0);
+ }
+ break;
+ case TRELLIS_HARD_BIT:
+ throw std::runtime_error ("Invalid metric type (not yet implemented).");
+ break;
+ default:
+ throw std::runtime_error ("Invalid metric type.");
+ }
+}
+
+
+// soft decisions (Eucledean distance squared)
+void calc_metric_c(const int O, const int D, const std::vector<gr_complex> &TABLE, const gr_complex *in, float *metric, trellis_metric_type_t type)
+{
+ float minm = FLT_MAX;
+ int minmi = 0;
+
+ switch (type){
+ case TRELLIS_EUCLIDEAN:
+ for(int o=0;o<O;o++) {
+ metric[o]=0.0;
+ for (int m=0;m<D;m++) {
+ gr_complex s=in[m]-TABLE[o*D+m];
+ metric[o]+=s.real()*s.real()+s.imag()*s.imag();
+ }
+ }
+ case TRELLIS_HARD_SYMBOL:
+ throw std::runtime_error ("Invalid metric type (not yet implemented).");
+ break;
+ case TRELLIS_HARD_BIT:
+ throw std::runtime_error ("Invalid metric type (not yet implemented).");
+ break;
+ default:
+ throw std::runtime_error ("Invalid metric type.");
+ }
+}
diff --git a/gr-trellis/src/lib/trellis_calc_metric.h b/gr-trellis/src/lib/trellis_calc_metric.h
new file mode 100644
index 000000000..5375070f8
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_calc_metric.h
@@ -0,0 +1,34 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef INCLUDED_TRELLIS_CALC_METRIC_H
+#define INCLUDED_TRELLIS_CALC_METRIC_H
+
+#include <vector>
+#include <gr_complex.h>
+#include <trellis_metric_type.h>
+
+void calc_metric_f(const int O, const int D, const std::vector<float> &TABLE, const float *in, float *metric, trellis_metric_type_t type);
+
+void calc_metric_c(const int O, const int D, const std::vector<gr_complex> &TABLE, const gr_complex *in, float *metric, trellis_metric_type_t type);
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_encoder_XX.cc.t b/gr-trellis/src/lib/trellis_encoder_XX.cc.t
new file mode 100644
index 000000000..75ae0750a
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_XX.cc.t
@@ -0,0 +1,76 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME@.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+@SPTR_NAME@
+trellis_make_@BASE_NAME@ (const fsm &FSM, const int ST)
+{
+ return @SPTR_NAME@ (new @NAME@ (FSM,ST));
+}
+
+@NAME@::@NAME@ (const fsm &FSM, const int ST)
+ : gr_sync_block ("@BASE_NAME@",
+ gr_make_io_signature (1, -1, sizeof (@I_TYPE@)),
+ gr_make_io_signature (1, -1, sizeof (@O_TYPE@))),
+ d_FSM (FSM),
+ d_ST (ST)
+{
+}
+
+
+
+int
+@NAME@::work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ int d_ST_tmp;
+
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+
+for (int m=0;m<nstreams;m++) {
+ const @I_TYPE@ *in = (const @I_TYPE@ *) input_items[m];
+ @O_TYPE@ *out = (@O_TYPE@ *) output_items[m];
+ d_ST_tmp = d_ST;
+
+// per stream processing
+
+ for (int i = 0; i < noutput_items; i++){
+ out[i] = (@O_TYPE@) d_FSM.OS()[d_ST_tmp*d_FSM.I()+in[i]]; // direction of time?
+ d_ST_tmp = (int) d_FSM.NS()[d_ST_tmp*d_FSM.I()+in[i]];
+ }
+
+// end per stream processing
+}
+ d_ST = d_ST_tmp;
+
+ return noutput_items;
+}
+
diff --git a/gr-trellis/src/lib/trellis_encoder_XX.h.t b/gr-trellis/src/lib/trellis_encoder_XX.h.t
new file mode 100644
index 000000000..bfca5ee40
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_XX.h.t
@@ -0,0 +1,59 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include "fsm.h"
+#include <gr_sync_block.h>
+
+class @NAME@;
+typedef boost::shared_ptr<@NAME@> @SPTR_NAME@;
+
+@SPTR_NAME@ trellis_make_@BASE_NAME@ (const fsm &FSM, const int ST);
+
+/*!
+ * \brief Convolutional encoder.
+ * \ingroup block
+ *
+ *
+ */
+class @NAME@ : public gr_sync_block
+{
+private:
+ friend @SPTR_NAME@ trellis_make_@BASE_NAME@ (const fsm &FSM, const int ST);
+ fsm d_FSM;
+ int d_ST;
+ @NAME@ (const fsm &FSM, const int ST);
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int ST () const { return d_ST; }
+
+ int work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_encoder_XX.i.t b/gr-trellis/src/lib/trellis_encoder_XX.i.t
new file mode 100644
index 000000000..ea015a84f
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_XX.i.t
@@ -0,0 +1,36 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// @WARNING@
+
+GR_SWIG_BLOCK_MAGIC(trellis,@BASE_NAME@);
+
+@SPTR_NAME@ trellis_make_@BASE_NAME@ (const fsm &FSM, const int ST);
+
+class @NAME@ : public gr_sync_block
+{
+private:
+ @NAME@ (const fsm &FSM, const int ST);
+public:
+ fsm FSM () const { return d_FSM; }
+ int ST () const { return d_ST; }
+};
diff --git a/gr-trellis/src/lib/trellis_encoder_bb.cc b/gr-trellis/src/lib/trellis_encoder_bb.cc
new file mode 100644
index 000000000..aecba87a4
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_bb.cc
@@ -0,0 +1,76 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_encoder_bb.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+trellis_encoder_bb_sptr
+trellis_make_encoder_bb (const fsm &FSM, const int ST)
+{
+ return trellis_encoder_bb_sptr (new trellis_encoder_bb (FSM,ST));
+}
+
+trellis_encoder_bb::trellis_encoder_bb (const fsm &FSM, const int ST)
+ : gr_sync_block ("encoder_bb",
+ gr_make_io_signature (1, -1, sizeof (unsigned char)),
+ gr_make_io_signature (1, -1, sizeof (unsigned char))),
+ d_FSM (FSM),
+ d_ST (ST)
+{
+}
+
+
+
+int
+trellis_encoder_bb::work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ int d_ST_tmp;
+
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+
+for (int m=0;m<nstreams;m++) {
+ const unsigned char *in = (const unsigned char *) input_items[m];
+ unsigned char *out = (unsigned char *) output_items[m];
+ d_ST_tmp = d_ST;
+
+// per stream processing
+
+ for (int i = 0; i < noutput_items; i++){
+ out[i] = (unsigned char) d_FSM.OS()[d_ST_tmp*d_FSM.I()+in[i]]; // direction of time?
+ d_ST_tmp = (int) d_FSM.NS()[d_ST_tmp*d_FSM.I()+in[i]];
+ }
+
+// end per stream processing
+}
+ d_ST = d_ST_tmp;
+
+ return noutput_items;
+}
+
diff --git a/gr-trellis/src/lib/trellis_encoder_bb.h b/gr-trellis/src/lib/trellis_encoder_bb.h
new file mode 100644
index 000000000..a3817f2e7
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_bb.h
@@ -0,0 +1,59 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+#ifndef INCLUDED_TRELLIS_ENCODER_BB_H
+#define INCLUDED_TRELLIS_ENCODER_BB_H
+
+#include "fsm.h"
+#include <gr_sync_block.h>
+
+class trellis_encoder_bb;
+typedef boost::shared_ptr<trellis_encoder_bb> trellis_encoder_bb_sptr;
+
+trellis_encoder_bb_sptr trellis_make_encoder_bb (const fsm &FSM, const int ST);
+
+/*!
+ * \brief Convolutional encoder.
+ * \ingroup block
+ *
+ *
+ */
+class trellis_encoder_bb : public gr_sync_block
+{
+private:
+ friend trellis_encoder_bb_sptr trellis_make_encoder_bb (const fsm &FSM, const int ST);
+ fsm d_FSM;
+ int d_ST;
+ trellis_encoder_bb (const fsm &FSM, const int ST);
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int ST () const { return d_ST; }
+
+ int work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_encoder_bb.i b/gr-trellis/src/lib/trellis_encoder_bb.i
new file mode 100644
index 000000000..07f5606e6
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_bb.i
@@ -0,0 +1,36 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,encoder_bb);
+
+trellis_encoder_bb_sptr trellis_make_encoder_bb (const fsm &FSM, const int ST);
+
+class trellis_encoder_bb : public gr_sync_block
+{
+private:
+ trellis_encoder_bb (const fsm &FSM, const int ST);
+public:
+ fsm FSM () const { return d_FSM; }
+ int ST () const { return d_ST; }
+};
diff --git a/gr-trellis/src/lib/trellis_encoder_bi.cc b/gr-trellis/src/lib/trellis_encoder_bi.cc
new file mode 100644
index 000000000..968527b8f
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_bi.cc
@@ -0,0 +1,76 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_encoder_bi.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+trellis_encoder_bi_sptr
+trellis_make_encoder_bi (const fsm &FSM, const int ST)
+{
+ return trellis_encoder_bi_sptr (new trellis_encoder_bi (FSM,ST));
+}
+
+trellis_encoder_bi::trellis_encoder_bi (const fsm &FSM, const int ST)
+ : gr_sync_block ("encoder_bi",
+ gr_make_io_signature (1, -1, sizeof (unsigned char)),
+ gr_make_io_signature (1, -1, sizeof (int))),
+ d_FSM (FSM),
+ d_ST (ST)
+{
+}
+
+
+
+int
+trellis_encoder_bi::work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ int d_ST_tmp;
+
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+
+for (int m=0;m<nstreams;m++) {
+ const unsigned char *in = (const unsigned char *) input_items[m];
+ int *out = (int *) output_items[m];
+ d_ST_tmp = d_ST;
+
+// per stream processing
+
+ for (int i = 0; i < noutput_items; i++){
+ out[i] = (int) d_FSM.OS()[d_ST_tmp*d_FSM.I()+in[i]]; // direction of time?
+ d_ST_tmp = (int) d_FSM.NS()[d_ST_tmp*d_FSM.I()+in[i]];
+ }
+
+// end per stream processing
+}
+ d_ST = d_ST_tmp;
+
+ return noutput_items;
+}
+
diff --git a/gr-trellis/src/lib/trellis_encoder_bi.h b/gr-trellis/src/lib/trellis_encoder_bi.h
new file mode 100644
index 000000000..5212f6416
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_bi.h
@@ -0,0 +1,59 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+#ifndef INCLUDED_TRELLIS_ENCODER_BI_H
+#define INCLUDED_TRELLIS_ENCODER_BI_H
+
+#include "fsm.h"
+#include <gr_sync_block.h>
+
+class trellis_encoder_bi;
+typedef boost::shared_ptr<trellis_encoder_bi> trellis_encoder_bi_sptr;
+
+trellis_encoder_bi_sptr trellis_make_encoder_bi (const fsm &FSM, const int ST);
+
+/*!
+ * \brief Convolutional encoder.
+ * \ingroup block
+ *
+ *
+ */
+class trellis_encoder_bi : public gr_sync_block
+{
+private:
+ friend trellis_encoder_bi_sptr trellis_make_encoder_bi (const fsm &FSM, const int ST);
+ fsm d_FSM;
+ int d_ST;
+ trellis_encoder_bi (const fsm &FSM, const int ST);
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int ST () const { return d_ST; }
+
+ int work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_encoder_bi.i b/gr-trellis/src/lib/trellis_encoder_bi.i
new file mode 100644
index 000000000..4fd389e94
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_bi.i
@@ -0,0 +1,36 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,encoder_bi);
+
+trellis_encoder_bi_sptr trellis_make_encoder_bi (const fsm &FSM, const int ST);
+
+class trellis_encoder_bi : public gr_sync_block
+{
+private:
+ trellis_encoder_bi (const fsm &FSM, const int ST);
+public:
+ fsm FSM () const { return d_FSM; }
+ int ST () const { return d_ST; }
+};
diff --git a/gr-trellis/src/lib/trellis_encoder_bs.cc b/gr-trellis/src/lib/trellis_encoder_bs.cc
new file mode 100644
index 000000000..9546e3d9d
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_bs.cc
@@ -0,0 +1,76 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_encoder_bs.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+trellis_encoder_bs_sptr
+trellis_make_encoder_bs (const fsm &FSM, const int ST)
+{
+ return trellis_encoder_bs_sptr (new trellis_encoder_bs (FSM,ST));
+}
+
+trellis_encoder_bs::trellis_encoder_bs (const fsm &FSM, const int ST)
+ : gr_sync_block ("encoder_bs",
+ gr_make_io_signature (1, -1, sizeof (unsigned char)),
+ gr_make_io_signature (1, -1, sizeof (short))),
+ d_FSM (FSM),
+ d_ST (ST)
+{
+}
+
+
+
+int
+trellis_encoder_bs::work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ int d_ST_tmp;
+
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+
+for (int m=0;m<nstreams;m++) {
+ const unsigned char *in = (const unsigned char *) input_items[m];
+ short *out = (short *) output_items[m];
+ d_ST_tmp = d_ST;
+
+// per stream processing
+
+ for (int i = 0; i < noutput_items; i++){
+ out[i] = (short) d_FSM.OS()[d_ST_tmp*d_FSM.I()+in[i]]; // direction of time?
+ d_ST_tmp = (int) d_FSM.NS()[d_ST_tmp*d_FSM.I()+in[i]];
+ }
+
+// end per stream processing
+}
+ d_ST = d_ST_tmp;
+
+ return noutput_items;
+}
+
diff --git a/gr-trellis/src/lib/trellis_encoder_bs.h b/gr-trellis/src/lib/trellis_encoder_bs.h
new file mode 100644
index 000000000..2ddf5505c
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_bs.h
@@ -0,0 +1,59 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+#ifndef INCLUDED_TRELLIS_ENCODER_BS_H
+#define INCLUDED_TRELLIS_ENCODER_BS_H
+
+#include "fsm.h"
+#include <gr_sync_block.h>
+
+class trellis_encoder_bs;
+typedef boost::shared_ptr<trellis_encoder_bs> trellis_encoder_bs_sptr;
+
+trellis_encoder_bs_sptr trellis_make_encoder_bs (const fsm &FSM, const int ST);
+
+/*!
+ * \brief Convolutional encoder.
+ * \ingroup block
+ *
+ *
+ */
+class trellis_encoder_bs : public gr_sync_block
+{
+private:
+ friend trellis_encoder_bs_sptr trellis_make_encoder_bs (const fsm &FSM, const int ST);
+ fsm d_FSM;
+ int d_ST;
+ trellis_encoder_bs (const fsm &FSM, const int ST);
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int ST () const { return d_ST; }
+
+ int work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_encoder_bs.i b/gr-trellis/src/lib/trellis_encoder_bs.i
new file mode 100644
index 000000000..51fc1d481
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_bs.i
@@ -0,0 +1,36 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,encoder_bs);
+
+trellis_encoder_bs_sptr trellis_make_encoder_bs (const fsm &FSM, const int ST);
+
+class trellis_encoder_bs : public gr_sync_block
+{
+private:
+ trellis_encoder_bs (const fsm &FSM, const int ST);
+public:
+ fsm FSM () const { return d_FSM; }
+ int ST () const { return d_ST; }
+};
diff --git a/gr-trellis/src/lib/trellis_encoder_ii.cc b/gr-trellis/src/lib/trellis_encoder_ii.cc
new file mode 100644
index 000000000..3469a235d
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_ii.cc
@@ -0,0 +1,76 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_encoder_ii.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+trellis_encoder_ii_sptr
+trellis_make_encoder_ii (const fsm &FSM, const int ST)
+{
+ return trellis_encoder_ii_sptr (new trellis_encoder_ii (FSM,ST));
+}
+
+trellis_encoder_ii::trellis_encoder_ii (const fsm &FSM, const int ST)
+ : gr_sync_block ("encoder_ii",
+ gr_make_io_signature (1, -1, sizeof (int)),
+ gr_make_io_signature (1, -1, sizeof (int))),
+ d_FSM (FSM),
+ d_ST (ST)
+{
+}
+
+
+
+int
+trellis_encoder_ii::work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ int d_ST_tmp;
+
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+
+for (int m=0;m<nstreams;m++) {
+ const int *in = (const int *) input_items[m];
+ int *out = (int *) output_items[m];
+ d_ST_tmp = d_ST;
+
+// per stream processing
+
+ for (int i = 0; i < noutput_items; i++){
+ out[i] = (int) d_FSM.OS()[d_ST_tmp*d_FSM.I()+in[i]]; // direction of time?
+ d_ST_tmp = (int) d_FSM.NS()[d_ST_tmp*d_FSM.I()+in[i]];
+ }
+
+// end per stream processing
+}
+ d_ST = d_ST_tmp;
+
+ return noutput_items;
+}
+
diff --git a/gr-trellis/src/lib/trellis_encoder_ii.h b/gr-trellis/src/lib/trellis_encoder_ii.h
new file mode 100644
index 000000000..b0a9cee02
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_ii.h
@@ -0,0 +1,59 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+#ifndef INCLUDED_TRELLIS_ENCODER_II_H
+#define INCLUDED_TRELLIS_ENCODER_II_H
+
+#include "fsm.h"
+#include <gr_sync_block.h>
+
+class trellis_encoder_ii;
+typedef boost::shared_ptr<trellis_encoder_ii> trellis_encoder_ii_sptr;
+
+trellis_encoder_ii_sptr trellis_make_encoder_ii (const fsm &FSM, const int ST);
+
+/*!
+ * \brief Convolutional encoder.
+ * \ingroup block
+ *
+ *
+ */
+class trellis_encoder_ii : public gr_sync_block
+{
+private:
+ friend trellis_encoder_ii_sptr trellis_make_encoder_ii (const fsm &FSM, const int ST);
+ fsm d_FSM;
+ int d_ST;
+ trellis_encoder_ii (const fsm &FSM, const int ST);
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int ST () const { return d_ST; }
+
+ int work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_encoder_ii.i b/gr-trellis/src/lib/trellis_encoder_ii.i
new file mode 100644
index 000000000..c05cbb36c
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_ii.i
@@ -0,0 +1,36 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,encoder_ii);
+
+trellis_encoder_ii_sptr trellis_make_encoder_ii (const fsm &FSM, const int ST);
+
+class trellis_encoder_ii : public gr_sync_block
+{
+private:
+ trellis_encoder_ii (const fsm &FSM, const int ST);
+public:
+ fsm FSM () const { return d_FSM; }
+ int ST () const { return d_ST; }
+};
diff --git a/gr-trellis/src/lib/trellis_encoder_si.cc b/gr-trellis/src/lib/trellis_encoder_si.cc
new file mode 100644
index 000000000..581ffe286
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_si.cc
@@ -0,0 +1,76 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_encoder_si.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+trellis_encoder_si_sptr
+trellis_make_encoder_si (const fsm &FSM, const int ST)
+{
+ return trellis_encoder_si_sptr (new trellis_encoder_si (FSM,ST));
+}
+
+trellis_encoder_si::trellis_encoder_si (const fsm &FSM, const int ST)
+ : gr_sync_block ("encoder_si",
+ gr_make_io_signature (1, -1, sizeof (short)),
+ gr_make_io_signature (1, -1, sizeof (int))),
+ d_FSM (FSM),
+ d_ST (ST)
+{
+}
+
+
+
+int
+trellis_encoder_si::work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ int d_ST_tmp;
+
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+
+for (int m=0;m<nstreams;m++) {
+ const short *in = (const short *) input_items[m];
+ int *out = (int *) output_items[m];
+ d_ST_tmp = d_ST;
+
+// per stream processing
+
+ for (int i = 0; i < noutput_items; i++){
+ out[i] = (int) d_FSM.OS()[d_ST_tmp*d_FSM.I()+in[i]]; // direction of time?
+ d_ST_tmp = (int) d_FSM.NS()[d_ST_tmp*d_FSM.I()+in[i]];
+ }
+
+// end per stream processing
+}
+ d_ST = d_ST_tmp;
+
+ return noutput_items;
+}
+
diff --git a/gr-trellis/src/lib/trellis_encoder_si.h b/gr-trellis/src/lib/trellis_encoder_si.h
new file mode 100644
index 000000000..d42db7a99
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_si.h
@@ -0,0 +1,59 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+#ifndef INCLUDED_TRELLIS_ENCODER_SI_H
+#define INCLUDED_TRELLIS_ENCODER_SI_H
+
+#include "fsm.h"
+#include <gr_sync_block.h>
+
+class trellis_encoder_si;
+typedef boost::shared_ptr<trellis_encoder_si> trellis_encoder_si_sptr;
+
+trellis_encoder_si_sptr trellis_make_encoder_si (const fsm &FSM, const int ST);
+
+/*!
+ * \brief Convolutional encoder.
+ * \ingroup block
+ *
+ *
+ */
+class trellis_encoder_si : public gr_sync_block
+{
+private:
+ friend trellis_encoder_si_sptr trellis_make_encoder_si (const fsm &FSM, const int ST);
+ fsm d_FSM;
+ int d_ST;
+ trellis_encoder_si (const fsm &FSM, const int ST);
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int ST () const { return d_ST; }
+
+ int work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_encoder_si.i b/gr-trellis/src/lib/trellis_encoder_si.i
new file mode 100644
index 000000000..e1166a6f2
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_si.i
@@ -0,0 +1,36 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,encoder_si);
+
+trellis_encoder_si_sptr trellis_make_encoder_si (const fsm &FSM, const int ST);
+
+class trellis_encoder_si : public gr_sync_block
+{
+private:
+ trellis_encoder_si (const fsm &FSM, const int ST);
+public:
+ fsm FSM () const { return d_FSM; }
+ int ST () const { return d_ST; }
+};
diff --git a/gr-trellis/src/lib/trellis_encoder_ss.cc b/gr-trellis/src/lib/trellis_encoder_ss.cc
new file mode 100644
index 000000000..96604a34b
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_ss.cc
@@ -0,0 +1,76 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_encoder_ss.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+trellis_encoder_ss_sptr
+trellis_make_encoder_ss (const fsm &FSM, const int ST)
+{
+ return trellis_encoder_ss_sptr (new trellis_encoder_ss (FSM,ST));
+}
+
+trellis_encoder_ss::trellis_encoder_ss (const fsm &FSM, const int ST)
+ : gr_sync_block ("encoder_ss",
+ gr_make_io_signature (1, -1, sizeof (short)),
+ gr_make_io_signature (1, -1, sizeof (short))),
+ d_FSM (FSM),
+ d_ST (ST)
+{
+}
+
+
+
+int
+trellis_encoder_ss::work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ int d_ST_tmp;
+
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+
+for (int m=0;m<nstreams;m++) {
+ const short *in = (const short *) input_items[m];
+ short *out = (short *) output_items[m];
+ d_ST_tmp = d_ST;
+
+// per stream processing
+
+ for (int i = 0; i < noutput_items; i++){
+ out[i] = (short) d_FSM.OS()[d_ST_tmp*d_FSM.I()+in[i]]; // direction of time?
+ d_ST_tmp = (int) d_FSM.NS()[d_ST_tmp*d_FSM.I()+in[i]];
+ }
+
+// end per stream processing
+}
+ d_ST = d_ST_tmp;
+
+ return noutput_items;
+}
+
diff --git a/gr-trellis/src/lib/trellis_encoder_ss.h b/gr-trellis/src/lib/trellis_encoder_ss.h
new file mode 100644
index 000000000..96e1a19bd
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_ss.h
@@ -0,0 +1,59 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+#ifndef INCLUDED_TRELLIS_ENCODER_SS_H
+#define INCLUDED_TRELLIS_ENCODER_SS_H
+
+#include "fsm.h"
+#include <gr_sync_block.h>
+
+class trellis_encoder_ss;
+typedef boost::shared_ptr<trellis_encoder_ss> trellis_encoder_ss_sptr;
+
+trellis_encoder_ss_sptr trellis_make_encoder_ss (const fsm &FSM, const int ST);
+
+/*!
+ * \brief Convolutional encoder.
+ * \ingroup block
+ *
+ *
+ */
+class trellis_encoder_ss : public gr_sync_block
+{
+private:
+ friend trellis_encoder_ss_sptr trellis_make_encoder_ss (const fsm &FSM, const int ST);
+ fsm d_FSM;
+ int d_ST;
+ trellis_encoder_ss (const fsm &FSM, const int ST);
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int ST () const { return d_ST; }
+
+ int work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_encoder_ss.i b/gr-trellis/src/lib/trellis_encoder_ss.i
new file mode 100644
index 000000000..ac194306f
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_encoder_ss.i
@@ -0,0 +1,36 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,encoder_ss);
+
+trellis_encoder_ss_sptr trellis_make_encoder_ss (const fsm &FSM, const int ST);
+
+class trellis_encoder_ss : public gr_sync_block
+{
+private:
+ trellis_encoder_ss (const fsm &FSM, const int ST);
+public:
+ fsm FSM () const { return d_FSM; }
+ int ST () const { return d_ST; }
+};
diff --git a/gr-trellis/src/lib/trellis_generated.i b/gr-trellis/src/lib/trellis_generated.i
new file mode 100644
index 000000000..c76e79c5c
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_generated.i
@@ -0,0 +1,34 @@
+//
+// This file is machine generated. All edits will be overwritten
+//
+%{
+#include <trellis_encoder_bb.h>
+#include <trellis_encoder_bi.h>
+#include <trellis_encoder_bs.h>
+#include <trellis_encoder_ii.h>
+#include <trellis_encoder_si.h>
+#include <trellis_encoder_ss.h>
+#include <trellis_metrics_c.h>
+#include <trellis_metrics_f.h>
+#include <trellis_viterbi_b.h>
+#include <trellis_viterbi_combined_b.h>
+#include <trellis_viterbi_combined_i.h>
+#include <trellis_viterbi_combined_s.h>
+#include <trellis_viterbi_i.h>
+#include <trellis_viterbi_s.h>
+%}
+
+%include <trellis_encoder_bb.i>
+%include <trellis_encoder_bi.i>
+%include <trellis_encoder_bs.i>
+%include <trellis_encoder_ii.i>
+%include <trellis_encoder_si.i>
+%include <trellis_encoder_ss.i>
+%include <trellis_metrics_c.i>
+%include <trellis_metrics_f.i>
+%include <trellis_viterbi_b.i>
+%include <trellis_viterbi_combined_b.i>
+%include <trellis_viterbi_combined_i.i>
+%include <trellis_viterbi_combined_s.i>
+%include <trellis_viterbi_i.i>
+%include <trellis_viterbi_s.i>
diff --git a/gr-trellis/src/lib/trellis_metric_type.h b/gr-trellis/src/lib/trellis_metric_type.h
new file mode 100644
index 000000000..ef52a5e7c
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_metric_type.h
@@ -0,0 +1,31 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef INCLUDED_TRELLIS_METRIC_TYPE_H
+#define INCLUDED_TRELLIS_METRIC_TYPE_H
+
+typedef enum {
+ TRELLIS_EUCLIDEAN = 200, TRELLIS_HARD_SYMBOL, TRELLIS_HARD_BIT
+} trellis_metric_type_t;
+
+#endif
+
diff --git a/gr-trellis/src/lib/trellis_metrics_X.cc.t b/gr-trellis/src/lib/trellis_metrics_X.cc.t
new file mode 100644
index 000000000..d5347e12d
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_metrics_X.cc.t
@@ -0,0 +1,96 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME@.h>
+#include <gr_io_signature.h>
+#include <assert.h>
+#include <stdexcept>
+#include <iostream>
+
+
+@SPTR_NAME@
+trellis_make_@BASE_NAME@ (const int O, const int D, const std::vector<@I_TYPE@> &TABLE, trellis_metric_type_t TYPE)
+{
+ return @SPTR_NAME@ (new @NAME@ (O,D,TABLE,TYPE));
+}
+
+
+
+@NAME@::@NAME@ (const int O, const int D, const std::vector<@I_TYPE@> &TABLE, trellis_metric_type_t TYPE)
+ : gr_block ("@BASE_NAME@",
+ gr_make_io_signature (1, -1, sizeof (@I_TYPE@)),
+ gr_make_io_signature (1, -1, sizeof (float))),
+ d_O (O),
+ d_D (D),
+ d_TYPE (TYPE),
+ d_TABLE (TABLE)
+{
+ set_relative_rate (1.0 * d_O / ((double) d_D));
+ set_output_multiple ((int)d_O);
+}
+
+
+
+
+void
+@NAME@::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+ assert (noutput_items % d_O == 0);
+ int input_required = d_D * noutput_items / d_O;
+ unsigned ninputs = ninput_items_required.size();
+ for (unsigned int i = 0; i < ninputs; i++)
+ ninput_items_required[i] = input_required;
+}
+
+
+
+int
+@NAME@::general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+
+ assert (noutput_items % d_O == 0);
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+
+for (int m=0;m<nstreams;m++) {
+ const @I_TYPE@ *in = (@I_TYPE@ *) input_items[m];
+ float *out = (float *) output_items[m];
+
+ for (int i = 0; i < noutput_items / d_O ; i++){
+#if @IS_FLOAT@
+ calc_metric_f(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#elif @IS_COMPLEX@
+ calc_metric_c(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#endif
+ }
+}
+
+ consume_each (d_D * noutput_items / d_O);
+ return noutput_items;
+}
diff --git a/gr-trellis/src/lib/trellis_metrics_X.h.t b/gr-trellis/src/lib/trellis_metrics_X.h.t
new file mode 100644
index 000000000..626791dd4
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_metrics_X.h.t
@@ -0,0 +1,65 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include <gr_block.h>
+#include "trellis_calc_metric.h"
+
+class @NAME@;
+typedef boost::shared_ptr<@NAME@> @SPTR_NAME@;
+
+@SPTR_NAME@ trellis_make_@BASE_NAME@ (const int O, const int D, const std::vector<@I_TYPE@> &TABLE, trellis_metric_type_t TYPE);
+
+/*!
+ * \brief Evaluate metrics for use by the Viterbi algorithm.
+ * \ingroup block
+ *
+ */
+class @NAME@ : public gr_block
+{
+ int d_O;
+ int d_D;
+ trellis_metric_type_t d_TYPE;
+ std::vector<@I_TYPE@> d_TABLE;
+
+ friend @SPTR_NAME@ trellis_make_@BASE_NAME@ (const int O, const int D, const std::vector<@I_TYPE@> &TABLE, trellis_metric_type_t TYPE);
+ @NAME@ (const int O, const int D, const std::vector<@I_TYPE@> &TABLE, trellis_metric_type_t TYPE);
+
+public:
+ int O () const { return d_O; }
+ int D () const { return d_D; }
+ trellis_metric_type_t TYPE () const { return d_TYPE; }
+ std::vector<@I_TYPE@> TABLE () const { return d_TABLE; }
+ void forecast (int noutput_items,
+ gr_vector_int &ninput_items_required);
+ int general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_metrics_X.i.t b/gr-trellis/src/lib/trellis_metrics_X.i.t
new file mode 100644
index 000000000..2fc3ba8ff
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_metrics_X.i.t
@@ -0,0 +1,39 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// @WARNING@
+
+GR_SWIG_BLOCK_MAGIC(trellis,@BASE_NAME@);
+
+@SPTR_NAME@ trellis_make_@BASE_NAME@ (const int O, const int D, const std::vector<@I_TYPE@> &TABLE, trellis_metric_type_t TYPE);
+
+class @NAME@ : public gr_block
+{
+private:
+ @NAME@ (const int O, const int D, const std::vector<@I_TYPE@> &TABLE, trellis_metric_type_t TYPE);
+
+public:
+ int O () const { return d_O; }
+ int D () const { return d_D; }
+ trellis_metric_type_t TYPE () const { return d_TYPE; }
+ std::vector<@I_TYPE@> TABLE () const { return d_TABLE; }
+};
diff --git a/gr-trellis/src/lib/trellis_metrics_c.cc b/gr-trellis/src/lib/trellis_metrics_c.cc
new file mode 100644
index 000000000..1ff5f4540
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_metrics_c.cc
@@ -0,0 +1,96 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_metrics_c.h>
+#include <gr_io_signature.h>
+#include <assert.h>
+#include <stdexcept>
+#include <iostream>
+
+
+trellis_metrics_c_sptr
+trellis_make_metrics_c (const int O, const int D, const std::vector<gr_complex> &TABLE, trellis_metric_type_t TYPE)
+{
+ return trellis_metrics_c_sptr (new trellis_metrics_c (O,D,TABLE,TYPE));
+}
+
+
+
+trellis_metrics_c::trellis_metrics_c (const int O, const int D, const std::vector<gr_complex> &TABLE, trellis_metric_type_t TYPE)
+ : gr_block ("metrics_c",
+ gr_make_io_signature (1, -1, sizeof (gr_complex)),
+ gr_make_io_signature (1, -1, sizeof (float))),
+ d_O (O),
+ d_D (D),
+ d_TYPE (TYPE),
+ d_TABLE (TABLE)
+{
+ set_relative_rate (1.0 * d_O / ((double) d_D));
+ set_output_multiple ((int)d_O);
+}
+
+
+
+
+void
+trellis_metrics_c::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+ assert (noutput_items % d_O == 0);
+ int input_required = d_D * noutput_items / d_O;
+ unsigned ninputs = ninput_items_required.size();
+ for (unsigned int i = 0; i < ninputs; i++)
+ ninput_items_required[i] = input_required;
+}
+
+
+
+int
+trellis_metrics_c::general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+
+ assert (noutput_items % d_O == 0);
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+
+for (int m=0;m<nstreams;m++) {
+ const gr_complex *in = (gr_complex *) input_items[m];
+ float *out = (float *) output_items[m];
+
+ for (int i = 0; i < noutput_items / d_O ; i++){
+#if 0
+ calc_metric_f(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#elif 1
+ calc_metric_c(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#endif
+ }
+}
+
+ consume_each (d_D * noutput_items / d_O);
+ return noutput_items;
+}
diff --git a/gr-trellis/src/lib/trellis_metrics_c.h b/gr-trellis/src/lib/trellis_metrics_c.h
new file mode 100644
index 000000000..5de578401
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_metrics_c.h
@@ -0,0 +1,65 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+#ifndef INCLUDED_TRELLIS_METRICS_C_H
+#define INCLUDED_TRELLIS_METRICS_C_H
+
+#include <gr_block.h>
+#include "trellis_calc_metric.h"
+
+class trellis_metrics_c;
+typedef boost::shared_ptr<trellis_metrics_c> trellis_metrics_c_sptr;
+
+trellis_metrics_c_sptr trellis_make_metrics_c (const int O, const int D, const std::vector<gr_complex> &TABLE, trellis_metric_type_t TYPE);
+
+/*!
+ * \brief Evaluate metrics for use by the Viterbi algorithm.
+ * \ingroup block
+ *
+ */
+class trellis_metrics_c : public gr_block
+{
+ int d_O;
+ int d_D;
+ trellis_metric_type_t d_TYPE;
+ std::vector<gr_complex> d_TABLE;
+
+ friend trellis_metrics_c_sptr trellis_make_metrics_c (const int O, const int D, const std::vector<gr_complex> &TABLE, trellis_metric_type_t TYPE);
+ trellis_metrics_c (const int O, const int D, const std::vector<gr_complex> &TABLE, trellis_metric_type_t TYPE);
+
+public:
+ int O () const { return d_O; }
+ int D () const { return d_D; }
+ trellis_metric_type_t TYPE () const { return d_TYPE; }
+ std::vector<gr_complex> TABLE () const { return d_TABLE; }
+ void forecast (int noutput_items,
+ gr_vector_int &ninput_items_required);
+ int general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_metrics_c.i b/gr-trellis/src/lib/trellis_metrics_c.i
new file mode 100644
index 000000000..6813cb946
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_metrics_c.i
@@ -0,0 +1,39 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,metrics_c);
+
+trellis_metrics_c_sptr trellis_make_metrics_c (const int O, const int D, const std::vector<gr_complex> &TABLE, trellis_metric_type_t TYPE);
+
+class trellis_metrics_c : public gr_block
+{
+private:
+ trellis_metrics_c (const int O, const int D, const std::vector<gr_complex> &TABLE, trellis_metric_type_t TYPE);
+
+public:
+ int O () const { return d_O; }
+ int D () const { return d_D; }
+ trellis_metric_type_t TYPE () const { return d_TYPE; }
+ std::vector<gr_complex> TABLE () const { return d_TABLE; }
+};
diff --git a/gr-trellis/src/lib/trellis_metrics_f.cc b/gr-trellis/src/lib/trellis_metrics_f.cc
new file mode 100644
index 000000000..472ec5942
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_metrics_f.cc
@@ -0,0 +1,96 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_metrics_f.h>
+#include <gr_io_signature.h>
+#include <assert.h>
+#include <stdexcept>
+#include <iostream>
+
+
+trellis_metrics_f_sptr
+trellis_make_metrics_f (const int O, const int D, const std::vector<float> &TABLE, trellis_metric_type_t TYPE)
+{
+ return trellis_metrics_f_sptr (new trellis_metrics_f (O,D,TABLE,TYPE));
+}
+
+
+
+trellis_metrics_f::trellis_metrics_f (const int O, const int D, const std::vector<float> &TABLE, trellis_metric_type_t TYPE)
+ : gr_block ("metrics_f",
+ gr_make_io_signature (1, -1, sizeof (float)),
+ gr_make_io_signature (1, -1, sizeof (float))),
+ d_O (O),
+ d_D (D),
+ d_TYPE (TYPE),
+ d_TABLE (TABLE)
+{
+ set_relative_rate (1.0 * d_O / ((double) d_D));
+ set_output_multiple ((int)d_O);
+}
+
+
+
+
+void
+trellis_metrics_f::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+ assert (noutput_items % d_O == 0);
+ int input_required = d_D * noutput_items / d_O;
+ unsigned ninputs = ninput_items_required.size();
+ for (unsigned int i = 0; i < ninputs; i++)
+ ninput_items_required[i] = input_required;
+}
+
+
+
+int
+trellis_metrics_f::general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+
+ assert (noutput_items % d_O == 0);
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+
+for (int m=0;m<nstreams;m++) {
+ const float *in = (float *) input_items[m];
+ float *out = (float *) output_items[m];
+
+ for (int i = 0; i < noutput_items / d_O ; i++){
+#if 1
+ calc_metric_f(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#elif 0
+ calc_metric_c(d_O, d_D, d_TABLE,&(in[i*d_D]),&(out[i*d_O]), d_TYPE);
+#endif
+ }
+}
+
+ consume_each (d_D * noutput_items / d_O);
+ return noutput_items;
+}
diff --git a/gr-trellis/src/lib/trellis_metrics_f.h b/gr-trellis/src/lib/trellis_metrics_f.h
new file mode 100644
index 000000000..b668c08d0
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_metrics_f.h
@@ -0,0 +1,65 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+#ifndef INCLUDED_TRELLIS_METRICS_F_H
+#define INCLUDED_TRELLIS_METRICS_F_H
+
+#include <gr_block.h>
+#include "trellis_calc_metric.h"
+
+class trellis_metrics_f;
+typedef boost::shared_ptr<trellis_metrics_f> trellis_metrics_f_sptr;
+
+trellis_metrics_f_sptr trellis_make_metrics_f (const int O, const int D, const std::vector<float> &TABLE, trellis_metric_type_t TYPE);
+
+/*!
+ * \brief Evaluate metrics for use by the Viterbi algorithm.
+ * \ingroup block
+ *
+ */
+class trellis_metrics_f : public gr_block
+{
+ int d_O;
+ int d_D;
+ trellis_metric_type_t d_TYPE;
+ std::vector<float> d_TABLE;
+
+ friend trellis_metrics_f_sptr trellis_make_metrics_f (const int O, const int D, const std::vector<float> &TABLE, trellis_metric_type_t TYPE);
+ trellis_metrics_f (const int O, const int D, const std::vector<float> &TABLE, trellis_metric_type_t TYPE);
+
+public:
+ int O () const { return d_O; }
+ int D () const { return d_D; }
+ trellis_metric_type_t TYPE () const { return d_TYPE; }
+ std::vector<float> TABLE () const { return d_TABLE; }
+ void forecast (int noutput_items,
+ gr_vector_int &ninput_items_required);
+ int general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_metrics_f.i b/gr-trellis/src/lib/trellis_metrics_f.i
new file mode 100644
index 000000000..e808af168
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_metrics_f.i
@@ -0,0 +1,39 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,metrics_f);
+
+trellis_metrics_f_sptr trellis_make_metrics_f (const int O, const int D, const std::vector<float> &TABLE, trellis_metric_type_t TYPE);
+
+class trellis_metrics_f : public gr_block
+{
+private:
+ trellis_metrics_f (const int O, const int D, const std::vector<float> &TABLE, trellis_metric_type_t TYPE);
+
+public:
+ int O () const { return d_O; }
+ int D () const { return d_D; }
+ trellis_metric_type_t TYPE () const { return d_TYPE; }
+ std::vector<float> TABLE () const { return d_TABLE; }
+};
diff --git a/gr-trellis/src/lib/trellis_viterbi_X.cc.t b/gr-trellis/src/lib/trellis_viterbi_X.cc.t
new file mode 100644
index 000000000..e8b9ee695
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_X.cc.t
@@ -0,0 +1,167 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME@.h>
+#include <gr_io_signature.h>
+#include <assert.h>
+#include <iostream>
+
+static const float INF = 1.0e9;
+
+@SPTR_NAME@
+trellis_make_@BASE_NAME@ (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK)
+{
+ return @SPTR_NAME@ (new @NAME@ (FSM,K,S0,SK));
+}
+
+@NAME@::@NAME@ (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK)
+ : gr_block ("@BASE_NAME@",
+ gr_make_io_signature (1, -1, sizeof (float)),
+ gr_make_io_signature (1, -1, sizeof (@TYPE@))),
+ d_FSM (FSM),
+ d_K (K),
+ d_S0 (S0),
+ d_SK (SK),
+ d_trace(FSM.S()*K)
+{
+ set_relative_rate (1.0 / ((double) d_FSM.O()));
+ set_output_multiple (d_K);
+}
+
+
+void
+@NAME@::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+ assert (noutput_items % d_K == 0);
+ int input_required = d_FSM.O() * noutput_items ;
+ unsigned ninputs = ninput_items_required.size();
+ for (unsigned int i = 0; i < ninputs; i++) {
+ ninput_items_required[i] = input_required;
+ }
+}
+
+
+
+
+void viterbi_algorithm(const int I, const int S, const int O,
+ const std::vector<int> &NS,
+ const std::vector<int> &OS,
+ const std::vector<int> &PS,
+ const std::vector<int> &PI,
+ const int K,
+ const int S0,const int SK,
+ const float *in, @TYPE@ *out,
+ std::vector<int> &trace)
+{
+ std::vector<float> alpha(S*2);
+ int alphai;
+ float norm,mm,minm;
+ int minmi;
+ int st;
+
+
+ if(S0<0) { // initial state not specified
+ for(int i=0;i<S;i++) alpha[0*S+i]=0;
+ }
+ else {
+ for(int i=0;i<S;i++) alpha[0*S+i]=INF;
+ alpha[0*S+S0]=0.0;
+ }
+
+ alphai=0;
+ for(int k=0;k<K;k++) {
+ norm=INF;
+ for(int j=0;j<S;j++) { // for each next state do ACS
+ minm=INF;
+ minmi=0;
+ for(int i=0;i<I;i++) {
+ int i0 = j*I+i;
+ if((mm=alpha[alphai*S+PS[i0]]+in[k*O+OS[PS[i0]*I+PI[i0]]])<minm)
+ minm=mm,minmi=i;
+ }
+ trace[k*S+j]=minmi;
+ alpha[((alphai+1)%2)*S+j]=minm;
+ if(minm<norm) norm=minm;
+ }
+ for(int j=0;j<S;j++)
+ alpha[((alphai+1)%2)*S+j]-=norm; // normalize total metrics so they do not explode
+ alphai=(alphai+1)%2;
+ }
+
+ if(SK<0) { // final state not specified
+ minm=INF;
+ minmi=0;
+ for(int i=0;i<S;i++)
+ if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i;
+ st=minmi;
+ }
+ else {
+ st=SK;
+ }
+
+ for(int k=K-1;k>=0;k--) { // traceback
+ int i0=st*I+trace[k*S+st];
+ out[k]= (@TYPE@) PI[i0];
+ st=PS[i0];
+ }
+
+}
+
+
+
+
+
+
+int
+@NAME@::general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+ assert (noutput_items % d_K == 0);
+ int nblocks = noutput_items / d_K;
+
+ for (int m=0;m<nstreams;m++) {
+ const float *in = (const float *) input_items[m];
+ @TYPE@ *out = (@TYPE@ *) output_items[m];
+ for (int n=0;n<nblocks;n++) {
+ viterbi_algorithm(d_FSM.I(),d_FSM.S(),d_FSM.O(),d_FSM.NS(),d_FSM.OS(),d_FSM.PS(),d_FSM.PI(),d_K,d_S0,d_SK,&(in[n*d_K*d_FSM.O()]),&(out[n*d_K]),d_trace);
+ }
+ }
+
+ consume_each (d_FSM.O() * noutput_items );
+ return noutput_items;
+}
diff --git a/gr-trellis/src/lib/trellis_viterbi_X.h.t b/gr-trellis/src/lib/trellis_viterbi_X.h.t
new file mode 100644
index 000000000..f1b8e0062
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_X.h.t
@@ -0,0 +1,78 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include "fsm.h"
+#include <gr_block.h>
+
+class @NAME@;
+typedef boost::shared_ptr<@NAME@> @SPTR_NAME@;
+
+@SPTR_NAME@ trellis_make_@BASE_NAME@ (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+
+
+class @NAME@ : public gr_block
+{
+ fsm d_FSM;
+ int d_K;
+ int d_S0;
+ int d_SK;
+ std::vector<int> d_trace;
+
+ friend @SPTR_NAME@ trellis_make_@BASE_NAME@ (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+
+ @NAME@ (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int K () const { return d_K; }
+ int S0 () const { return d_S0; }
+ int SK () const { return d_SK; }
+ //std::vector<int> trace () const { return d_trace; }
+ void forecast (int noutput_items,
+ gr_vector_int &ninput_items_required);
+ int general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_viterbi_X.i.t b/gr-trellis/src/lib/trellis_viterbi_X.i.t
new file mode 100644
index 000000000..605251e4d
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_X.i.t
@@ -0,0 +1,49 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// @WARNING@
+
+GR_SWIG_BLOCK_MAGIC(trellis,@BASE_NAME@);
+
+@SPTR_NAME@ trellis_make_@BASE_NAME@ (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+
+class @NAME@ : public gr_block
+{
+private:
+ @NAME@ (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int K () const { return d_K; }
+ int S0 () const { return d_S0; }
+ int SK () const { return d_SK; }
+ //std::vector<short> trace () const { return d_trace; }
+};
diff --git a/gr-trellis/src/lib/trellis_viterbi_b.cc b/gr-trellis/src/lib/trellis_viterbi_b.cc
new file mode 100644
index 000000000..dbcd85bbd
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_b.cc
@@ -0,0 +1,167 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_viterbi_b.h>
+#include <gr_io_signature.h>
+#include <assert.h>
+#include <iostream>
+
+static const float INF = 1.0e9;
+
+trellis_viterbi_b_sptr
+trellis_make_viterbi_b (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK)
+{
+ return trellis_viterbi_b_sptr (new trellis_viterbi_b (FSM,K,S0,SK));
+}
+
+trellis_viterbi_b::trellis_viterbi_b (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK)
+ : gr_block ("viterbi_b",
+ gr_make_io_signature (1, -1, sizeof (float)),
+ gr_make_io_signature (1, -1, sizeof (unsigned char))),
+ d_FSM (FSM),
+ d_K (K),
+ d_S0 (S0),
+ d_SK (SK),
+ d_trace(FSM.S()*K)
+{
+ set_relative_rate (1.0 / ((double) d_FSM.O()));
+ set_output_multiple (d_K);
+}
+
+
+void
+trellis_viterbi_b::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+ assert (noutput_items % d_K == 0);
+ int input_required = d_FSM.O() * noutput_items ;
+ unsigned ninputs = ninput_items_required.size();
+ for (unsigned int i = 0; i < ninputs; i++) {
+ ninput_items_required[i] = input_required;
+ }
+}
+
+
+
+
+void viterbi_algorithm(const int I, const int S, const int O,
+ const std::vector<int> &NS,
+ const std::vector<int> &OS,
+ const std::vector<int> &PS,
+ const std::vector<int> &PI,
+ const int K,
+ const int S0,const int SK,
+ const float *in, unsigned char *out,
+ std::vector<int> &trace)
+{
+ std::vector<float> alpha(S*2);
+ int alphai;
+ float norm,mm,minm;
+ int minmi;
+ int st;
+
+
+ if(S0<0) { // initial state not specified
+ for(int i=0;i<S;i++) alpha[0*S+i]=0;
+ }
+ else {
+ for(int i=0;i<S;i++) alpha[0*S+i]=INF;
+ alpha[0*S+S0]=0.0;
+ }
+
+ alphai=0;
+ for(int k=0;k<K;k++) {
+ norm=INF;
+ for(int j=0;j<S;j++) { // for each next state do ACS
+ minm=INF;
+ minmi=0;
+ for(int i=0;i<I;i++) {
+ int i0 = j*I+i;
+ if((mm=alpha[alphai*S+PS[i0]]+in[k*O+OS[PS[i0]*I+PI[i0]]])<minm)
+ minm=mm,minmi=i;
+ }
+ trace[k*S+j]=minmi;
+ alpha[((alphai+1)%2)*S+j]=minm;
+ if(minm<norm) norm=minm;
+ }
+ for(int j=0;j<S;j++)
+ alpha[((alphai+1)%2)*S+j]-=norm; // normalize total metrics so they do not explode
+ alphai=(alphai+1)%2;
+ }
+
+ if(SK<0) { // final state not specified
+ minm=INF;
+ minmi=0;
+ for(int i=0;i<S;i++)
+ if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i;
+ st=minmi;
+ }
+ else {
+ st=SK;
+ }
+
+ for(int k=K-1;k>=0;k--) { // traceback
+ int i0=st*I+trace[k*S+st];
+ out[k]= (unsigned char) PI[i0];
+ st=PS[i0];
+ }
+
+}
+
+
+
+
+
+
+int
+trellis_viterbi_b::general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+ assert (noutput_items % d_K == 0);
+ int nblocks = noutput_items / d_K;
+
+ for (int m=0;m<nstreams;m++) {
+ const float *in = (const float *) input_items[m];
+ unsigned char *out = (unsigned char *) output_items[m];
+ for (int n=0;n<nblocks;n++) {
+ viterbi_algorithm(d_FSM.I(),d_FSM.S(),d_FSM.O(),d_FSM.NS(),d_FSM.OS(),d_FSM.PS(),d_FSM.PI(),d_K,d_S0,d_SK,&(in[n*d_K*d_FSM.O()]),&(out[n*d_K]),d_trace);
+ }
+ }
+
+ consume_each (d_FSM.O() * noutput_items );
+ return noutput_items;
+}
diff --git a/gr-trellis/src/lib/trellis_viterbi_b.h b/gr-trellis/src/lib/trellis_viterbi_b.h
new file mode 100644
index 000000000..a4fa533e8
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_b.h
@@ -0,0 +1,78 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+#ifndef INCLUDED_TRELLIS_VITERBI_B_H
+#define INCLUDED_TRELLIS_VITERBI_B_H
+
+#include "fsm.h"
+#include <gr_block.h>
+
+class trellis_viterbi_b;
+typedef boost::shared_ptr<trellis_viterbi_b> trellis_viterbi_b_sptr;
+
+trellis_viterbi_b_sptr trellis_make_viterbi_b (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+
+
+class trellis_viterbi_b : public gr_block
+{
+ fsm d_FSM;
+ int d_K;
+ int d_S0;
+ int d_SK;
+ std::vector<int> d_trace;
+
+ friend trellis_viterbi_b_sptr trellis_make_viterbi_b (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+
+ trellis_viterbi_b (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int K () const { return d_K; }
+ int S0 () const { return d_S0; }
+ int SK () const { return d_SK; }
+ //std::vector<int> trace () const { return d_trace; }
+ void forecast (int noutput_items,
+ gr_vector_int &ninput_items_required);
+ int general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_viterbi_b.i b/gr-trellis/src/lib/trellis_viterbi_b.i
new file mode 100644
index 000000000..44fca365b
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_b.i
@@ -0,0 +1,49 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,viterbi_b);
+
+trellis_viterbi_b_sptr trellis_make_viterbi_b (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+
+class trellis_viterbi_b : public gr_block
+{
+private:
+ trellis_viterbi_b (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int K () const { return d_K; }
+ int S0 () const { return d_S0; }
+ int SK () const { return d_SK; }
+ //std::vector<short> trace () const { return d_trace; }
+};
diff --git a/gr-trellis/src/lib/trellis_viterbi_combined_X.cc.t b/gr-trellis/src/lib/trellis_viterbi_combined_X.cc.t
new file mode 100644
index 000000000..e62d90fea
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_combined_X.cc.t
@@ -0,0 +1,182 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME@.h>
+#include <gr_io_signature.h>
+#include <assert.h>
+#include <iostream>
+
+static const float INF = 1.0e9;
+
+@SPTR_NAME@
+trellis_make_@BASE_NAME@ (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE)
+{
+ return @SPTR_NAME@ (new @NAME@ (FSM,D,TABLE,K,S0,SK,TYPE));
+}
+
+@NAME@::@NAME@ (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE)
+ : gr_block ("@BASE_NAME@",
+ gr_make_io_signature (1, -1, sizeof (float)),
+ gr_make_io_signature (1, -1, sizeof (@TYPE@))),
+ d_FSM (FSM),
+ d_D (D),
+ d_TABLE (TABLE),
+ d_K (K),
+ d_S0 (S0),
+ d_SK (SK),
+ d_TYPE (TYPE),
+ d_trace(FSM.S()*K)
+{
+ set_relative_rate (1.0 / ((double) d_D));
+ set_output_multiple (d_K);
+}
+
+
+void
+@NAME@::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+ assert (noutput_items % d_K == 0);
+ int input_required = d_D * noutput_items ;
+ unsigned ninputs = ninput_items_required.size();
+ for (unsigned int i = 0; i < ninputs; i++) {
+ ninput_items_required[i] = input_required;
+ }
+}
+
+
+
+
+void viterbi_algorithm_combined(const int I, const int S, const int O,
+ const std::vector<int> &NS,
+ const std::vector<int> &OS,
+ const std::vector<int> &PS,
+ const std::vector<int> &PI,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,const int SK,
+ const trellis_metric_type_t TYPE,
+ const float *in, @TYPE@ *out,
+ std::vector<int> &trace)
+{
+ std::vector<float> alpha(S*2);
+ float *metric = new float[O];
+ int alphai;
+ float norm,mm,minm;
+ int minmi;
+ int st;
+
+ if(S0<0) { // initial state not specified
+ for(int i=0;i<S;i++) alpha[0*S+i]=0;
+ }
+ else {
+ for(int i=0;i<S;i++) alpha[0*S+i]=INF;
+ alpha[0*S+S0]=0.0;
+ }
+
+ alphai=0;
+ for(int k=0;k<K;k++) {
+ calc_metric_f(O, D, TABLE, &(in[k*D]), metric,TYPE); // calc metrics
+ norm=INF;
+ for(int j=0;j<S;j++) { // for each next state do ACS
+ minm=INF;
+ minmi=0;
+ for(int i=0;i<I;i++) {
+ int i0 = j*I+i;
+ if((mm=alpha[alphai*S+PS[i0]]+metric[OS[PS[i0]*I+PI[i0]]])<minm)
+ minm=mm,minmi=i;
+ }
+ trace[k*S+j]=minmi;
+ alpha[((alphai+1)%2)*S+j]=minm;
+ if(minm<norm) norm=minm;
+ }
+ for(int j=0;j<S;j++)
+ alpha[((alphai+1)%2)*S+j]-=norm; // normalize total metrics so they do not explode
+ alphai=(alphai+1)%2;
+ }
+
+ if(SK<0) { // final state not specified
+ minm=INF;
+ minmi=0;
+ for(int i=0;i<S;i++)
+ if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i;
+ st=minmi;
+ }
+ else {
+ st=SK;
+ }
+
+ for(int k=K-1;k>=0;k--) { // traceback
+ int i0=st*I+trace[k*S+st];
+ out[k]= (@TYPE@) PI[i0];
+ st=PS[i0];
+ }
+
+ delete [] metric;
+
+}
+
+
+
+
+
+
+int
+@NAME@::general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+ assert (noutput_items % d_K == 0);
+ int nblocks = noutput_items / d_K;
+
+ for (int m=0;m<nstreams;m++) {
+ const float *in = (const float *) input_items[m];
+ @TYPE@ *out = (@TYPE@ *) output_items[m];
+ for (int n=0;n<nblocks;n++) {
+ viterbi_algorithm_combined(d_FSM.I(),d_FSM.S(),d_FSM.O(),d_FSM.NS(),d_FSM.OS(),d_FSM.PS(),d_FSM.PI(),d_D,d_TABLE,d_K,d_S0,d_SK,d_TYPE,&(in[n*d_K*d_D]),&(out[n*d_K]),d_trace);
+ }
+ }
+
+ consume_each (d_D * noutput_items );
+ return noutput_items;
+}
diff --git a/gr-trellis/src/lib/trellis_viterbi_combined_X.h.t b/gr-trellis/src/lib/trellis_viterbi_combined_X.h.t
new file mode 100644
index 000000000..8d7059a55
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_combined_X.h.t
@@ -0,0 +1,93 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include "fsm.h"
+#include <gr_block.h>
+#include "trellis_calc_metric.h"
+
+class @NAME@;
+typedef boost::shared_ptr<@NAME@> @SPTR_NAME@;
+
+@SPTR_NAME@ trellis_make_@BASE_NAME@ (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+
+class @NAME@ : public gr_block
+{
+ fsm d_FSM;
+ int d_D;
+ std::vector<float> d_TABLE;
+ int d_K;
+ int d_S0;
+ int d_SK;
+ trellis_metric_type_t d_TYPE;
+ std::vector<int> d_trace;
+
+ friend @SPTR_NAME@ trellis_make_@BASE_NAME@ (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+
+ @NAME@ (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int D () const { return d_D; }
+ std::vector<float> TABLE () const { return d_TABLE; }
+ int K () const { return d_K; }
+ int S0 () const { return d_S0; }
+ int SK () const { return d_SK; }
+ trellis_metric_type_t TYPE () const { return d_TYPE; }
+ //std::vector<int> trace () const { return d_trace; }
+ void forecast (int noutput_items,
+ gr_vector_int &ninput_items_required);
+ int general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_viterbi_combined_X.i.t b/gr-trellis/src/lib/trellis_viterbi_combined_X.i.t
new file mode 100644
index 000000000..388e0626e
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_combined_X.i.t
@@ -0,0 +1,58 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// @WARNING@
+
+GR_SWIG_BLOCK_MAGIC(trellis,@BASE_NAME@);
+
+@SPTR_NAME@ trellis_make_@BASE_NAME@ (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+
+class @NAME@ : public gr_block
+{
+private:
+ @NAME@ (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int D () const { return d_D; }
+ std::vector<float> TABLE () const { return d_TABLE; }
+ int K () const { return d_K; }
+ int S0 () const { return d_S0; }
+ int SK () const { return d_SK; }
+ trellis_metric_type_t TYPE () const { return d_TYPE; }
+ //std::vector<short> trace () const { return d_trace; }
+};
diff --git a/gr-trellis/src/lib/trellis_viterbi_combined_b.cc b/gr-trellis/src/lib/trellis_viterbi_combined_b.cc
new file mode 100644
index 000000000..ee4f5f8f8
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_combined_b.cc
@@ -0,0 +1,182 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_viterbi_combined_b.h>
+#include <gr_io_signature.h>
+#include <assert.h>
+#include <iostream>
+
+static const float INF = 1.0e9;
+
+trellis_viterbi_combined_b_sptr
+trellis_make_viterbi_combined_b (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE)
+{
+ return trellis_viterbi_combined_b_sptr (new trellis_viterbi_combined_b (FSM,D,TABLE,K,S0,SK,TYPE));
+}
+
+trellis_viterbi_combined_b::trellis_viterbi_combined_b (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE)
+ : gr_block ("viterbi_combined_b",
+ gr_make_io_signature (1, -1, sizeof (float)),
+ gr_make_io_signature (1, -1, sizeof (unsigned char))),
+ d_FSM (FSM),
+ d_D (D),
+ d_TABLE (TABLE),
+ d_K (K),
+ d_S0 (S0),
+ d_SK (SK),
+ d_TYPE (TYPE),
+ d_trace(FSM.S()*K)
+{
+ set_relative_rate (1.0 / ((double) d_D));
+ set_output_multiple (d_K);
+}
+
+
+void
+trellis_viterbi_combined_b::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+ assert (noutput_items % d_K == 0);
+ int input_required = d_D * noutput_items ;
+ unsigned ninputs = ninput_items_required.size();
+ for (unsigned int i = 0; i < ninputs; i++) {
+ ninput_items_required[i] = input_required;
+ }
+}
+
+
+
+
+void viterbi_algorithm_combined(const int I, const int S, const int O,
+ const std::vector<int> &NS,
+ const std::vector<int> &OS,
+ const std::vector<int> &PS,
+ const std::vector<int> &PI,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,const int SK,
+ const trellis_metric_type_t TYPE,
+ const float *in, unsigned char *out,
+ std::vector<int> &trace)
+{
+ std::vector<float> alpha(S*2);
+ float *metric = new float[O];
+ int alphai;
+ float norm,mm,minm;
+ int minmi;
+ int st;
+
+ if(S0<0) { // initial state not specified
+ for(int i=0;i<S;i++) alpha[0*S+i]=0;
+ }
+ else {
+ for(int i=0;i<S;i++) alpha[0*S+i]=INF;
+ alpha[0*S+S0]=0.0;
+ }
+
+ alphai=0;
+ for(int k=0;k<K;k++) {
+ calc_metric_f(O, D, TABLE, &(in[k*D]), metric,TYPE); // calc metrics
+ norm=INF;
+ for(int j=0;j<S;j++) { // for each next state do ACS
+ minm=INF;
+ minmi=0;
+ for(int i=0;i<I;i++) {
+ int i0 = j*I+i;
+ if((mm=alpha[alphai*S+PS[i0]]+metric[OS[PS[i0]*I+PI[i0]]])<minm)
+ minm=mm,minmi=i;
+ }
+ trace[k*S+j]=minmi;
+ alpha[((alphai+1)%2)*S+j]=minm;
+ if(minm<norm) norm=minm;
+ }
+ for(int j=0;j<S;j++)
+ alpha[((alphai+1)%2)*S+j]-=norm; // normalize total metrics so they do not explode
+ alphai=(alphai+1)%2;
+ }
+
+ if(SK<0) { // final state not specified
+ minm=INF;
+ minmi=0;
+ for(int i=0;i<S;i++)
+ if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i;
+ st=minmi;
+ }
+ else {
+ st=SK;
+ }
+
+ for(int k=K-1;k>=0;k--) { // traceback
+ int i0=st*I+trace[k*S+st];
+ out[k]= (unsigned char) PI[i0];
+ st=PS[i0];
+ }
+
+ delete [] metric;
+
+}
+
+
+
+
+
+
+int
+trellis_viterbi_combined_b::general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+ assert (noutput_items % d_K == 0);
+ int nblocks = noutput_items / d_K;
+
+ for (int m=0;m<nstreams;m++) {
+ const float *in = (const float *) input_items[m];
+ unsigned char *out = (unsigned char *) output_items[m];
+ for (int n=0;n<nblocks;n++) {
+ viterbi_algorithm_combined(d_FSM.I(),d_FSM.S(),d_FSM.O(),d_FSM.NS(),d_FSM.OS(),d_FSM.PS(),d_FSM.PI(),d_D,d_TABLE,d_K,d_S0,d_SK,d_TYPE,&(in[n*d_K*d_D]),&(out[n*d_K]),d_trace);
+ }
+ }
+
+ consume_each (d_D * noutput_items );
+ return noutput_items;
+}
diff --git a/gr-trellis/src/lib/trellis_viterbi_combined_b.h b/gr-trellis/src/lib/trellis_viterbi_combined_b.h
new file mode 100644
index 000000000..f523c5ce1
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_combined_b.h
@@ -0,0 +1,93 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+#ifndef INCLUDED_TRELLIS_VITERBI_COMBINED_B_H
+#define INCLUDED_TRELLIS_VITERBI_COMBINED_B_H
+
+#include "fsm.h"
+#include <gr_block.h>
+#include "trellis_calc_metric.h"
+
+class trellis_viterbi_combined_b;
+typedef boost::shared_ptr<trellis_viterbi_combined_b> trellis_viterbi_combined_b_sptr;
+
+trellis_viterbi_combined_b_sptr trellis_make_viterbi_combined_b (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+
+class trellis_viterbi_combined_b : public gr_block
+{
+ fsm d_FSM;
+ int d_D;
+ std::vector<float> d_TABLE;
+ int d_K;
+ int d_S0;
+ int d_SK;
+ trellis_metric_type_t d_TYPE;
+ std::vector<int> d_trace;
+
+ friend trellis_viterbi_combined_b_sptr trellis_make_viterbi_combined_b (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+
+ trellis_viterbi_combined_b (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int D () const { return d_D; }
+ std::vector<float> TABLE () const { return d_TABLE; }
+ int K () const { return d_K; }
+ int S0 () const { return d_S0; }
+ int SK () const { return d_SK; }
+ trellis_metric_type_t TYPE () const { return d_TYPE; }
+ //std::vector<int> trace () const { return d_trace; }
+ void forecast (int noutput_items,
+ gr_vector_int &ninput_items_required);
+ int general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_viterbi_combined_b.i b/gr-trellis/src/lib/trellis_viterbi_combined_b.i
new file mode 100644
index 000000000..44b4aa431
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_combined_b.i
@@ -0,0 +1,58 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,viterbi_combined_b);
+
+trellis_viterbi_combined_b_sptr trellis_make_viterbi_combined_b (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+
+class trellis_viterbi_combined_b : public gr_block
+{
+private:
+ trellis_viterbi_combined_b (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int D () const { return d_D; }
+ std::vector<float> TABLE () const { return d_TABLE; }
+ int K () const { return d_K; }
+ int S0 () const { return d_S0; }
+ int SK () const { return d_SK; }
+ trellis_metric_type_t TYPE () const { return d_TYPE; }
+ //std::vector<short> trace () const { return d_trace; }
+};
diff --git a/gr-trellis/src/lib/trellis_viterbi_combined_i.cc b/gr-trellis/src/lib/trellis_viterbi_combined_i.cc
new file mode 100644
index 000000000..b415f064e
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_combined_i.cc
@@ -0,0 +1,182 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_viterbi_combined_i.h>
+#include <gr_io_signature.h>
+#include <assert.h>
+#include <iostream>
+
+static const float INF = 1.0e9;
+
+trellis_viterbi_combined_i_sptr
+trellis_make_viterbi_combined_i (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE)
+{
+ return trellis_viterbi_combined_i_sptr (new trellis_viterbi_combined_i (FSM,D,TABLE,K,S0,SK,TYPE));
+}
+
+trellis_viterbi_combined_i::trellis_viterbi_combined_i (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE)
+ : gr_block ("viterbi_combined_i",
+ gr_make_io_signature (1, -1, sizeof (float)),
+ gr_make_io_signature (1, -1, sizeof (int))),
+ d_FSM (FSM),
+ d_D (D),
+ d_TABLE (TABLE),
+ d_K (K),
+ d_S0 (S0),
+ d_SK (SK),
+ d_TYPE (TYPE),
+ d_trace(FSM.S()*K)
+{
+ set_relative_rate (1.0 / ((double) d_D));
+ set_output_multiple (d_K);
+}
+
+
+void
+trellis_viterbi_combined_i::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+ assert (noutput_items % d_K == 0);
+ int input_required = d_D * noutput_items ;
+ unsigned ninputs = ninput_items_required.size();
+ for (unsigned int i = 0; i < ninputs; i++) {
+ ninput_items_required[i] = input_required;
+ }
+}
+
+
+
+
+void viterbi_algorithm_combined(const int I, const int S, const int O,
+ const std::vector<int> &NS,
+ const std::vector<int> &OS,
+ const std::vector<int> &PS,
+ const std::vector<int> &PI,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,const int SK,
+ const trellis_metric_type_t TYPE,
+ const float *in, int *out,
+ std::vector<int> &trace)
+{
+ std::vector<float> alpha(S*2);
+ float *metric = new float[O];
+ int alphai;
+ float norm,mm,minm;
+ int minmi;
+ int st;
+
+ if(S0<0) { // initial state not specified
+ for(int i=0;i<S;i++) alpha[0*S+i]=0;
+ }
+ else {
+ for(int i=0;i<S;i++) alpha[0*S+i]=INF;
+ alpha[0*S+S0]=0.0;
+ }
+
+ alphai=0;
+ for(int k=0;k<K;k++) {
+ calc_metric_f(O, D, TABLE, &(in[k*D]), metric,TYPE); // calc metrics
+ norm=INF;
+ for(int j=0;j<S;j++) { // for each next state do ACS
+ minm=INF;
+ minmi=0;
+ for(int i=0;i<I;i++) {
+ int i0 = j*I+i;
+ if((mm=alpha[alphai*S+PS[i0]]+metric[OS[PS[i0]*I+PI[i0]]])<minm)
+ minm=mm,minmi=i;
+ }
+ trace[k*S+j]=minmi;
+ alpha[((alphai+1)%2)*S+j]=minm;
+ if(minm<norm) norm=minm;
+ }
+ for(int j=0;j<S;j++)
+ alpha[((alphai+1)%2)*S+j]-=norm; // normalize total metrics so they do not explode
+ alphai=(alphai+1)%2;
+ }
+
+ if(SK<0) { // final state not specified
+ minm=INF;
+ minmi=0;
+ for(int i=0;i<S;i++)
+ if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i;
+ st=minmi;
+ }
+ else {
+ st=SK;
+ }
+
+ for(int k=K-1;k>=0;k--) { // traceback
+ int i0=st*I+trace[k*S+st];
+ out[k]= (int) PI[i0];
+ st=PS[i0];
+ }
+
+ delete [] metric;
+
+}
+
+
+
+
+
+
+int
+trellis_viterbi_combined_i::general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+ assert (noutput_items % d_K == 0);
+ int nblocks = noutput_items / d_K;
+
+ for (int m=0;m<nstreams;m++) {
+ const float *in = (const float *) input_items[m];
+ int *out = (int *) output_items[m];
+ for (int n=0;n<nblocks;n++) {
+ viterbi_algorithm_combined(d_FSM.I(),d_FSM.S(),d_FSM.O(),d_FSM.NS(),d_FSM.OS(),d_FSM.PS(),d_FSM.PI(),d_D,d_TABLE,d_K,d_S0,d_SK,d_TYPE,&(in[n*d_K*d_D]),&(out[n*d_K]),d_trace);
+ }
+ }
+
+ consume_each (d_D * noutput_items );
+ return noutput_items;
+}
diff --git a/gr-trellis/src/lib/trellis_viterbi_combined_i.h b/gr-trellis/src/lib/trellis_viterbi_combined_i.h
new file mode 100644
index 000000000..171fcb93d
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_combined_i.h
@@ -0,0 +1,93 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+#ifndef INCLUDED_TRELLIS_VITERBI_COMBINED_I_H
+#define INCLUDED_TRELLIS_VITERBI_COMBINED_I_H
+
+#include "fsm.h"
+#include <gr_block.h>
+#include "trellis_calc_metric.h"
+
+class trellis_viterbi_combined_i;
+typedef boost::shared_ptr<trellis_viterbi_combined_i> trellis_viterbi_combined_i_sptr;
+
+trellis_viterbi_combined_i_sptr trellis_make_viterbi_combined_i (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+
+class trellis_viterbi_combined_i : public gr_block
+{
+ fsm d_FSM;
+ int d_D;
+ std::vector<float> d_TABLE;
+ int d_K;
+ int d_S0;
+ int d_SK;
+ trellis_metric_type_t d_TYPE;
+ std::vector<int> d_trace;
+
+ friend trellis_viterbi_combined_i_sptr trellis_make_viterbi_combined_i (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+
+ trellis_viterbi_combined_i (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int D () const { return d_D; }
+ std::vector<float> TABLE () const { return d_TABLE; }
+ int K () const { return d_K; }
+ int S0 () const { return d_S0; }
+ int SK () const { return d_SK; }
+ trellis_metric_type_t TYPE () const { return d_TYPE; }
+ //std::vector<int> trace () const { return d_trace; }
+ void forecast (int noutput_items,
+ gr_vector_int &ninput_items_required);
+ int general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_viterbi_combined_i.i b/gr-trellis/src/lib/trellis_viterbi_combined_i.i
new file mode 100644
index 000000000..4b8355e0e
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_combined_i.i
@@ -0,0 +1,58 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,viterbi_combined_i);
+
+trellis_viterbi_combined_i_sptr trellis_make_viterbi_combined_i (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+
+class trellis_viterbi_combined_i : public gr_block
+{
+private:
+ trellis_viterbi_combined_i (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int D () const { return d_D; }
+ std::vector<float> TABLE () const { return d_TABLE; }
+ int K () const { return d_K; }
+ int S0 () const { return d_S0; }
+ int SK () const { return d_SK; }
+ trellis_metric_type_t TYPE () const { return d_TYPE; }
+ //std::vector<short> trace () const { return d_trace; }
+};
diff --git a/gr-trellis/src/lib/trellis_viterbi_combined_s.cc b/gr-trellis/src/lib/trellis_viterbi_combined_s.cc
new file mode 100644
index 000000000..6a7883420
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_combined_s.cc
@@ -0,0 +1,182 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_viterbi_combined_s.h>
+#include <gr_io_signature.h>
+#include <assert.h>
+#include <iostream>
+
+static const float INF = 1.0e9;
+
+trellis_viterbi_combined_s_sptr
+trellis_make_viterbi_combined_s (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE)
+{
+ return trellis_viterbi_combined_s_sptr (new trellis_viterbi_combined_s (FSM,D,TABLE,K,S0,SK,TYPE));
+}
+
+trellis_viterbi_combined_s::trellis_viterbi_combined_s (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE)
+ : gr_block ("viterbi_combined_s",
+ gr_make_io_signature (1, -1, sizeof (float)),
+ gr_make_io_signature (1, -1, sizeof (short))),
+ d_FSM (FSM),
+ d_D (D),
+ d_TABLE (TABLE),
+ d_K (K),
+ d_S0 (S0),
+ d_SK (SK),
+ d_TYPE (TYPE),
+ d_trace(FSM.S()*K)
+{
+ set_relative_rate (1.0 / ((double) d_D));
+ set_output_multiple (d_K);
+}
+
+
+void
+trellis_viterbi_combined_s::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+ assert (noutput_items % d_K == 0);
+ int input_required = d_D * noutput_items ;
+ unsigned ninputs = ninput_items_required.size();
+ for (unsigned int i = 0; i < ninputs; i++) {
+ ninput_items_required[i] = input_required;
+ }
+}
+
+
+
+
+void viterbi_algorithm_combined(const int I, const int S, const int O,
+ const std::vector<int> &NS,
+ const std::vector<int> &OS,
+ const std::vector<int> &PS,
+ const std::vector<int> &PI,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,const int SK,
+ const trellis_metric_type_t TYPE,
+ const float *in, short *out,
+ std::vector<int> &trace)
+{
+ std::vector<float> alpha(S*2);
+ float *metric = new float[O];
+ int alphai;
+ float norm,mm,minm;
+ int minmi;
+ int st;
+
+ if(S0<0) { // initial state not specified
+ for(int i=0;i<S;i++) alpha[0*S+i]=0;
+ }
+ else {
+ for(int i=0;i<S;i++) alpha[0*S+i]=INF;
+ alpha[0*S+S0]=0.0;
+ }
+
+ alphai=0;
+ for(int k=0;k<K;k++) {
+ calc_metric_f(O, D, TABLE, &(in[k*D]), metric,TYPE); // calc metrics
+ norm=INF;
+ for(int j=0;j<S;j++) { // for each next state do ACS
+ minm=INF;
+ minmi=0;
+ for(int i=0;i<I;i++) {
+ int i0 = j*I+i;
+ if((mm=alpha[alphai*S+PS[i0]]+metric[OS[PS[i0]*I+PI[i0]]])<minm)
+ minm=mm,minmi=i;
+ }
+ trace[k*S+j]=minmi;
+ alpha[((alphai+1)%2)*S+j]=minm;
+ if(minm<norm) norm=minm;
+ }
+ for(int j=0;j<S;j++)
+ alpha[((alphai+1)%2)*S+j]-=norm; // normalize total metrics so they do not explode
+ alphai=(alphai+1)%2;
+ }
+
+ if(SK<0) { // final state not specified
+ minm=INF;
+ minmi=0;
+ for(int i=0;i<S;i++)
+ if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i;
+ st=minmi;
+ }
+ else {
+ st=SK;
+ }
+
+ for(int k=K-1;k>=0;k--) { // traceback
+ int i0=st*I+trace[k*S+st];
+ out[k]= (short) PI[i0];
+ st=PS[i0];
+ }
+
+ delete [] metric;
+
+}
+
+
+
+
+
+
+int
+trellis_viterbi_combined_s::general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+ assert (noutput_items % d_K == 0);
+ int nblocks = noutput_items / d_K;
+
+ for (int m=0;m<nstreams;m++) {
+ const float *in = (const float *) input_items[m];
+ short *out = (short *) output_items[m];
+ for (int n=0;n<nblocks;n++) {
+ viterbi_algorithm_combined(d_FSM.I(),d_FSM.S(),d_FSM.O(),d_FSM.NS(),d_FSM.OS(),d_FSM.PS(),d_FSM.PI(),d_D,d_TABLE,d_K,d_S0,d_SK,d_TYPE,&(in[n*d_K*d_D]),&(out[n*d_K]),d_trace);
+ }
+ }
+
+ consume_each (d_D * noutput_items );
+ return noutput_items;
+}
diff --git a/gr-trellis/src/lib/trellis_viterbi_combined_s.h b/gr-trellis/src/lib/trellis_viterbi_combined_s.h
new file mode 100644
index 000000000..5b74b35a9
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_combined_s.h
@@ -0,0 +1,93 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+#ifndef INCLUDED_TRELLIS_VITERBI_COMBINED_S_H
+#define INCLUDED_TRELLIS_VITERBI_COMBINED_S_H
+
+#include "fsm.h"
+#include <gr_block.h>
+#include "trellis_calc_metric.h"
+
+class trellis_viterbi_combined_s;
+typedef boost::shared_ptr<trellis_viterbi_combined_s> trellis_viterbi_combined_s_sptr;
+
+trellis_viterbi_combined_s_sptr trellis_make_viterbi_combined_s (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+
+class trellis_viterbi_combined_s : public gr_block
+{
+ fsm d_FSM;
+ int d_D;
+ std::vector<float> d_TABLE;
+ int d_K;
+ int d_S0;
+ int d_SK;
+ trellis_metric_type_t d_TYPE;
+ std::vector<int> d_trace;
+
+ friend trellis_viterbi_combined_s_sptr trellis_make_viterbi_combined_s (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+
+ trellis_viterbi_combined_s (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int D () const { return d_D; }
+ std::vector<float> TABLE () const { return d_TABLE; }
+ int K () const { return d_K; }
+ int S0 () const { return d_S0; }
+ int SK () const { return d_SK; }
+ trellis_metric_type_t TYPE () const { return d_TYPE; }
+ //std::vector<int> trace () const { return d_trace; }
+ void forecast (int noutput_items,
+ gr_vector_int &ninput_items_required);
+ int general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_viterbi_combined_s.i b/gr-trellis/src/lib/trellis_viterbi_combined_s.i
new file mode 100644
index 000000000..ddac52692
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_combined_s.i
@@ -0,0 +1,58 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,viterbi_combined_s);
+
+trellis_viterbi_combined_s_sptr trellis_make_viterbi_combined_s (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+
+class trellis_viterbi_combined_s : public gr_block
+{
+private:
+ trellis_viterbi_combined_s (
+ const fsm &FSM,
+ const int D,
+ const std::vector<float> &TABLE,
+ const int K,
+ const int S0,
+ const int SK,
+ const trellis_metric_type_t TYPE);
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int D () const { return d_D; }
+ std::vector<float> TABLE () const { return d_TABLE; }
+ int K () const { return d_K; }
+ int S0 () const { return d_S0; }
+ int SK () const { return d_SK; }
+ trellis_metric_type_t TYPE () const { return d_TYPE; }
+ //std::vector<short> trace () const { return d_trace; }
+};
diff --git a/gr-trellis/src/lib/trellis_viterbi_i.cc b/gr-trellis/src/lib/trellis_viterbi_i.cc
new file mode 100644
index 000000000..b5ae79d1f
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_i.cc
@@ -0,0 +1,167 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_viterbi_i.h>
+#include <gr_io_signature.h>
+#include <assert.h>
+#include <iostream>
+
+static const float INF = 1.0e9;
+
+trellis_viterbi_i_sptr
+trellis_make_viterbi_i (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK)
+{
+ return trellis_viterbi_i_sptr (new trellis_viterbi_i (FSM,K,S0,SK));
+}
+
+trellis_viterbi_i::trellis_viterbi_i (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK)
+ : gr_block ("viterbi_i",
+ gr_make_io_signature (1, -1, sizeof (float)),
+ gr_make_io_signature (1, -1, sizeof (int))),
+ d_FSM (FSM),
+ d_K (K),
+ d_S0 (S0),
+ d_SK (SK),
+ d_trace(FSM.S()*K)
+{
+ set_relative_rate (1.0 / ((double) d_FSM.O()));
+ set_output_multiple (d_K);
+}
+
+
+void
+trellis_viterbi_i::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+ assert (noutput_items % d_K == 0);
+ int input_required = d_FSM.O() * noutput_items ;
+ unsigned ninputs = ninput_items_required.size();
+ for (unsigned int i = 0; i < ninputs; i++) {
+ ninput_items_required[i] = input_required;
+ }
+}
+
+
+
+
+void viterbi_algorithm(const int I, const int S, const int O,
+ const std::vector<int> &NS,
+ const std::vector<int> &OS,
+ const std::vector<int> &PS,
+ const std::vector<int> &PI,
+ const int K,
+ const int S0,const int SK,
+ const float *in, int *out,
+ std::vector<int> &trace)
+{
+ std::vector<float> alpha(S*2);
+ int alphai;
+ float norm,mm,minm;
+ int minmi;
+ int st;
+
+
+ if(S0<0) { // initial state not specified
+ for(int i=0;i<S;i++) alpha[0*S+i]=0;
+ }
+ else {
+ for(int i=0;i<S;i++) alpha[0*S+i]=INF;
+ alpha[0*S+S0]=0.0;
+ }
+
+ alphai=0;
+ for(int k=0;k<K;k++) {
+ norm=INF;
+ for(int j=0;j<S;j++) { // for each next state do ACS
+ minm=INF;
+ minmi=0;
+ for(int i=0;i<I;i++) {
+ int i0 = j*I+i;
+ if((mm=alpha[alphai*S+PS[i0]]+in[k*O+OS[PS[i0]*I+PI[i0]]])<minm)
+ minm=mm,minmi=i;
+ }
+ trace[k*S+j]=minmi;
+ alpha[((alphai+1)%2)*S+j]=minm;
+ if(minm<norm) norm=minm;
+ }
+ for(int j=0;j<S;j++)
+ alpha[((alphai+1)%2)*S+j]-=norm; // normalize total metrics so they do not explode
+ alphai=(alphai+1)%2;
+ }
+
+ if(SK<0) { // final state not specified
+ minm=INF;
+ minmi=0;
+ for(int i=0;i<S;i++)
+ if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i;
+ st=minmi;
+ }
+ else {
+ st=SK;
+ }
+
+ for(int k=K-1;k>=0;k--) { // traceback
+ int i0=st*I+trace[k*S+st];
+ out[k]= (int) PI[i0];
+ st=PS[i0];
+ }
+
+}
+
+
+
+
+
+
+int
+trellis_viterbi_i::general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+ assert (noutput_items % d_K == 0);
+ int nblocks = noutput_items / d_K;
+
+ for (int m=0;m<nstreams;m++) {
+ const float *in = (const float *) input_items[m];
+ int *out = (int *) output_items[m];
+ for (int n=0;n<nblocks;n++) {
+ viterbi_algorithm(d_FSM.I(),d_FSM.S(),d_FSM.O(),d_FSM.NS(),d_FSM.OS(),d_FSM.PS(),d_FSM.PI(),d_K,d_S0,d_SK,&(in[n*d_K*d_FSM.O()]),&(out[n*d_K]),d_trace);
+ }
+ }
+
+ consume_each (d_FSM.O() * noutput_items );
+ return noutput_items;
+}
diff --git a/gr-trellis/src/lib/trellis_viterbi_i.h b/gr-trellis/src/lib/trellis_viterbi_i.h
new file mode 100644
index 000000000..5da0a3866
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_i.h
@@ -0,0 +1,78 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+#ifndef INCLUDED_TRELLIS_VITERBI_I_H
+#define INCLUDED_TRELLIS_VITERBI_I_H
+
+#include "fsm.h"
+#include <gr_block.h>
+
+class trellis_viterbi_i;
+typedef boost::shared_ptr<trellis_viterbi_i> trellis_viterbi_i_sptr;
+
+trellis_viterbi_i_sptr trellis_make_viterbi_i (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+
+
+class trellis_viterbi_i : public gr_block
+{
+ fsm d_FSM;
+ int d_K;
+ int d_S0;
+ int d_SK;
+ std::vector<int> d_trace;
+
+ friend trellis_viterbi_i_sptr trellis_make_viterbi_i (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+
+ trellis_viterbi_i (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int K () const { return d_K; }
+ int S0 () const { return d_S0; }
+ int SK () const { return d_SK; }
+ //std::vector<int> trace () const { return d_trace; }
+ void forecast (int noutput_items,
+ gr_vector_int &ninput_items_required);
+ int general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_viterbi_i.i b/gr-trellis/src/lib/trellis_viterbi_i.i
new file mode 100644
index 000000000..de402e36d
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_i.i
@@ -0,0 +1,49 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,viterbi_i);
+
+trellis_viterbi_i_sptr trellis_make_viterbi_i (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+
+class trellis_viterbi_i : public gr_block
+{
+private:
+ trellis_viterbi_i (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int K () const { return d_K; }
+ int S0 () const { return d_S0; }
+ int SK () const { return d_SK; }
+ //std::vector<short> trace () const { return d_trace; }
+};
diff --git a/gr-trellis/src/lib/trellis_viterbi_s.cc b/gr-trellis/src/lib/trellis_viterbi_s.cc
new file mode 100644
index 000000000..6180dabc3
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_s.cc
@@ -0,0 +1,167 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <trellis_viterbi_s.h>
+#include <gr_io_signature.h>
+#include <assert.h>
+#include <iostream>
+
+static const float INF = 1.0e9;
+
+trellis_viterbi_s_sptr
+trellis_make_viterbi_s (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK)
+{
+ return trellis_viterbi_s_sptr (new trellis_viterbi_s (FSM,K,S0,SK));
+}
+
+trellis_viterbi_s::trellis_viterbi_s (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK)
+ : gr_block ("viterbi_s",
+ gr_make_io_signature (1, -1, sizeof (float)),
+ gr_make_io_signature (1, -1, sizeof (short))),
+ d_FSM (FSM),
+ d_K (K),
+ d_S0 (S0),
+ d_SK (SK),
+ d_trace(FSM.S()*K)
+{
+ set_relative_rate (1.0 / ((double) d_FSM.O()));
+ set_output_multiple (d_K);
+}
+
+
+void
+trellis_viterbi_s::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+ assert (noutput_items % d_K == 0);
+ int input_required = d_FSM.O() * noutput_items ;
+ unsigned ninputs = ninput_items_required.size();
+ for (unsigned int i = 0; i < ninputs; i++) {
+ ninput_items_required[i] = input_required;
+ }
+}
+
+
+
+
+void viterbi_algorithm(const int I, const int S, const int O,
+ const std::vector<int> &NS,
+ const std::vector<int> &OS,
+ const std::vector<int> &PS,
+ const std::vector<int> &PI,
+ const int K,
+ const int S0,const int SK,
+ const float *in, short *out,
+ std::vector<int> &trace)
+{
+ std::vector<float> alpha(S*2);
+ int alphai;
+ float norm,mm,minm;
+ int minmi;
+ int st;
+
+
+ if(S0<0) { // initial state not specified
+ for(int i=0;i<S;i++) alpha[0*S+i]=0;
+ }
+ else {
+ for(int i=0;i<S;i++) alpha[0*S+i]=INF;
+ alpha[0*S+S0]=0.0;
+ }
+
+ alphai=0;
+ for(int k=0;k<K;k++) {
+ norm=INF;
+ for(int j=0;j<S;j++) { // for each next state do ACS
+ minm=INF;
+ minmi=0;
+ for(int i=0;i<I;i++) {
+ int i0 = j*I+i;
+ if((mm=alpha[alphai*S+PS[i0]]+in[k*O+OS[PS[i0]*I+PI[i0]]])<minm)
+ minm=mm,minmi=i;
+ }
+ trace[k*S+j]=minmi;
+ alpha[((alphai+1)%2)*S+j]=minm;
+ if(minm<norm) norm=minm;
+ }
+ for(int j=0;j<S;j++)
+ alpha[((alphai+1)%2)*S+j]-=norm; // normalize total metrics so they do not explode
+ alphai=(alphai+1)%2;
+ }
+
+ if(SK<0) { // final state not specified
+ minm=INF;
+ minmi=0;
+ for(int i=0;i<S;i++)
+ if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i;
+ st=minmi;
+ }
+ else {
+ st=SK;
+ }
+
+ for(int k=K-1;k>=0;k--) { // traceback
+ int i0=st*I+trace[k*S+st];
+ out[k]= (short) PI[i0];
+ st=PS[i0];
+ }
+
+}
+
+
+
+
+
+
+int
+trellis_viterbi_s::general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ assert (input_items.size() == output_items.size());
+ int nstreams = input_items.size();
+ assert (noutput_items % d_K == 0);
+ int nblocks = noutput_items / d_K;
+
+ for (int m=0;m<nstreams;m++) {
+ const float *in = (const float *) input_items[m];
+ short *out = (short *) output_items[m];
+ for (int n=0;n<nblocks;n++) {
+ viterbi_algorithm(d_FSM.I(),d_FSM.S(),d_FSM.O(),d_FSM.NS(),d_FSM.OS(),d_FSM.PS(),d_FSM.PI(),d_K,d_S0,d_SK,&(in[n*d_K*d_FSM.O()]),&(out[n*d_K]),d_trace);
+ }
+ }
+
+ consume_each (d_FSM.O() * noutput_items );
+ return noutput_items;
+}
diff --git a/gr-trellis/src/lib/trellis_viterbi_s.h b/gr-trellis/src/lib/trellis_viterbi_s.h
new file mode 100644
index 000000000..2c3a61c9b
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_s.h
@@ -0,0 +1,78 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+#ifndef INCLUDED_TRELLIS_VITERBI_S_H
+#define INCLUDED_TRELLIS_VITERBI_S_H
+
+#include "fsm.h"
+#include <gr_block.h>
+
+class trellis_viterbi_s;
+typedef boost::shared_ptr<trellis_viterbi_s> trellis_viterbi_s_sptr;
+
+trellis_viterbi_s_sptr trellis_make_viterbi_s (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+
+
+class trellis_viterbi_s : public gr_block
+{
+ fsm d_FSM;
+ int d_K;
+ int d_S0;
+ int d_SK;
+ std::vector<int> d_trace;
+
+ friend trellis_viterbi_s_sptr trellis_make_viterbi_s (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+
+ trellis_viterbi_s (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int K () const { return d_K; }
+ int S0 () const { return d_S0; }
+ int SK () const { return d_SK; }
+ //std::vector<int> trace () const { return d_trace; }
+ void forecast (int noutput_items,
+ gr_vector_int &ninput_items_required);
+ int general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
diff --git a/gr-trellis/src/lib/trellis_viterbi_s.i b/gr-trellis/src/lib/trellis_viterbi_s.i
new file mode 100644
index 000000000..44e437265
--- /dev/null
+++ b/gr-trellis/src/lib/trellis_viterbi_s.i
@@ -0,0 +1,49 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+// WARNING: this file is machine generated. Edits will be over written
+
+GR_SWIG_BLOCK_MAGIC(trellis,viterbi_s);
+
+trellis_viterbi_s_sptr trellis_make_viterbi_s (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+
+class trellis_viterbi_s : public gr_block
+{
+private:
+ trellis_viterbi_s (
+ const fsm &FSM,
+ const int K,
+ const int S0,
+ const int SK);
+
+public:
+ fsm FSM () const { return d_FSM; }
+ int K () const { return d_K; }
+ int S0 () const { return d_S0; }
+ int SK () const { return d_SK; }
+ //std::vector<short> trace () const { return d_trace; }
+};
diff --git a/gr-trellis/src/python/Makefile.am b/gr-trellis/src/python/Makefile.am
new file mode 100644
index 000000000..5c7b8ccf1
--- /dev/null
+++ b/gr-trellis/src/python/Makefile.am
@@ -0,0 +1,32 @@
+#
+# Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+
+include $(top_srcdir)/Makefile.common
+
+EXTRA_DIST = run_tests.in
+
+
+TESTS = \
+ run_tests
+
+
+noinst_PYTHON = \
+ qa_trellis.py
diff --git a/gr-trellis/src/python/qa_trellis.py b/gr-trellis/src/python/qa_trellis.py
new file mode 100755
index 000000000..c47ee2881
--- /dev/null
+++ b/gr-trellis/src/python/qa_trellis.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+#
+# Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+
+from gnuradio import gr, gr_unittest
+import trellis
+
+class qa_trellis (gr_unittest.TestCase):
+
+ def setUp (self):
+ self.fg = gr.flow_graph ()
+
+ def tearDown (self):
+ self.fg = None
+
+if __name__ == '__main__':
+ gr_unittest.main ()
diff --git a/gr-trellis/src/python/run_tests.in b/gr-trellis/src/python/run_tests.in
new file mode 100644
index 000000000..103a9a260
--- /dev/null
+++ b/gr-trellis/src/python/run_tests.in
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+# All this strange PYTHONPATH manipulation is required to run our
+# tests using our just built shared library and swig-generated python
+# code prior to installation.
+
+# build tree == src tree unless you're doing a VPATH build.
+# If you don't know what a VPATH build is, you're not doing one. Relax...
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+
+# Where to look in the build tree for our shared library
+libbld=@abs_top_builddir@/gr-trellis/src/lib
+# Where to look in the src tree for swig generated python code
+libsrc=@abs_top_srcdir@/gr-trellis/src/lib
+# Where to look in the src tree for hand written python code
+py=@abs_top_srcdir@/gr-trellis/src/python
+
+# Where to look for GNU Radio python modules in current build tree
+grpythonbld=@abs_top_builddir@/gnuradio-core/src/python/:@abs_top_builddir@/gnuradio-core/src/lib/swig/:@abs_top_builddir@/gnuradio-core/src/lib/swig/.libs
+
+PYTHONPATH="$grpythonbld:$libbld:$libbld/.libs:$libsrc:$py:$PYTHONPATH"
+export PYTHONPATH
+
+#
+# This is the simple part...
+# Run everything that matches qa_*.py and return the final result.
+#
+
+ok=yes
+for file in @srcdir@/qa_*.py
+do
+ if ! $file
+ then
+ ok=no
+ fi
+done
+
+if [ $ok = yes ]
+then
+ exit 0
+else
+ exit 1
+fi