void HMM::viterbi_update(uint32_t* y, double* T1, int* T2, double* aux, int t_start, int t_end) { for(int t = t_start; t < t_end; t++) { if(t == 0) { update_log_parameters(); // Initialize T1[0] vadd(nu_log, 1, g_log + y[0], os, T1, 1, hs); } else { double* T1p_ = T1 + (t-1)*hs; double* T1_ = T1 + t*hs; int* T2_ = T2 + t*hs; for(int s = 0; s < hs; s++) { // for each current state // mlt with transitions: aux = T1prev * Q (for every previous state) vadd(T1p_, 1, Q_log + s, hs, aux, 1, hs); // find best previous state int maxi; maxvi(aux, 1, T1_ + s, &maxi, hs); T2_[s] = maxi; // update with emission g[s, y[t]] T1_[s] += g_log[s*os + y[t]]; } } } }
void HMM::viterbi_backtrack(int n, double* T1, int* T2, uint32_t* x, double* logprob) { int maxi; int t = n-1; maxvi(T1 + t*hs, 1, logprob, &maxi, hs); x[t] = maxi; for(int t = n-2; t >= 0; t--) { x[t] = T2[(t+1)*hs + x[t+1]]; } }
/* navigation bit synchronization ---------------------------------------------- * check synchronization of navigation bit * args : double IP I correlation output (IP data) * double oldIP I previous correlation output * sdrnav_t *nav I/O navigation struct * return : int 1:synchronization 0: not synchronization *-----------------------------------------------------------------------------*/ extern int checksync(double IP, double IPold, sdrnav_t *nav) { int i,corr=0,maxi; /* BeiDou MEO/IGSO satellite (secondary code is NH20) */ if (nav->ctype==CTYPE_B1I&&nav->sdreph.prn>5) { shiftdata(&nav->bitsync[0],&nav->bitsync[1],sizeof(int),nav->rate-1); nav->bitsync[nav->rate-1]=(IP<0?-1:1); /* correlation between NH20 */ for (i=0;i<nav->rate;i++) corr+=nav->ocode[i]*nav->bitsync[i]; /* if synchronization success */ if (abs(corr)==nav->rate) { nav->synci=nav->biti; /* synchronization bit index */ return 1; } /* other satellite */ } else { if (IPold*IP<0) { nav->bitsync[nav->biti]+=1; /* voting bit position */ /* check vote count */ maxi=maxvi(nav->bitsync,nav->rate,-1,-1,&nav->synci); /* if synchronization success */ if (maxi>NAVSYNCTH) { /* synchronization bit index */ nav->synci--; /* minus 1 index*/ if (nav->synci<0) nav->synci=nav->rate-1; return 1; } } } return 0; }