From 4cfc3dca2b252bfa65cf1633b9f966d572493547 Mon Sep 17 00:00:00 2001 From: tvoid Date: Tue, 8 Apr 2008 01:11:27 -0600 Subject: -fixed burst_cf sampling --- gsm-tvoid/src/lib/gsm_burst.cc | 9 ++-- gsm-tvoid/src/lib/gsm_burst_cf.cc | 111 +++++++++++++++++++------------------- gsm-tvoid/src/lib/gsm_burst_cf.h | 4 +- gsm-tvoid/src/python/gsm_scan.py | 4 +- 4 files changed, 67 insertions(+), 61 deletions(-) (limited to 'gsm-tvoid') diff --git a/gsm-tvoid/src/lib/gsm_burst.cc b/gsm-tvoid/src/lib/gsm_burst.cc index cb896bc..00a5a95 100755 --- a/gsm-tvoid/src/lib/gsm_burst.cc +++ b/gsm-tvoid/src/lib/gsm_burst.cc @@ -358,14 +358,15 @@ void gsm_burst::shift_burst(int shift_bits) //of the mean phase from pi/2. void gsm_burst::calc_freq_offset(void) { - int start = d_burst_start + 10; - int end = d_burst_start + USEFUL_BITS - 10; + const int padding = 20; + int start = d_burst_start + padding; + int end = d_burst_start + USEFUL_BITS - padding; float sum = 0.0; for (int j = start; j <= end; j++) { sum += d_burst_buffer[j]; } - float mean = sum / ((float)USEFUL_BITS - 20.0); + float mean = sum / ((float)USEFUL_BITS - 2.0 * (float)padding); float p_off = mean - (M_PI / 2); d_freq_offset = p_off * 1625000.0 / (12.0 * M_PI); @@ -701,6 +702,7 @@ int gsm_burst::get_burst(void) ///////////////////// //start tune testing +#ifdef TEST_TUNE_TIMING static int good_count = -1; //-1: wait sch, >=0: got sch, counting if (UNKNOWN == d_burst_type) { @@ -732,6 +734,7 @@ int gsm_burst::get_burst(void) } } } +#endif //end tune testing ///////////////////// diff --git a/gsm-tvoid/src/lib/gsm_burst_cf.cc b/gsm-tvoid/src/lib/gsm_burst_cf.cc index 08ff7ba..821b41f 100755 --- a/gsm-tvoid/src/lib/gsm_burst_cf.cc +++ b/gsm-tvoid/src/lib/gsm_burst_cf.cc @@ -25,6 +25,7 @@ gsm_burst_cf::gsm_burst_cf (gr_feval_ll *t, float sample_rate) : gr_make_io_signature (MIN_IN, MAX_IN, sizeof (gr_complex)), gr_make_io_signature (MIN_OUT, MAX_OUT, USEFUL_BITS * sizeof (float))), d_clock_counter(0.0), + d_mu(0.5), d_last_sample(0.0,0.0), d_interp(new gri_mmse_fir_interpolator_cc()) @@ -37,7 +38,7 @@ gsm_burst_cf::gsm_burst_cf (gr_feval_ll *t, float sample_rate) : fprintf(stderr,"Sample interval : %e\n",d_sample_interval); fprintf(stderr,"Relative sample rate : %g\n",d_relative_sample_rate); - set_history(4); + set_history(4); //need history for interpolator } @@ -68,70 +69,70 @@ int gsm_burst_cf::general_work (int noutput_items, int ninput = ninput_items[0]; //fprintf(stderr,"#i=%d/#o=%d",n_input,noutput_items); - int ni = ninput - d_interp->ntaps(); // interpolator need -4/+3 samples NTAPS = 8 + int ni = ninput - d_interp->ntaps() - 16; // interpolator need -4/+3 samples NTAPS = 8 , - 16 for safety margin while (( rval < noutput_items) && ( ii < ni ) ) { //clock symbols //TODO: this is very basic and can be improved. Need tracking... //TODO: use burst_start offsets as timing feedback //TODO: save complex samples for Viterbi EQ - if ( d_clock_counter >= GSM_SYMBOL_PERIOD) { - - d_clock_counter -= GSM_SYMBOL_PERIOD; //reset clock for next sample, keep the remainder - - //float mu = 1.0 - d_clock_counter / GSM_SYMBOL_PERIOD; - float mu = d_clock_counter / GSM_SYMBOL_PERIOD; - gr_complex sample = d_interp->interpolate (&in[ii], mu); //FIXME: this seems noisy, make sure it is being used correctly + + //from m&m + gr_complex sample = d_interp->interpolate (&in[ii], d_mu); //FIXME: this seems noisy, make sure it is being used correctly + + gr_complex conjprod = sample * conj(d_last_sample); + float diff_angle = gr_fast_atan2f(imag(conjprod), real(conjprod)); - gr_complex conjprod = sample * conj(d_last_sample); - float diff_angle = gr_fast_atan2f(imag(conjprod), real(conjprod)); + d_last_sample = sample; - d_last_sample = sample; - - assert(d_bbuf_pos <= BBUF_SIZE ); - - if (d_bbuf_pos >= 0) //could be negative offset from burst alignment. TODO: perhaps better just to add some padding to the buffer - d_burst_buffer[d_bbuf_pos] = diff_angle; - - d_bbuf_pos++; - - if ( d_bbuf_pos >= BBUF_SIZE ) { - - if (get_burst()) { - //found a burst, send to output - //ensure that output data is in range - int b = d_burst_start; - if (b < 0) - b = 0; - else if (b >= 2 * MAX_CORR_DIST) - b = 2 * MAX_CORR_DIST - 1; + assert(d_bbuf_pos <= BBUF_SIZE ); + + if (d_bbuf_pos >= 0) //could be negative offset from burst alignment. TODO: perhaps better just to add some padding to the buffer + d_burst_buffer[d_bbuf_pos] = diff_angle; - memcpy(out+rval*USEFUL_BITS, d_burst_buffer + b, USEFUL_BITS*sizeof(float)); - rval++; - - switch ( d_clock_options & QB_MASK ) { - case QB_QUARTER: //extra 1/4 bit each burst - d_clock_counter -= GSM_SYMBOL_PERIOD / 4.0; - break; - case QB_FULL04: //extra bit on timeslot 0 & 4 - if (!(d_ts%4)) - d_clock_counter -= GSM_SYMBOL_PERIOD; - break; - case QB_NONE: //don't adjust for quarter bits at all - default: - break; - } - - d_last_burst_s_count = d_sample_count; - - //fprintf(stderr,"clock: %f, pos: %d\n",d_clock_counter,d_bbuf_pos); + d_bbuf_pos++; + + if ( d_bbuf_pos >= BBUF_SIZE ) { + + if (get_burst()) { + //found a burst, send to output + //ensure that output data is in range + int b = d_burst_start; + if (b < 0) + b = 0; + else if (b >= 2 * MAX_CORR_DIST) + b = 2 * MAX_CORR_DIST - 1; + + memcpy(out+rval*USEFUL_BITS, d_burst_buffer + b, USEFUL_BITS*sizeof(float)); + rval++; + + switch ( d_clock_options & QB_MASK ) { + case QB_QUARTER: //extra 1/4 bit each burst + d_mu -= d_relative_sample_rate / 4.0; + //d_clock_counter -= GSM_SYMBOL_PERIOD / 4.0; + break; + case QB_FULL04: //extra bit on timeslot 0 & 4 + if (!(d_ts%4)) + d_mu -= d_relative_sample_rate; + //d_clock_counter -= GSM_SYMBOL_PERIOD; + break; + case QB_NONE: //don't adjust for quarter bits at all + default: + break; } - } - } - - d_clock_counter += d_sample_interval; - d_sample_count++; - ii++; + + d_last_burst_s_count = d_sample_count; + + //fprintf(stderr,"clock: %f, pos: %d\n",d_clock_counter,d_bbuf_pos); + } + } + + //TODO: timing adjust + //d_mu = d_mu + d_omega + d_gain_mu * mm_val; + d_mu += d_relative_sample_rate; + ii += (int)floor(d_mu); + d_sample_count += (int)floor(d_mu); + d_mu -= floor(d_mu); } //fprintf(stderr,"/ii=%d/rval=%d\n",ii,rval); diff --git a/gsm-tvoid/src/lib/gsm_burst_cf.h b/gsm-tvoid/src/lib/gsm_burst_cf.h index 2b806e0..40ccc83 100755 --- a/gsm-tvoid/src/lib/gsm_burst_cf.h +++ b/gsm-tvoid/src/lib/gsm_burst_cf.h @@ -20,11 +20,13 @@ private: gsm_burst_cf(gr_feval_ll *,float); //clocking parameters - float d_relative_sample_rate; double d_sample_interval; double d_clock_counter; gr_complex d_last_sample; + float d_relative_sample_rate; //omega + float d_mu; + gri_mmse_fir_interpolator_cc *d_interp; //sub-sample interpolator from GR public: diff --git a/gsm-tvoid/src/python/gsm_scan.py b/gsm-tvoid/src/python/gsm_scan.py index 51ff92e..577acf4 100755 --- a/gsm-tvoid/src/python/gsm_scan.py +++ b/gsm-tvoid/src/python/gsm_scan.py @@ -36,10 +36,10 @@ class burst_callback(gr.feval_ll): try: #print "burst_callback: ", x, "\n"; if gsm.BURST_CB_ADJ_OFFSET == x: - return 0 + #return 0 #TODO: rework so this will work on file input last_offset = self.fg.burst.last_freq_offset() - if 20000.0 > abs(last_offset) > 200.0: + if 20000.0 > abs(last_offset) > 500.0: self.fg.offset -= last_offset print "burst_callback: ADJ_OFFSET:", last_offset, " ARFCN: ", self.fg.arfcn, "\n"; self.fg.set_channel(self.fg.arfcn) -- cgit v1.2.3