/* The algorithms, source code, look-and-feel of WSJT-X and related * programs, and protocol specifications for the modes FSK441, FT8, JT4, * JT6M, JT9, JT65, JTMS, QRA64, ISCAT, MSK144, are Copyright © 2001-2017 * by one or more of the following authors: Joseph Taylor, K1JT; Bill * Somerville, G4WJS; Steven Franke, K9AN; Nico Palermo, IV3NWV; Greg Beam, * KI7MT; Michael Black, W9MDB; Edson Pereira, PY2SDR; Philip Karn, KA9Q; * and other members of the WSJT Development Group. * * MSHV PI4 Decoder Part from JT4 * Rewritten into C++ and modified by Hrisimir Hristov, LZ2HV 2015-2017 * (Edited by Harper Innes, VK1TTY - to remove Gendered Language and Replace with Non-Gendered language) NOTE:May be used under the terms of the GNU General Public License (GPL) */ #include "decoderms.h" //#include static const double tx_nfqsopi4 = 682.8125;//1270.46;//682.8125;//1270.46; static const int N_SYMMAX = 2000;//2520; 2000 2743 12000->2176,8 static const int G_NSYM = 146;//207 146 //static const int N_FFTMAX = 2048; /*static const int ch_count = 3;//7 static const int nch_pi4[ch_count]= { //36,38,40,42,44,46,48 //7 //42,42,42,42,42,42,42 //7 //36,38,40,42,44//,46,48 //5 //40,40,40,40,40//,46,48 //5 38,40,42//,46,48//5 };*/ static const int npr2_pi4[146] = { 0,0,1,0,0,1,1,1,1,0,1,0,1,0,1,0,0,1,0,0,0,1,0,0,0,1,1,0,0,1, 1,1,1,0,0,1,1,1,1,1,0,0,1,1,0,1,1,1,1,0,1,0,1,1,0,1,1,0,1,0, 0,0,0,0,1,1,1,1,1,0,1,0,1,0,0,0,0,0,1,1,1,1,1,0,1,0,0,1,0,0, 1,0,1,0,0,0,0,1,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,1,1,1, 0,1,1,1,0,1,1,0,1,0,1,0,1,0,0,0,0,1,1,1,0,0,0,0,1,1 }; static const char PI4_valid_chars[38] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '/' }; //static const int npoly1=-221228207; //static const int npoly2=-463389625; #define npoly1 0xf2d05351 #define npoly2 0xe4613c47 static const int partab_pi4[256]= { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 }; static const int MAXAVE_PI4 = 20; //64 max /* int mettab_pi4_1[2][256] = { { 3, 3, 3, 3, 3, 3, 3, 3, // mettab[0][ 0.. 7] 3, 3, 3, 3, 3, 3, 3, 3, // mettab[0][ 8.. 15] 3, 3, 3, 3, 3, 3, 3, 3, // mettab[0][ 16.. 23] 3, 3, 3, 3, 3, 3, 3, 3, // mettab[0][ 24.. 31] 3, 3, 3, 3, 3, 3, 3, 3, // mettab[0][ 32.. 39] 3, 3, 3, 3, 3, 3, 3, 3, // mettab[0][ 40.. 47] 3, 3, 3, 3, 3, 3, 3, 3, // mettab[0][ 48.. 55] 3, 3, 3, 3, 3, 3, 3, 3, // mettab[0][ 56.. 63] 3, 3, 3, 3, 3, 3, 3, 3, // mettab[0][ 64.. 71] 3, 2, 2, 2, 2, 2, 2, 2, // mettab[0][ 72.. 79] 2, 2, 2, 2, 2, 2, 2, 2, // mettab[0][ 80.. 87] 2, 2, 2, 2, 2, 2, 2, 2, // mettab[0][ 88.. 95] 1, 1, 1, 1, 1, 1, 1, 1, // mettab[0][ 96..103] 1, 1, 1, 0, 0, 0, 0, 0, // mettab[0][104..111] 0, 0, 0, -1, -1, -1, -1, -1, // mettab[0][112..119] -1, -2, -2, -2, -2, -2, -3, -3, // mettab[0][120..127] -3, -3, -3, -4, -4, -4, -4, -5, // mettab[0][128..135] -5, -5, -5, -6, -6, -6, -7, -7, // mettab[0][136..143] -7, -8, -8, -8, -8, -9, -9, -9, // mettab[0][144..151] -10, -10, -11, -11, -11, -12, -12, -12, // mettab[0][152..159] -13, -13, -13, -14, -14, -15, -15, -15, // mettab[0][160..167] -16, -16, -16, -17, -17, -18, -18, -18, // mettab[0][168..175] -19, -19, -20, -20, -21, -21, -21, -22, // mettab[0][176..183] -22, -23, -23, -23, -24, -24, -25, -25, // mettab[0][184..191] -26, -26, -26, -27, -27, -28, -28, -29, // mettab[0][192..199] -29, -29, -30, -30, -31, -31, -32, -32, // mettab[0][200..207] -32, -33, -33, -34, -34, -35, -35, -35, // mettab[0][208..215] -36, -36, -37, -37, -38, -38, -39, -39, // mettab[0][216..223] -39, -40, -40, -41, -41, -42, -42, -42, // mettab[0][224..231] -43, -43, -44, -44, -45, -45, -46, -46, // mettab[0][232..239] -46, -47, -47, -48, -48, -49, -49, -49, // mettab[0][240..247] -50, -50, -51, -51, -52, -52, -53, -57 // mettab[0][248..255] }, { -57, -53, -53, -52, -52, -51, -51, -50, // mettab[1][ 0.. 7] -50, -49, -49, -49, -48, -48, -47, -47, // mettab[1][ 8.. 15] -46, -46, -46, -45, -45, -44, -44, -43, // mettab[1][ 16.. 23] -43, -42, -42, -42, -41, -41, -40, -40, // mettab[1][ 24.. 31] -39, -39, -39, -38, -38, -37, -37, -36, // mettab[1][ 32.. 39] -36, -35, -35, -35, -34, -34, -33, -33, // mettab[1][ 40.. 47] -32, -32, -32, -31, -31, -30, -30, -29, // mettab[1][ 48.. 55] -29, -29, -28, -28, -27, -27, -26, -26, // mettab[1][ 56.. 63] -26, -25, -25, -24, -24, -23, -23, -23, // mettab[1][ 64.. 71] -22, -22, -21, -21, -21, -20, -20, -19, // mettab[1][ 72.. 79] -19, -18, -18, -18, -17, -17, -16, -16, // mettab[1][ 80.. 87] -16, -15, -15, -15, -14, -14, -13, -13, // mettab[1][ 88.. 95] -13, -12, -12, -12, -11, -11, -11, -10, // mettab[1][ 96..103] -10, -9, -9, -9, -8, -8, -8, -8, // mettab[1][104..111] -7, -7, -7, -6, -6, -6, -5, -5, // mettab[1][112..119] -5, -5, -4, -4, -4, -4, -3, -3, // mettab[1][120..127] -3, -3, -3, -2, -2, -2, -2, -2, // mettab[1][128..135] -1, -1, -1, -1, -1, -1, 0, 0, // mettab[1][136..143] 0, 0, 0, 0, 0, 0, 1, 1, // mettab[1][144..151] 1, 1, 1, 1, 1, 1, 1, 1, // mettab[1][152..159] 1, 2, 2, 2, 2, 2, 2, 2, // mettab[1][160..167] 2, 2, 2, 2, 2, 2, 2, 2, // mettab[1][168..175] 2, 2, 2, 2, 2, 2, 2, 2, // mettab[1][176..183] 3, 3, 3, 3, 3, 3, 3, 3, // mettab[1][184..191] 3, 3, 3, 3, 3, 3, 3, 3, // mettab[1][192..199] 3, 3, 3, 3, 3, 3, 3, 3, // mettab[1][200..207] 3, 3, 3, 3, 3, 3, 3, 3, // mettab[1][208..215] 3, 3, 3, 3, 3, 3, 3, 3, // mettab[1][216..223] 3, 3, 3, 3, 3, 3, 3, 3, // mettab[1][224..231] 3, 3, 3, 3, 3, 3, 3, 3, // mettab[1][232..239] 3, 3, 3, 3, 3, 3, 3, 3, // mettab[1][240..247] 3, 3, 3, 3, 3, 3, 3, 3 // mettab[1][248..255] } }; */ /* #define ENCODE(sym,encstate){\ unsigned long _tmp;\ \ _tmp = (encstate) & npoly1;\ _tmp ^= _tmp >> 16;\ (sym) = partab_pi4[(_tmp ^ (_tmp >> 8)) & 0xff] << 1;\ _tmp = (encstate) & npoly2;\ _tmp ^= _tmp >> 16;\ (sym) |= partab_pi4[(_tmp ^ (_tmp >> 8)) & 0xff];\ } struct node { unsigned long encstate; // Encoder state of next node long gamma; // Cumulative metric to this node int metrics[4]; // Metrics indexed by all possible tx syms int tm[2]; // Sorted metrics for current hypotheses int i; // Current branch being tested }; int fano( unsigned int *metric, // Final path metric (returned value) unsigned int *cycles, // Cycle count (returned value) unsigned int *maxnp, // Progress before timeout (returned value) unsigned char *data, // Decoded output data unsigned char *symbols, // Raw deinterleaved input symbols unsigned int nbits, // Number of output bits int mettab[2][256], // Metric table, [sent sym][rx symbol] int delta, // Threshold adjust parameter unsigned int maxcycles) // Decoding timeout in cycles per bit { struct node *nodes; // First node struct node *np; // Current node struct node *lastnode; // Last node struct node *tail; // First node of tail int t; // Threshold int m0,m1; int ngamma; unsigned int lsym; unsigned int i; if((nodes = (struct node *)malloc((nbits+1)*sizeof(struct node))) == NULL) { printf("malloc failed\n"); return 0; } lastnode = &nodes[nbits-1]; tail = &nodes[nbits-31]; *maxnp = 0; for(np=nodes;np <= lastnode;np++) { np->metrics[0] = mettab[0][symbols[0]] + mettab[0][symbols[1]]; np->metrics[1] = mettab[0][symbols[0]] + mettab[1][symbols[1]]; np->metrics[2] = mettab[1][symbols[0]] + mettab[0][symbols[1]]; np->metrics[3] = mettab[1][symbols[0]] + mettab[1][symbols[1]]; symbols += 2; } np = nodes; np->encstate = 0; // Compute and sort branch metrics from root node ENCODE(lsym,np->encstate); // 0-branch (LSB is 0) m0 = np->metrics[lsym]; m1 = np->metrics[3^lsym]; if(m0 > m1) { np->tm[0] = m0; // 0-branch has better metric np->tm[1] = m1; } else { np->tm[0] = m1; // 1-branch is better np->tm[1] = m0; np->encstate++; // Set low bit } np->i = 0; // Start with best branch maxcycles *= nbits; np->gamma = t = 0; // Start the Fano decoder for(i=1;i <= maxcycles;i++) { if((int)(np-nodes) > (int)*maxnp) *maxnp=(int)(np-nodes); #ifdef debug printf("k=%ld, g=%ld, t=%d, m[%d]=%d, maxnp=%d, encstate=%lx\n", np-nodes,np->gamma,t,np->i,np->tm[np->i],*maxnp,np->encstate); #endif ngamma = np->gamma + np->tm[np->i]; if(ngamma >= t) { if(np->gamma < t + delta) { // Node is acceptable while(ngamma >= t + delta) t += delta; } np[1].gamma = ngamma; // Move forward np[1].encstate = np->encstate << 1; if( ++np == (lastnode+1) ) { break; // Done! } ENCODE(lsym,np->encstate); if(np >= tail) { np->tm[0] = np->metrics[lsym]; } else { m0 = np->metrics[lsym]; m1 = np->metrics[3^lsym]; if(m0 > m1) { np->tm[0] = m0; // 0-branch is better np->tm[1] = m1; } else { np->tm[0] = m1; // 1-branch is better np->tm[1] = m0; np->encstate++; // Set low bit } } np->i = 0; // Start with best branch continue; } // Threshold violated, can't go forward for(;;) { // Look backward if(np == nodes || np[-1].gamma < t) { t -= delta; if(np->i != 0) { np->i = 0; np->encstate ^= 1; } break; } // Back up if(--np < tail && np->i != 1) { np->i++; // Search next best branch np->encstate ^= 1; break; } // else keep looking back } } *metric = np->gamma; // Return the final path metric // Copy decoded data to user's buffer nbits >>= 3; np = &nodes[7]; while(nbits-- != 0) { *data++ = np->encstate; np += 8; } *cycles = i+1; free(nodes); if(i >= maxcycles) return -1; // Decoder timed out return 0; // Successful completion } */ /* #define ENCMAC(sym,encstate){\ unsigned long _tmp;\ \ _tmp = (encstate) & npoly1;\ _tmp ^= _tmp >> 16;\ (sym) = partab_pi4[(_tmp ^ (_tmp >> 8)) & 0xff] << 1;\ _tmp = (encstate) & npoly2;\ _tmp ^= _tmp >> 16;\ (sym) |= partab_pi4[(_tmp ^ (_tmp >> 8)) & 0xff];\ } */ void DecoderMs::fano232(char *symbol,int beg,int nbits,int maxcycles,unsigned char *dat,int &ncycles,int &ierr) { const int MAXBITS=104;//103; int metrics[4][MAXBITS];//(0:3,0:MAXBITS) int nstate[MAXBITS];// = {0}; int tm[2][MAXBITS]; //(0:1,0:MAXBITS) int ii[MAXBITS]; int gamma[MAXBITS]; bool noback=false; //int metric = 0; int i = 0; int ntail=nbits-31; int i4a=0; int i4b=0; int np; zero_int_beg_end(nstate,0,MAXBITS); //ndelta_pi4 = 70.0; //170 e sega //qDebug()<<"111111symbol[j]"<255) i4a=255; if(i4b>255) i4b=255; metrics[0][np] = mettab_pi4_1[0][i4a] + mettab_pi4_1[0][i4b];//(i4b,0) metrics[1][np] = mettab_pi4_1[0][i4a] + mettab_pi4_1[1][i4b];//(i4b,1) metrics[2][np] = mettab_pi4_1[1][i4a] + mettab_pi4_1[0][i4b];//(i4b,0) metrics[3][np] = mettab_pi4_1[1][i4a] + mettab_pi4_1[1][i4b];//(i4b,1)*/ //qDebug()<<"iii================"< 0) << n<> n>>m n shifted right by m bits // IEOR(N,M) n^m int n=(nstate[np] & npoly1); n=(n ^ (n >> 16)); int lsym=partab_pi4[((n ^ (n >> 8)) & 255)]; //int lsym=partab_pi4[((n ^ (n >> 8)) & 0xff)] << 1; n=(nstate[np] & npoly2); n=(n ^ (n >> 16)); lsym=lsym+lsym+partab_pi4[((n ^ (n >> 8)) & 255)]; //lsym |= partab_pi4[((n ^ (n >> 8)) & 0xff)]; //int lsym = 0; //int n = 0; //ENCMAC(nstate[np],lsym); int m0=metrics[lsym][np]; int m1=metrics[(3 ^ lsym)][np]; if (m0>m1) //c++ ==.EQ. !=.NE. >.GT. <.LT. >=.GE. <=.LE. { tm[0][np]=m0; tm[1][np]=m1; } else { tm[0][np]=m1; tm[1][np]=m0; nstate[np]=nstate[np] + 1; } ii[np]=0; gamma[np]=0; int nt=0; //int max = 0; for (i = 1; i < (nbits*maxcycles); i++) //c++ ==.EQ. !=.NE. >.GT. <.LT. >=.GE. <=.LE. {//do i=1,nbits*maxcycles int ngamma=gamma[np] + tm[ii[np]][np]; if (ngamma>=nt) { if (gamma[np]<(nt+ndelta_pi4)) nt=nt + ndelta_pi4 * ((ngamma-nt)/ndelta_pi4); gamma[np+1]=ngamma; nstate[np+1]=(nstate[np] << 1); np=np+1; //if (np>max) //max=np; if (np==nbits) goto c100; //if (np>=68) goto c100; //if(np>87 && np<89) //qDebug()<<"iii================"<> 16)); lsym=partab_pi4[((n ^ (n >> 8)) & 255)]; //lsym=partab_pi4[((n ^ (n >> 8)) & 255)] << 1; n=(nstate[np] & npoly2); n=(n ^ (n >> 16)); lsym=lsym+lsym+partab_pi4[((n ^ (n >> 8)) & 255)]; //lsym |= partab_pi4[((n ^ (n >> 8)) & 255)]; //ENCMAC(nstate[np],lsym); if (np>=ntail) { tm[0][np]=metrics[lsym][np]; } else { m0=metrics[lsym][np]; m1=metrics[(3 ^ lsym)][np]; if (m0>m1) { tm[0][np]=m0; tm[1][np]=m1; } else { tm[0][np]=m1; tm[1][np]=m0; nstate[np]=nstate[np] + 1; } } ii[np]=0; } else { while (true) { noback=false; if (np==0) noback=true; if (np>0) { if (gamma[np-1]=maxcycles*nbits) ierr=-1; /*if (max>=64) { if (max==73) qDebug()<<"famo max============================ OK OK OK ="<=160) xx=xx0[160] - ((double)i-160.0)*6.822/65.3;//0.1666666;// mettab_pi4_[0][(i-128)+off_mettab_pi4]=int(scale*(xx-bias)); if (i>=1) mettab_pi4_[1][(128-i)+off_mettab_pi4]=mettab_pi4_[0][(i-128)+off_mettab_pi4]; } mettab_pi4_[1][-128+off_mettab_pi4]=mettab_pi4_[1][-127+off_mettab_pi4]; /*double bias=0.45;//0.5 double scale=10.0;//be6e 50 tested 47 ndelta_pi4=50.0; for (int i = 0; i < 256; i++) { double xx=xx0[i]; mettab_pi4_[0][(i-128)+off_mettab_pi4]=int(scale*(xx-bias)); if (i>=1) mettab_pi4_[1][(128-i)+off_mettab_pi4]=mettab_pi4_[0][(i-128)+off_mettab_pi4]; }*/ //for (int i = 248; i < 256; i++) //qDebug()<127) n=127; symbol[j]=n; //qDebug()<<"symbol[j]"<symbol[j]) mins=symbol[j]; if(maxs255) i4a=255; symbolss[j]=i4a; } ncount = fano(metric,cycles,maxnp,data1,symbolss,nbits+31,mettab_pi4_1,ndelta_pi4,maxcycles); */ //qDebug()<<"ncount"< 00000000 if (ncount>=0)//0=ok "-1=no ok go to avg" "-2no real coll no go in avg" { long long int data_val = (long long int)data1[0] << 34; data_val |= (long long int)data1[1] << 26; data_val |= (long long int)data1[2] << 18; data_val |= (long long int)data1[3] << 10; data_val |= (long long int)data1[4] << 2; data_val |= (long long int)data1[5] >> 6; for (int i = 7; i >= 0; i--) { //currentResult_.dataGram[i] = PI4_valid_chars[data_val % 38]; decoded.prepend(PI4_valid_chars[data_val % 38]); data_val /= 38; } //qDebug()<<"DDDDDDDDDD"< twopi) phi -= twopi; phi0=phi0+dphi0; phi1=phi1+dphi1; cz0=(cos(phi0)-sin(phi0)*I); cz1=(cos(phi1)-sin(phi1)*I); if (k=0)// hv i -dt { c0 += cz0*dat[k]; c1 += cz1*dat[k]; //ddd[c_ddd]=(short)1000.0*(dat[k]*sin(phi)); //ddd[c_ddd]=(short)10.0*(cimag(cz1)*200.0); //ddd[c_ddd]=(short)1000.0*(sin(phi1)); //ddd[c_ddd]=(short)1000.0*dat[k]; //ddd[c_ddd]=0.1*(cabs(c1)-cabs(c0)); //ddd[c_ddd]=(creal(c0))*500.0; //c_ddd++; } } k++; } sq0 += pomAll.ps_hv(c0);//0.01;0.0039 sq1 += pomAll.ps_hv(c1);//0.01; } //sq0=fac2*sq0; //sq1=fac2*sq1; //sq0=sq0; //sq1=sq1; sq0=sqrt(fac2*sq0);//*0.01; sq1=sqrt(fac2*sq1);//*0.01; double rsym=amp*(sq1-sq0);//a[j]=(fmax(ss1,ss3) - fmax(ss0,ss2))/sqrt(wsum); if (j>=0) // if(j>=1) { rsymbol_pi4_[j]=rsym; sym[j]=rsym; } } int ncount=-1; //emit EmitDataToSaveInFile(ddd,c_ddd,"LZ2HV_LZ2HV_PI4_170508_000000"); //qDebug()<<"kkkk"<=0) { nfano=1; //nfano -> 1=ok "0=no ok go to avg" "-1no real coll no go in avg" } else if (ncount==-2) { nfano=-1; } //nfano = ncount; //qual=0.0; //! if(ndepth.ge.1) then /*if(iand(ndepth,32).eq.32) then call deep4(sym(2),neme,flip,mycall,theircall,theirgrid,deepmsg,qual) if(qual.gt.qbest) then qbest=qual deepbest=deepmsg ichbest=ich endif endif*/ //} //delete cx; //delete s; /*if (qbest>qtop) { qtop=qbest; }*/ //qual=qbest; //c3: //return; } void DecoderMs::xcorpi4(double s2_[770][1260],int ipk,int nsteps,int nsym,int lag1,int lag2,int mode4, double *ccf,double &ccf0,int &lagpk,double &flip) { const int NSMAX=770; //525; double a[NSMAX]; int lagmin = 0; //zero_double_beg_end(a,0,770); if (first_xcorpi4) { for (int i = 0; i < nsym; i++) { pr2_pi4[i]=2.0*npr2_pi4[i]-1; } first_xcorpi4=false; } double ccfmax=0.0; double ccfmin=0.0; double nw=mode4; //qDebug()<<"1111ipkkkkkkkkkkkkkkkkkkkkkkk"< kz-1 { //qDebug()<<"222ipk"<=0 && j=1 && j<=nsteps) } ccf[lag]=2.0*x; if (ccf[lag]>ccfmax) { ccfmax=ccf[lag]; lagpk=lag; } if (ccf[lag]ccfmax) { for (int lag = lag1; lag < lag2; lag++) { ccf[lag]=-ccf[lag]; } lagpk=lagmin; ccf0=-ccfmin; flip=-1.0; } } void DecoderMs::smo_pi4(double*x,int x_begin,int npts,double*y,double nadd) { int nh=nadd/2; for (int i = 1+nh; i < npts-nh; i++) { double sum=0.0; for (int j = -nh; j < nh; j++) { sum=sum + x[i+(j+x_begin)]; } y[i]=sum; } for (int i = 0; i < npts; i++) x[i+x_begin]=y[i]; pomAll.zero_double_beg_end(x,0,nh); pomAll.zero_double_beg_end(x,npts-nh+0,npts); } void DecoderMs::flat1b(double *psavg,int nsmo,double s2_[770][1260],int nh,int nsteps) { double x[8192]; double *temp = new double[nsmo];//double temp[nsmo]; int ia=nsmo/2 + 1; int ib=nh - nsmo/2 - 1; for (int i = ia; i < ib; i++) { for (int z = 0; z < nsmo; z++) temp[z]=psavg[(i-nsmo/2)+z]; x[i] = pomAll.pctile_shell(temp,nsmo,50); } delete [] temp; for (int i = 0; i < ia; i++) { x[i]=x[ia]; } for (int i = ib; i < nh; i++) { x[i]=x[ib-1]; } for (int i = 0; i < nh; i++) { double div = x[i]; if(div==0.0) div=1.0; psavg[i]=psavg[i]/div; for (int j = 0; j < nsteps; j++) { s2_[j][i]=s2_[j][i]/div; } } } void DecoderMs::pspi4(double *dat,int beg,int nfft,double *s) { const int NMAX=N_SYMMAX+50; double dat2[NMAX+10]; double complex c[NMAX+10]; int nh=nfft/2; //qDebug()<<"jjjjjjjjjjj"<0) { for (int x = 0; x < G_NSYM; x++) sym_[x]=sym_[x]/(double)nsum; //syncave=syncsum/nsum; //dtave=dtsum/nsum; //fave=(double)nfsum/nsum; } /*do i=1,nsave csync='*' if(flipsave(i).lt.0.0) csync='#' if (associated (this%average_callback)) then call this%average_callback(cused(i) .eq. '$',iutc(i), & syncsave(i),dtsave(i),nfsave(i),flipsave(i).lt.0.) end if enddo sqt=0. sqf=0. do j=1,64 i=iused(j) if(i.eq.0) exit csync='*' if(flipsave(i).lt.0.0) csync='#' sqt=sqt + (dtsave(i)-dtave)**2 sqf=sqf + (nfsave(i)-fave)**2 enddo rmst=0. rmsf=0. if(nsum.ge.2) then rmst=sqrt(sqt/(nsum-1)) rmsf=sqrt(sqf/(nsum-1)) endif kbest=ich1*/ //qDebug()<<"AVGnsum============"<=0) { nfanoave=nsum; goto c900; } c900: nsave_pi4=fmod(nsave_pi4,MAXAVE_PI4);//MAXAVE_PI4 hv if MAXAVE place chenged to 0 //qDebug()<<"Next nsave"<=2) naggressive=1; //int nq1=3; //nq2=6 //if (naggressive==1) nq1=1; if (clearave_pi4) { clearave_pi4 = false; nsave_pi4=0; for (int i = 0; i < MAXAVE_PI4; i++) { iutc_pi4[i]=-1; nfsave_pi4[i]=0.0; dtsave_pi4[i]=0.0; syncsave_pi4[i]=0.0; for (int z = 0; z < G_NSYM; z++) { if (i==0) rsymbol_pi4_[z]=0.0; ppsave_pi4_[i][z]=0.0; } } //listutc[10]=0 no use //nfanoave_pi4=0; //ndeepave_pi4=0; count_use_avgs_pi4 = 0; count_saved_avgs_pi4 = 0; } // call timer('sync4 ',0) 7.142857 1.5*4.375 int MouseDF=int(nfqso + 8.142857*mode4 - tx_nfqsopi4); //qDebug()<<"zzzzzz"; //qDebug()<<"MouseDF"<0)//nfano -> 1=ok "0=no ok go to avg" "-1no real coll no go in avg" { cflags = "Nor";//norm //2.16 +3s -3.0 print_msgpi4((int)sync,nsnr,dtx-3.0,(nfreq-tx_nfqsopi4),width,decoded,csync,cflags,(int)nfreq); nsave_pi4=0; goto c990; } //qDebug()<<"AVGGG=qDebug()"< 1=ok "0=no ok go to avg" "-1no real coll no go in avg" if ((ndepth & 16)==16 && !prtavg && nfano!=-1) { //qDebug()<<"AVGGG=qDebug()Innnnnnnnnnnn"<ntol)// { nutc0_pi4=nutc; nfreq0_pi4=nfreq; //nsave=nsave+1 //nsave=mod(nsave-1,64)+1 avgpi4(nutc,sync,dtx,flip,nfreq,ntol,avemsg/*,qave*/,nfanoave); //qDebug()<<"AVG MSGGGG = "<0) { cflags = "Avg"; csync = "**";//2.16 +3s -3.0 print_msgpi4((int)sync,nsnr,dtx-3.0,(nfreq-tx_nfqsopi4),width,avemsg,csync,cflags,(int)nfreq); prtavg=true; //SetClearAvgPi4(); continue; // cycle } } } //nfano -> 1=ok "0=no ok go to avg" "-1no real coll no go in avg" if (nfano!=-1 && decoded.isEmpty() && !prtavg)//nfano -> 1=ok "0=no ok go to avg" "-1no real coll no go in avg" { cflags = "Nor";//norm csync = "#"; decoded = "?";//2.16 +3s -3.0 print_msgpi4((int)sync,nsnr,dtxz-3.0,(nfreq-tx_nfqsopi4),width,decoded,csync,cflags,(int)nfreq); } c990: return; } void DecoderMs::lpf1(double *dd,int jz,double *dat,int &jz2) { int NFFT1=64*DEC_SAMPLE_RATE;// change hv int NFFT2=32*DEC_SAMPLE_RATE;//2.16 3s //int offset_pi4 = 1.0*(DEC_SAMPLE_RATE/2.0);//3.2 1.0,2.0,3.0 ... sec work from to 0.2s-4.0s //double x[NFFT1+50]; double *x = new double[NFFT1+1024];//+1024 for linux crash //double complex cx[NFFT1/2+50]; double complex *cx = new double complex[NFFT1+1024];//2.09 crash->[NFFT1/2+1024];//+1024 for linux crash double fac=1.0/double(NFFT1); for (int i = 0; i < jz; i++) x[i]=fac*dd[i]; for (int i = jz; i < NFFT1; i++) x[i]=0.0; f2a.four2a_d2c(cx,x,NFFT1,-1,0); for (int i = NFFT2/2; i < NFFT1/2; i++) cx[i]=0.0+0.0*I; f2a.four2a_d2c(cx,x,NFFT2,1,-1); jz2=jz/2; /*for (int i = 0; i < offset_pi4; i++) dat[i] = 0.0; int count_offset = offset_pi4; for (int i = 0; i < jz2-(offset_pi4+1); i++) { dat[count_offset]=x[i]; count_offset++; }*/ for (int i = 0; i < jz2; i++) { dat[i]=x[i]*0.01;//hv koeficient double } delete [] cx; delete [] x; } void DecoderMs::SetClearAvgPi4() { clearave_pi4 = true; emit EmitAvgSavesPi4(0,0); // exception } void DecoderMs::pi4_decode(double *dd,int jz) { int jz2 = 0; //double dat[361000]; //60*6000=360000 61*6000=366000 double *dat = new double[366000];//366000 int mode4=40;//nmode hv //bool NClearAve = clearave_pi4; int ntol = G_DfTolerance; //int neme = 0; int nutc = s_time.toInt()/100; int minsync = G_MinSigdB; //double emedelay = 0.0; // -99.0 outof cicle //double dttol = 3.0; //int minw = 0; double s_nfqsoPi4 = s_nfqso_all; //bool NAgain = false; int ndepth = 16;//G_DepthAvg;//0 stop avg=16 ; //qDebug()<<"s_nfqsoPi4 ntol"<