3
* Copyright 2004 Free Software Foundation, Inc.
5
* This file is part of GNU Radio
7
* GNU Radio is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 3, or (at your option)
12
* GNU Radio is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with GNU Radio; see the file COPYING. If not, write to
19
* the Free Software Foundation, Inc., 51 Franklin Street,
20
* Boston, MA 02110-1301, USA.
23
// WARNING: this file is machine generated. Edits will be over written
29
#include <trellis_viterbi_combined_cb.h>
30
#include <gr_io_signature.h>
34
static const float INF = 1.0e9;
36
trellis_viterbi_combined_cb_sptr
37
trellis_make_viterbi_combined_cb (
43
const std::vector<gr_complex> &TABLE,
44
trellis_metric_type_t TYPE)
46
return trellis_viterbi_combined_cb_sptr (new trellis_viterbi_combined_cb (FSM,K,S0,SK,D,TABLE,TYPE));
49
trellis_viterbi_combined_cb::trellis_viterbi_combined_cb (
55
const std::vector<gr_complex> &TABLE,
56
trellis_metric_type_t TYPE)
57
: gr_block ("viterbi_combined_cb",
58
gr_make_io_signature (1, -1, sizeof (gr_complex)),
59
gr_make_io_signature (1, -1, sizeof (unsigned char))),
69
set_relative_rate (1.0 / ((double) d_D));
70
set_output_multiple (d_K);
74
void trellis_viterbi_combined_cb::set_TABLE(const std::vector<gr_complex> &table)
80
trellis_viterbi_combined_cb::forecast (int noutput_items, gr_vector_int &ninput_items_required)
82
assert (noutput_items % d_K == 0);
83
int input_required = d_D * noutput_items ;
84
unsigned ninputs = ninput_items_required.size();
85
for (unsigned int i = 0; i < ninputs; i++) {
86
ninput_items_required[i] = input_required;
93
void viterbi_algorithm_combined(int I, int S, int O,
94
const std::vector<int> &NS,
95
const std::vector<int> &OS,
96
const std::vector< std::vector<int> > &PS,
97
const std::vector< std::vector<int> > &PI,
101
const std::vector<gr_complex> &TABLE,
102
trellis_metric_type_t TYPE,
103
const gr_complex *in, unsigned char *out)//,
104
//std::vector<int> &trace)
106
std::vector<int> trace(S*K);
107
std::vector<float> alpha(S*2);
108
float *metric = new float[O];
114
if(S0<0) { // initial state not specified
115
for(int i=0;i<S;i++) alpha[0*S+i]=0;
118
for(int i=0;i<S;i++) alpha[0*S+i]=INF;
123
for(int k=0;k<K;k++) {
124
calc_metric(O, D, TABLE, &(in[k*D]), metric,TYPE); // calc metrics
126
for(int j=0;j<S;j++) { // for each next state do ACS
129
for(unsigned int i=0;i<PS[j].size();i++) {
131
if((mm=alpha[alphai*S+PS[j][i]]+metric[OS[PS[j][i]*I+PI[j][i]]])<minm)
135
alpha[((alphai+1)%2)*S+j]=minm;
136
if(minm<norm) norm=minm;
139
alpha[((alphai+1)%2)*S+j]-=norm; // normalize total metrics so they do not explode
143
if(SK<0) { // final state not specified
147
if((mm=alpha[alphai*S+i])<minm) minm=mm,minmi=i;
154
for(int k=K-1;k>=0;k--) { // traceback
155
int i0=trace[k*S+st];
156
out[k]= (unsigned char) PI[st][i0];
170
trellis_viterbi_combined_cb::general_work (int noutput_items,
171
gr_vector_int &ninput_items,
172
gr_vector_const_void_star &input_items,
173
gr_vector_void_star &output_items)
175
assert (input_items.size() == output_items.size());
176
int nstreams = input_items.size();
177
assert (noutput_items % d_K == 0);
178
int nblocks = noutput_items / d_K;
180
for (int m=0;m<nstreams;m++) {
181
const gr_complex *in = (const gr_complex *) input_items[m];
182
unsigned char *out = (unsigned char *) output_items[m];
183
for (int n=0;n<nblocks;n++) {
184
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_K,d_S0,d_SK,d_D,d_TABLE,d_TYPE,&(in[n*d_K*d_D]),&(out[n*d_K]));//,d_trace);
188
consume_each (d_D * noutput_items );
189
return noutput_items;