SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Classes | Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
leansdr::viterbi_dec< TS, NSTATES, TUS, NUS, TCS, NCS, TBM, TPM, TP > Struct Template Reference

#include <viterbi.h>

+ Inheritance diagram for leansdr::viterbi_dec< TS, NSTATES, TUS, NUS, TCS, NCS, TBM, TPM, TP >:
+ Collaboration diagram for leansdr::viterbi_dec< TS, NSTATES, TUS, NUS, TCS, NCS, TBM, TPM, TP >:

Classes

struct  state
 

Public Types

typedef state statebank[NSTATES]
 

Public Member Functions

 viterbi_dec (trellis< TS, NSTATES, TUS, NUS, NCS > *_trellis)
 
TUS update (TBM costs[NCS], TPM *quality=NULL)
 
TUS update (int nm, TCS cs[], TBM costs[], TPM *quality=NULL)
 
TUS update (TCS cs, TBM cost, TPM *quality=NULL)
 
void dump ()
 
- Public Member Functions inherited from leansdr::viterbi_dec_interface< TUS, TCS, TBM, TPM >
virtual TUS update (TBM *costs, TPM *quality=NULL)=0
 

Public Attributes

trellis< TS, NSTATES, TUS, NUS, NCS > * trell
 
state statebanks [2][NSTATES]
 
statebankstates
 
statebanknewstates
 

Private Attributes

TPM max_tpm
 

Detailed Description

template<typename TS, int NSTATES, typename TUS, int NUS, typename TCS, int NCS, typename TBM, typename TPM, typename TP>
struct leansdr::viterbi_dec< TS, NSTATES, TUS, NUS, TCS, NCS, TBM, TPM, TP >

Definition at line 136 of file viterbi.h.

Member Typedef Documentation

◆ statebank

template<typename TS , int NSTATES, typename TUS , int NUS, typename TCS , int NCS, typename TBM , typename TPM , typename TP >
typedef state leansdr::viterbi_dec< TS, NSTATES, TUS, NUS, TCS, NCS, TBM, TPM, TP >::statebank[NSTATES]

Definition at line 146 of file viterbi.h.

Constructor & Destructor Documentation

◆ viterbi_dec()

template<typename TS , int NSTATES, typename TUS , int NUS, typename TCS , int NCS, typename TBM , typename TPM , typename TP >
leansdr::viterbi_dec< TS, NSTATES, TUS, NUS, TCS, NCS, TBM, TPM, TP >::viterbi_dec ( trellis< TS, NSTATES, TUS, NUS, NCS > *  _trellis)
inline

Definition at line 150 of file viterbi.h.

References leansdr::viterbi_dec< TS, NSTATES, TUS, NUS, TCS, NCS, TBM, TPM, TP >::state::cost.

150  : trell(_trellis)
151  {
152  states = &statebanks[0];
153  newstates = &statebanks[1];
154  for (TS s = 0; s < NSTATES; ++s)
155  (*states)[s].cost = 0;
156  // Determine max value that can fit in TPM
157  max_tpm = (TPM)0 - 1;
158  if (max_tpm < 0)
159  {
160  // TPM is signed
161  for (max_tpm = 0; max_tpm * 2 + 1 > max_tpm; max_tpm = max_tpm * 2 + 1)
162  ;
163  }
164  }
state statebanks[2][NSTATES]
Definition: viterbi.h:147
statebank * newstates
Definition: viterbi.h:148
trellis< TS, NSTATES, TUS, NUS, NCS > * trell
Definition: viterbi.h:139
statebank * states
Definition: viterbi.h:148

Member Function Documentation

◆ dump()

template<typename TS , int NSTATES, typename TUS , int NUS, typename TCS , int NCS, typename TBM , typename TPM , typename TP >
void leansdr::viterbi_dec< TS, NSTATES, TUS, NUS, TCS, NCS, TBM, TPM, TP >::dump ( )
inline

Definition at line 315 of file viterbi.h.

316  {
317  fprintf(stderr, "[");
318  for (TS s = 0; s < NSTATES; ++s)
319  if (states[s].cost)
320  fprintf(stderr, " %02x:%d", s, states[s].cost);
321  fprintf(stderr, "\n");
322  }
statebank * states
Definition: viterbi.h:148

◆ update() [1/3]

template<typename TS , int NSTATES, typename TUS , int NUS, typename TCS , int NCS, typename TBM , typename TPM , typename TP >
TUS leansdr::viterbi_dec< TS, NSTATES, TUS, NUS, TCS, NCS, TBM, TPM, TP >::update ( TBM  costs[NCS],
TPM *  quality = NULL 
)
inline

Definition at line 168 of file viterbi.h.

References leansdr::trellis< TS, NSTATES, TUS, NUS, NCS >::state::branches, leansdr::trellis< TS, NSTATES, TUS, NUS, NCS >::NOSTATE, leansdr::trellis< TS, NSTATES, TUS, NUS, NCS >::state::branch::pred, leansdr::trellis< TS, NSTATES, TUS, NUS, NCS >::states, and leansdr::trellis< TS, NSTATES, TUS, NUS, NCS >::state::branch::us.

169  {
170  TPM best_tpm = max_tpm, best2_tpm = max_tpm;
171  TS best_state = 0;
172  // Update all states
173  for (int s = 0; s < NSTATES; ++s)
174  {
175  TPM best_m = max_tpm;
176  typename trellis<TS, NSTATES, TUS, NUS, NCS>::state::branch *best_b = NULL;
177  // Select best branch
178  for (int cs = 0; cs < NCS; ++cs)
179  {
180  typename trellis<TS, NSTATES, TUS, NUS, NCS>::state::branch *b =
181  &trell->states[s].branches[cs];
182  if (b->pred == trell->NOSTATE)
183  continue;
184  TPM m = (*states)[b->pred].cost + costs[cs];
185  if (m <= best_m)
186  { // <= guarantees one match
187  best_m = m;
188  best_b = b;
189  }
190  }
191  (*newstates)[s].path = (*states)[best_b->pred].path;
192  (*newstates)[s].path.append(best_b->us);
193  (*newstates)[s].cost = best_m;
194  // Select best and second-best states
195  if (best_m < best_tpm)
196  {
197  best_state = s;
198  best2_tpm = best_tpm;
199  best_tpm = best_m;
200  }
201  else if (best_m < best2_tpm)
202  best2_tpm = best_m;
203  }
204  // Swap banks
205  {
206  statebank *tmp = states;
207  states = newstates;
208  newstates = tmp;
209  }
210  // Prevent overflow of path metrics
211  for (TS s = 0; s < NSTATES; ++s)
212  (*states)[s].cost -= best_tpm;
213 #if 0
214  // Observe that the min-max range remains bounded
215  fprintf(stderr,"-%2d = [", best_tpm);
216  for ( TS s=0; s<NSTATES; ++s ) fprintf(stderr," %d", (*states)[s].cost);
217  fprintf(stderr," ]\n");
218 #endif
219  // Return difference between best and second-best as quality metric.
220  if (quality)
221  *quality = best2_tpm - best_tpm;
222  // Return uncoded symbol of best path
223  return (*states)[best_state].path.read();
224  }
state statebank[NSTATES]
Definition: viterbi.h:146
statebank * newstates
Definition: viterbi.h:148
trellis< TS, NSTATES, TUS, NUS, NCS > * trell
Definition: viterbi.h:139
statebank * states
Definition: viterbi.h:148

◆ update() [2/3]

template<typename TS , int NSTATES, typename TUS , int NUS, typename TCS , int NCS, typename TBM , typename TPM , typename TP >
TUS leansdr::viterbi_dec< TS, NSTATES, TUS, NUS, TCS, NCS, TBM, TPM, TP >::update ( int  nm,
TCS  cs[],
TBM  costs[],
TPM *  quality = NULL 
)
inline

Definition at line 230 of file viterbi.h.

References leansdr::trellis< TS, NSTATES, TUS, NUS, NCS >::state::branches, leansdr::trellis< TS, NSTATES, TUS, NUS, NCS >::NOSTATE, leansdr::trellis< TS, NSTATES, TUS, NUS, NCS >::state::branch::pred, leansdr::trellis< TS, NSTATES, TUS, NUS, NCS >::states, and leansdr::trellis< TS, NSTATES, TUS, NUS, NCS >::state::branch::us.

231  {
232  TPM best_tpm = max_tpm, best2_tpm = max_tpm;
233  TS best_state = 0;
234  // Update all states
235  for (int s = 0; s < NSTATES; ++s)
236  {
237  // Select best branch among those for with metrics are provided
238  TPM best_m = max_tpm;
239  typename trellis<TS, NSTATES, TUS, NUS, NCS>::state::branch *best_b = NULL;
240  for (int im = 0; im < nm; ++im)
241  {
242  typename trellis<TS, NSTATES, TUS, NUS, NCS>::state::branch *b =
243  &trell->states[s].branches[cs[im]];
244  if (b->pred == trell->NOSTATE)
245  continue;
246  TPM m = (*states)[b->pred].cost + costs[im];
247  if (m <= best_m)
248  { // <= guarantees one match
249  best_m = m;
250  best_b = b;
251  }
252  }
253  if (nm != NCS)
254  {
255  // Also scan the other branches.
256  // We actually rescan the branches with metrics.
257  // This works because costs are negative.
258  for (int cs = 0; cs < NCS; ++cs)
259  {
260  typename trellis<TS, NSTATES, TUS, NUS, NCS>::state::branch *b =
261  &trell->states[s].branches[cs];
262  if (b->pred == trell->NOSTATE)
263  continue;
264  TPM m = (*states)[b->pred].cost;
265  if (m <= best_m)
266  {
267  best_m = m;
268  best_b = b;
269  }
270  }
271  }
272  (*newstates)[s].path = (*states)[best_b->pred].path;
273  (*newstates)[s].path.append(best_b->us);
274  (*newstates)[s].cost = best_m;
275  // Select best states
276  if (best_m < best_tpm)
277  {
278  best_state = s;
279  best2_tpm = best_tpm;
280  best_tpm = best_m;
281  }
282  else if (best_m < best2_tpm)
283  best2_tpm = best_m;
284  }
285  // Swap banks
286  {
287  statebank *tmp = states;
288  states = newstates;
289  newstates = tmp;
290  }
291  // Prevent overflow of path metrics
292  for (TS s = 0; s < NSTATES; ++s)
293  (*states)[s].cost -= best_tpm;
294 #if 0
295  // Observe that the min-max range remains bounded
296  fprintf(stderr,"-%2d = [", best_tpm);
297  for ( TS s=0; s<NSTATES; ++s ) fprintf(stderr," %d", (*states)[s].cost);
298  fprintf(stderr," ]\n");
299 #endif
300  // Return difference between best and second-best as quality metric.
301  if (quality)
302  *quality = best2_tpm - best_tpm;
303  // Return uncoded symbol of best path
304  return (*states)[best_state].path.read();
305  }
state statebank[NSTATES]
Definition: viterbi.h:146
statebank * newstates
Definition: viterbi.h:148
trellis< TS, NSTATES, TUS, NUS, NCS > * trell
Definition: viterbi.h:139
statebank * states
Definition: viterbi.h:148

◆ update() [3/3]

template<typename TS , int NSTATES, typename TUS , int NUS, typename TCS , int NCS, typename TBM , typename TPM , typename TP >
TUS leansdr::viterbi_dec< TS, NSTATES, TUS, NUS, TCS, NCS, TBM, TPM, TP >::update ( TCS  cs,
TBM  cost,
TPM *  quality = NULL 
)
inlinevirtual

Implements leansdr::viterbi_dec_interface< TUS, TCS, TBM, TPM >.

Definition at line 310 of file viterbi.h.

311  {
312  return update(1, &cs, &cost, quality);
313  }
TUS update(TBM costs[NCS], TPM *quality=NULL)
Definition: viterbi.h:168

Member Data Documentation

◆ max_tpm

template<typename TS , int NSTATES, typename TUS , int NUS, typename TCS , int NCS, typename TBM , typename TPM , typename TP >
TPM leansdr::viterbi_dec< TS, NSTATES, TUS, NUS, TCS, NCS, TBM, TPM, TP >::max_tpm
private

Definition at line 325 of file viterbi.h.

◆ newstates

template<typename TS , int NSTATES, typename TUS , int NUS, typename TCS , int NCS, typename TBM , typename TPM , typename TP >
statebank * leansdr::viterbi_dec< TS, NSTATES, TUS, NUS, TCS, NCS, TBM, TPM, TP >::newstates

Definition at line 148 of file viterbi.h.

◆ statebanks

template<typename TS , int NSTATES, typename TUS , int NUS, typename TCS , int NCS, typename TBM , typename TPM , typename TP >
state leansdr::viterbi_dec< TS, NSTATES, TUS, NUS, TCS, NCS, TBM, TPM, TP >::statebanks[2][NSTATES]

Definition at line 147 of file viterbi.h.

◆ states

template<typename TS , int NSTATES, typename TUS , int NUS, typename TCS , int NCS, typename TBM , typename TPM , typename TP >
statebank* leansdr::viterbi_dec< TS, NSTATES, TUS, NUS, TCS, NCS, TBM, TPM, TP >::states

Definition at line 148 of file viterbi.h.

◆ trell

template<typename TS , int NSTATES, typename TUS , int NUS, typename TCS , int NCS, typename TBM , typename TPM , typename TP >
trellis<TS, NSTATES, TUS, NUS, NCS>* leansdr::viterbi_dec< TS, NSTATES, TUS, NUS, TCS, NCS, TBM, TPM, TP >::trell

Definition at line 139 of file viterbi.h.


The documentation for this struct was generated from the following file: