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 2, 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., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
27
#include <trellis_viterbi_combined_s.h>
28
#include <gr_io_signature.h>
32
static const float INF = 1.0e9;
34
trellis_viterbi_combined_s_sptr
35
trellis_make_viterbi_combined_s (
38
const std::vector<float> &TABLE,
42
const trellis_metric_type_t TYPE)
44
return trellis_viterbi_combined_s_sptr (new trellis_viterbi_combined_s (FSM,D,TABLE,K,S0,SK,TYPE));
47
trellis_viterbi_combined_s::trellis_viterbi_combined_s (
50
const std::vector<float> &TABLE,
54
const trellis_metric_type_t TYPE)
55
: gr_block ("viterbi_combined_s",
56
gr_make_io_signature (1, -1, sizeof (float)),
57
gr_make_io_signature (1, -1, sizeof (short))),
67
set_relative_rate (1.0 / ((double) d_D));
68
set_output_multiple (d_K);
73
trellis_viterbi_combined_s::forecast (int noutput_items, gr_vector_int &ninput_items_required)
75
assert (noutput_items % d_K == 0);
76
int input_required = d_D * noutput_items ;
77
unsigned ninputs = ninput_items_required.size();
78
for (unsigned int i = 0; i < ninputs; i++) {
79
ninput_items_required[i] = input_required;
86
void viterbi_algorithm_combined(const int I, const int S, const int O,
87
const std::vector<int> &NS,
88
const std::vector<int> &OS,
89
const std::vector<int> &PS,
90
const std::vector<int> &PI,
92
const std::vector<float> &TABLE,
94
const int S0,const int SK,
95
const trellis_metric_type_t TYPE,
96
const float *in, short *out,
97
std::vector<int> &trace)
99
std::vector<float> alpha(S*2);
100
float *metric = new float[O];
106
if(S0<0) { // initial state not specified
107
for(int i=0;i<S;i++) alpha[0*S+i]=0;
110
for(int i=0;i<S;i++) alpha[0*S+i]=INF;
115
for(int k=0;k<K;k++) {
116
calc_metric_f(O, D, TABLE, &(in[k*D]), metric,TYPE); // calc metrics
118
for(int j=0;j<S;j++) { // for each next state do ACS
121
for(int i=0;i<I;i++) {
123
if((mm=alpha[alphai*S+PS[i0]]+metric[OS[PS[i0]*I+PI[i0]]])<minm)
127
alpha[((alphai+1)%2)*S+j]=minm;
128
if(minm<norm) norm=minm;
131
alpha[((alphai+1)%2)*S+j]-=norm; // normalize total metrics so they do not explode
135
if(SK<0) { // final state not specified
139
if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i;
146
for(int k=K-1;k>=0;k--) { // traceback
147
int i0=st*I+trace[k*S+st];
148
out[k]= (short) PI[i0];
162
trellis_viterbi_combined_s::general_work (int noutput_items,
163
gr_vector_int &ninput_items,
164
gr_vector_const_void_star &input_items,
165
gr_vector_void_star &output_items)
167
assert (input_items.size() == output_items.size());
168
int nstreams = input_items.size();
169
assert (noutput_items % d_K == 0);
170
int nblocks = noutput_items / d_K;
172
for (int m=0;m<nstreams;m++) {
173
const float *in = (const float *) input_items[m];
174
short *out = (short *) output_items[m];
175
for (int n=0;n<nblocks;n++) {
176
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);
180
consume_each (d_D * noutput_items );
181
return noutput_items;