Integrate preamble search

This commit is contained in:
Thomas Kolb 2022-02-01 21:35:43 +01:00
parent b6713909f7
commit c17c7e060f
2 changed files with 90 additions and 56 deletions

View file

@ -19,6 +19,8 @@ set(sources
src/preamble.c src/preamble.c
src/transmission.h src/transmission.h
src/transmission.c src/transmission.c
src/correlator.h
src/correlator.c
) )
include_directories( include_directories(

View file

@ -4,11 +4,19 @@
#include <math.h> #include <math.h>
#include <liquid/liquid.h> #include <liquid/liquid.h>
#include "results.h"
#include "utils.h" #include "utils.h"
#include "packet_mod.h" #include "packet_mod.h"
#include "config.h" #include "config.h"
#include "preamble.h" #include "preamble.h"
#include "transmission.h" #include "transmission.h"
#include "correlator.h"
typedef enum {
RX_STATE_ACQUISITION,
RX_STATE_HEADER,
RX_STATE_DATA,
} rx_state_t;
int main(void) int main(void)
{ {
@ -93,6 +101,13 @@ int main(void)
float phase_history[FREQ_EST_L]; float phase_history[FREQ_EST_L];
memset(phase_history, 0, sizeof(phase_history)); memset(phase_history, 0, sizeof(phase_history));
// General receiver state
rx_state_t rx_state = RX_STATE_ACQUISITION;
// Correlator for preamble search
correlator_ctx_t preamble_correlator;
correlator_init(&preamble_correlator, preamble_get_symbols(), preamble_get_symbol_count());
for(unsigned int i = 0; i < burst_len; i++) { for(unsigned int i = 0; i < burst_len; i++) {
// Mix the input signal with the carrier NCO, which oscillates at the // Mix the input signal with the carrier NCO, which oscillates at the
// frequency estimated so far. // frequency estimated so far.
@ -100,10 +115,12 @@ int main(void)
nco_crcf_step(carrier_nco); nco_crcf_step(carrier_nco);
nco_crcf_mix_down(carrier_nco, msg_received[i], &mixed_sample); nco_crcf_mix_down(carrier_nco, msg_received[i], &mixed_sample);
// run the timing synchronizer (works even with shifted frequency // run the timing synchronizer (works even with shifted frequency)
unsigned int out_len; unsigned int out_len;
symsync_crcf_execute(symsync, &mixed_sample, 1, symsync_out + symsync_out_len, &out_len); symsync_crcf_execute(symsync, &mixed_sample, 1, symsync_out + symsync_out_len, &out_len);
switch(rx_state) {
case RX_STATE_ACQUISITION:
if(out_len != 0) { if(out_len != 0) {
// for all the output samples produced, run the frequency // for all the output samples produced, run the frequency
// estimator. This is an implementation that works with unknown // estimator. This is an implementation that works with unknown
@ -164,6 +181,21 @@ int main(void)
} }
} }
} }
break;
case RX_STATE_HEADER:
case RX_STATE_DATA:
break;
}
// preamble search
if(out_len != 0) {
float complex corr_out = correlator_step(&preamble_correlator, symsync_out[symsync_out_len]);
if(cabsf(corr_out) > 0.5f * preamble_get_symbol_count()) {
printf("Preamble found at sample %u: %.3f > %.3f\n", i/RRC_SPS, cabsf(corr_out), 0.5f * preamble_get_symbol_count());
}
}
symsync_out_len += out_len; symsync_out_len += out_len;
} }