Major cosmetic changes to preamble detector

This commit is contained in:
Nick Foster 2011-06-08 22:02:13 -07:00
parent 140f91537c
commit c8dce82b75
2 changed files with 45 additions and 51 deletions

View File

@ -54,14 +54,8 @@ air_modes_preamble::air_modes_preamble(int channel_rate, float threshold_db) :
}
static int early_late(const float *data) {
float gate_sum_early, gate_sum_now, gate_sum_late;
gate_sum_early = data[-1];
gate_sum_now = data[0];
gate_sum_late = data[1];
if(gate_sum_early > gate_sum_now) return -1;
else if(gate_sum_late > gate_sum_now) return 1;
if(data[-1] > data[0]) return -1;
else if(data[1] > data[0]) return 1;
else return 0;
}
@ -70,16 +64,21 @@ int air_modes_preamble::work(int noutput_items,
gr_vector_void_star &output_items)
{
//do things!
const float *inraw = (const float *) input_items[0];
const float *in = (const float *) input_items[0];
const float *inavg = (const float *) input_items[1];
float *outraw = (float *) output_items[0];
float *out = (float *) output_items[0];
int size = noutput_items;// - d_check_width;
int pulse_offsets[4];
float bit_energies[4];
int size = noutput_items;
const int pulse_offsets[4] = {0,
int(1.0 * d_samples_per_symbol),
int(3.5 * d_samples_per_symbol),
int(4.5 * d_samples_per_symbol)
};
float preamble_pulses[4];
memcpy(outraw, inraw, size * sizeof(float));
memcpy(out, in, size * sizeof(float));
uint64_t abs_out_sample_cnt = nitems_written(0);
@ -88,50 +87,45 @@ int air_modes_preamble::work(int noutput_items,
bool valid_preamble = false;
float gate_sum_now = 0, gate_sum_early = 0, gate_sum_late = 0;
if(inraw[i] > pulse_threshold) { //if the sample is greater than the reference level by the specified amount
int gate_sum = early_late(&inraw[i]);
if(in[i] > pulse_threshold) { //if the sample is greater than the reference level by the specified amount
int gate_sum = early_late(&in[i]);
if(gate_sum != 0) continue; //if either the early gate or the late gate had greater energy, keep moving.
//the packets are so short we choose not to do any sort of closed-loop synchronization after this simple gating.
//if we get a good center sample, the drift should be negligible.
pulse_offsets[0] = 0;
pulse_offsets[1] = int(1.0 * d_samples_per_symbol);
pulse_offsets[2] = int(3.5 * d_samples_per_symbol);
pulse_offsets[3] = int(4.5 * d_samples_per_symbol);
bit_energies[0] = inraw[i+pulse_offsets[0]];
bit_energies[1] = inraw[i+pulse_offsets[1]];
bit_energies[2] = inraw[i+pulse_offsets[2]];
bit_energies[3] = inraw[i+pulse_offsets[3]];
preamble_pulses[0] = in[i+pulse_offsets[0]];
preamble_pulses[1] = in[i+pulse_offsets[1]];
preamble_pulses[2] = in[i+pulse_offsets[2]];
preamble_pulses[3] = in[i+pulse_offsets[3]];
//search for the rest of the pulses at their expected positions
if( bit_energies[1] < pulse_threshold) continue;
if( bit_energies[2] < pulse_threshold) continue;
if( bit_energies[3] < pulse_threshold) continue;
if( preamble_pulses[1] < pulse_threshold ) continue;
if( preamble_pulses[2] < pulse_threshold ) continue;
if( preamble_pulses[3] < pulse_threshold ) continue;
valid_preamble = true; //this gets falsified by the following statements to disqualify a preamble
float avgpeak = (bit_energies[0] + bit_energies[1] + bit_energies[2] + bit_energies[3]) / 4;
float avgpeak = (preamble_pulses[0] + preamble_pulses[1] + preamble_pulses[2] + preamble_pulses[3]) / 4;
//set the threshold requirement for spaces (0 chips) to
//threshold dB below the current peak
float space_threshold = bit_energies[0] / d_threshold;
float space_threshold = preamble_pulses[0] / d_threshold;
//search between pulses and all the way out to 8.0us to make
//sure there are no pulses inside the "0" chips. make sure
//all the samples are <= (inraw[peak] * d_threshold).
//all the samples are <= (in[peak] * d_threshold).
//so 0.5us has to be < space_threshold, as does (1.5-3), 4, (5-7.5) in order to qualify.
for(int j = 1.5 * d_samples_per_symbol; j <= 3 * d_samples_per_symbol; j+=d_samples_per_chip)
if(inraw[i+j] > space_threshold) valid_preamble = false;
if(in[i+j] > space_threshold) valid_preamble = false;
for(int j = 5 * d_samples_per_symbol; j <= 7.5 * d_samples_per_symbol; j+=d_samples_per_chip)
if(inraw[i+j] > space_threshold) valid_preamble = false;
if(in[i+j] > space_threshold) valid_preamble = false;
//make sure all four peaks are within 3dB of each other
float minpeak = avgpeak * 0.5;//-3db, was 0.631; //-2db
float maxpeak = avgpeak * 2.0;//3db, was 1.585; //2db
if(bit_energies[0] < minpeak || bit_energies[0] > maxpeak) continue;
if(bit_energies[1] < minpeak || bit_energies[1] > maxpeak) continue;
if(bit_energies[2] < minpeak || bit_energies[2] > maxpeak) continue;
if(bit_energies[3] < minpeak || bit_energies[3] > maxpeak) continue;
if(preamble_pulses[0] < minpeak || preamble_pulses[0] > maxpeak) continue;
if(preamble_pulses[1] < minpeak || preamble_pulses[1] > maxpeak) continue;
if(preamble_pulses[2] < minpeak || preamble_pulses[2] > maxpeak) continue;
if(preamble_pulses[3] < minpeak || preamble_pulses[3] > maxpeak) continue;
}
if(valid_preamble) {
@ -140,20 +134,20 @@ int air_modes_preamble::work(int noutput_items,
bool early, late;
do {
early = late = false;
//gate_sum_early= inraw[i+pulse_offsets[0]-1]
// + inraw[i+pulse_offsets[1]-1]
// + inraw[i+pulse_offsets[2]-1]
// + inraw[i+pulse_offsets[3]-1];
//gate_sum_early= in[i+pulse_offsets[0]-1]
// + in[i+pulse_offsets[1]-1]
// + in[i+pulse_offsets[2]-1]
// + in[i+pulse_offsets[3]-1];
gate_sum_now = inraw[i+pulse_offsets[0]]
+ inraw[i+pulse_offsets[1]]
+ inraw[i+pulse_offsets[2]]
+ inraw[i+pulse_offsets[3]];
gate_sum_now = in[i+pulse_offsets[0]]
+ in[i+pulse_offsets[1]]
+ in[i+pulse_offsets[2]]
+ in[i+pulse_offsets[3]];
gate_sum_late = inraw[i+pulse_offsets[0]+1]
+ inraw[i+pulse_offsets[1]+1]
+ inraw[i+pulse_offsets[2]+1]
+ inraw[i+pulse_offsets[3]+1];
gate_sum_late = in[i+pulse_offsets[0]+1]
+ in[i+pulse_offsets[1]+1]
+ in[i+pulse_offsets[2]+1]
+ in[i+pulse_offsets[3]+1];
early = (gate_sum_early > gate_sum_now);
late = (gate_sum_late > gate_sum_now);

View File

@ -100,8 +100,8 @@ class adsb_rx_block (gr.top_block):
#if a particular Mode S transponder is using a pulse shaping filter,
#this will not be optimal.
self.filtcoeffs = list()
for i in range(int(rate/2e6)):
self.filtcoeffs.append(1.0 / (rate/2e6))
for i in range(int(rate/4e6)):
self.filtcoeffs.append(1.0 / (rate/4e6))
#i think downstream blocks can therefore process at 2Msps -- try this
#self.filter = gr.fir_filter_fff(int(rate/2e6), self.filtcoeffs)