From: baobrien Date: Sun, 24 Jan 2016 04:20:58 +0000 (+0000) Subject: fsk.c now matches fsk_horus closer X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=eb10443ae4323e8d6c44c2d282e12cf2dc08b9b3;p=freetel-svn-tracking.git fsk.c now matches fsk_horus closer git-svn-id: https://svn.code.sf.net/p/freetel/code@2650 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/octave/tfsk.m b/codec2-dev/octave/tfsk.m index 9b9ec895..31f42214 100644 --- a/codec2-dev/octave/tfsk.m +++ b/codec2-dev/octave/tfsk.m @@ -75,13 +75,13 @@ endfunction %Compare 2 vectors, fail if they are not close enough -function pass = vcompare(va,vb,vname,tname,tol) +function pass = vcompare(vc,voct,vname,tname,tol) %Get delta of vectors - dvec = abs(abs(va)-abs(vb)); + dvec = abs(abs(vc)-abs(voct)); %Normalize difference - dvec = dvec ./ abs(max(abs(va))); + dvec = dvec ./ abs(max(abs(voct))); maxdvec = abs(max(dvec)); pass = maxdvecEbNodB = 0; fsk->f1_est = 0; fsk->f2_est = 0; + fsk->twist_est = 0; + fsk->ppm = 0; return fsk; } @@ -341,10 +343,6 @@ void fsk_demod(struct FSK *fsk, uint8_t rx_bits[], float fsk_in[]){ /* Estimate tone frequencies */ fsk_demod_freq_est(fsk,fsk_in,&f1,&f2,&twist); - fsk->f1_est = f1; - fsk->f2_est = f2; - fsk->twist_est = twist; - /* allocate memory for the integrated samples */ /* Note: This must be kept after fsk_demod_freq_est for memory usage reasons */ f1_int = (COMP*) alloca(sizeof(COMP)*(nsym+1)*P); @@ -353,10 +351,19 @@ void fsk_demod(struct FSK *fsk, uint8_t rx_bits[], float fsk_in[]){ /* Allocate circular buffers for integration */ f1_intbuf = (COMP*) alloca(sizeof(COMP)*Ts); f2_intbuf = (COMP*) alloca(sizeof(COMP)*Ts); + + /* If this is the first run and we haven't already estimated freq, save the new est */ + if(fsk->f1_est<1 || fsk->f2_est<1){ + fsk->f1_est = f1; + fsk->f2_est = f2; + fsk->twist_est = twist; + } /* Figure out how much to nudge each sample downmixer for every sample */ - dphi1 = comp_exp_j(-2*M_PI*((float)(f1)/(float)(Fs))); - dphi2 = comp_exp_j(-2*M_PI*((float)(f2)/(float)(Fs))); + /* Use old freq. estimate here so that old samples will be converted at old + * frequency, to match behaviour of fsk_horus */ + dphi1 = comp_exp_j(-2*M_PI*((float)(fsk->f1_est)/(float)(Fs))); + dphi2 = comp_exp_j(-2*M_PI*((float)(fsk->f2_est)/(float)(Fs))); dc_i = 0; cbuf_i = 0; @@ -370,6 +377,12 @@ void fsk_demod(struct FSK *fsk, uint8_t rx_bits[], float fsk_in[]){ sample_src = &fsk_in[0]; dc_i = 0; using_old_samps = 0; + + /* Recalculate delta-phi after switching to new sample source */ + phi1_c = comp_normalize(phi1_c); + phi2_c = comp_normalize(phi2_c); + dphi1 = comp_exp_j(-2*M_PI*((float)(f1)/(float)(Fs))); + dphi2 = comp_exp_j(-2*M_PI*((float)(f2)/(float)(Fs))); } /* Downconvert and place into integration buffer */ f1_intbuf[dc_i]=fcmult(sample_src[dc_i],phi1_c); @@ -392,6 +405,12 @@ void fsk_demod(struct FSK *fsk, uint8_t rx_bits[], float fsk_in[]){ sample_src = &fsk_in[0]; dc_i = 0; using_old_samps = 0; + + /* Recalculate delta-phi after switching to new sample source */ + phi1_c = comp_normalize(phi1_c); + phi2_c = comp_normalize(phi2_c); + dphi1 = comp_exp_j(-2*M_PI*((float)(f1)/(float)(Fs))); + dphi2 = comp_exp_j(-2*M_PI*((float)(f2)/(float)(Fs))); } /* Downconvert and place into integration buffer */ f1_intbuf[cbuf_i+j]=fcmult(sample_src[dc_i],phi1_c); @@ -423,8 +442,12 @@ void fsk_demod(struct FSK *fsk, uint8_t rx_bits[], float fsk_in[]){ } - fsk->phi1_c = comp_normalize(phi1_c); - fsk->phi2_c = comp_normalize(phi2_c); + fsk->phi1_c = phi1_c; + fsk->phi2_c = phi2_c; + + fsk->f1_est = f1; + fsk->f2_est = f2; + fsk->twist_est = twist; /* Stash samples away in the old sample buffer for the next round of bit getting */ memcpy((void*)&(fsk->samp_old[0]),(void*)&(fsk_in[nin-nstash]),sizeof(float)*nstash);