Fixed and tested AGC

master
Ismael Gomez 7 years ago
parent 6196c096af
commit 8b6bd607a7

@ -117,7 +117,7 @@ void srslte_agc_lock(srslte_agc_t *q, bool enable) {
void srslte_agc_process(srslte_agc_t *q, cf_t *signal, uint32_t len) { void srslte_agc_process(srslte_agc_t *q, cf_t *signal, uint32_t len) {
if (!q->lock) { if (!q->lock) {
float gain_db = 10*log10(q->gain); float gain_db = 10*log10(q->gain);
float gain_uhd_db = 1.0; float gain_uhd_db = 50.0;
//float gain_uhd = 1.0; //float gain_uhd = 1.0;
float y = 0; float y = 0;
// Apply current gain to input signal // Apply current gain to input signal
@ -125,10 +125,10 @@ void srslte_agc_process(srslte_agc_t *q, cf_t *signal, uint32_t len) {
srslte_vec_sc_prod_cfc(signal, q->gain, signal, len); srslte_vec_sc_prod_cfc(signal, q->gain, signal, len);
} else { } else {
if (gain_db < 0) { if (gain_db < 0) {
gain_db = 0.0; gain_db = 5.0;
} }
if (isinf(gain_db) || isnan(gain_db)) { if (isinf(gain_db) || isnan(gain_db)) {
gain_db = 10.0; gain_db = 40.0;
} else { } else {
gain_uhd_db = q->set_gain_callback(q->uhd_handler, gain_db); gain_uhd_db = q->set_gain_callback(q->uhd_handler, gain_db);
q->gain = pow(10, gain_uhd_db/10); q->gain = pow(10, gain_uhd_db/10);

@ -41,7 +41,7 @@ int rf_get_available_devices(char **devnames, int max_strlen) {
double srslte_rf_set_rx_gain_th(srslte_rf_t *rf, double gain) double srslte_rf_set_rx_gain_th(srslte_rf_t *rf, double gain)
{ {
if (gain > rf->new_rx_gain + 0.5 || gain < rf->new_rx_gain - 0.5) { if (gain > rf->new_rx_gain + 2 || gain < rf->new_rx_gain - 2) {
pthread_mutex_lock(&rf->mutex); pthread_mutex_lock(&rf->mutex);
rf->new_rx_gain = gain; rf->new_rx_gain = gain;
pthread_cond_signal(&rf->cond); pthread_cond_signal(&rf->cond);
@ -69,6 +69,7 @@ static void* thread_gain_fcn(void *h) {
srslte_rf_set_rx_gain(h, rf->cur_rx_gain); srslte_rf_set_rx_gain(h, rf->cur_rx_gain);
} }
if (rf->tx_gain_same_rx) { if (rf->tx_gain_same_rx) {
printf("setting also tx\n");
srslte_rf_set_tx_gain(h, rf->cur_rx_gain+rf->tx_rx_gain_offset); srslte_rf_set_tx_gain(h, rf->cur_rx_gain+rf->tx_rx_gain_offset);
} }
pthread_mutex_unlock(&rf->mutex); pthread_mutex_unlock(&rf->mutex);

@ -122,6 +122,8 @@ int srslte_ue_sync_start_agc(srslte_ue_sync_t *q, double (set_gain_callback)(voi
q->do_agc = n==0?true:false; q->do_agc = n==0?true:false;
if (q->do_agc) { if (q->do_agc) {
srslte_agc_set_gain(&q->agc, init_gain_value); srslte_agc_set_gain(&q->agc, init_gain_value);
srslte_agc_set_target(&q->agc, 0.3);
srslte_agc_set_bandwidth(&q->agc, 0.8);
} }
return n; return n;
} }

@ -57,8 +57,9 @@ int radio_recv_wrapper_cs(void *obj, cf_t *data[SRSLTE_MAX_PORTS], uint32_t nsam
} }
double callback_set_rx_gain(void *h, double gain) { double callback_set_rx_gain(void *h, double gain) {
srslte::radio_multi *radio_handler = (srslte::radio_multi *) h; phch_recv *obj = (phch_recv*) h;
return radio_handler->set_rx_gain_th(gain); srslte::radio_multi *radio_h = obj->radio_h;
return radio_h->set_rx_gain_th(gain);
} }
@ -100,6 +101,7 @@ void phch_recv:: init(srslte::radio_multi *_radio_handler, mac_interface_phy *_
// Set options defined in expert section // Set options defined in expert section
set_ue_sync_opts(&cs.ue_sync); set_ue_sync_opts(&cs.ue_sync);
last_gain = 40;
if (do_agc) { if (do_agc) {
srslte_ue_sync_start_agc(&cs.ue_sync, callback_set_rx_gain, last_gain); srslte_ue_sync_start_agc(&cs.ue_sync, callback_set_rx_gain, last_gain);
} }
@ -553,8 +555,6 @@ bool phch_recv::cell_select(uint32_t earfcn, srslte_cell_t cell) {
current_earfcn = earfcn; current_earfcn = earfcn;
printf("cell select called set frequency\n");
if (set_frequency()) { if (set_frequency()) {
this->cell = cell; this->cell = cell;
log_h->info("Cell Select: Configuring cell...\n"); log_h->info("Cell Select: Configuring cell...\n");
@ -670,7 +670,7 @@ void phch_recv::run_thread() {
switch (cell_sync_sfn()) { switch (cell_sync_sfn()) {
case 1: case 1:
srslte_ue_sync_set_agc_period(&ue_sync, 20); srslte_ue_sync_set_agc_period(&ue_sync, 4);
if (!cell_search_in_progress) { if (!cell_search_in_progress) {
phy_state = CELL_CAMP; phy_state = CELL_CAMP;
log_h->info("Sync OK. Camping on cell PCI=%d...\n", cell.id); log_h->info("Sync OK. Camping on cell PCI=%d...\n", cell.id);

@ -117,6 +117,10 @@ bool ue::init(all_args_t *args_)
// Init layers // Init layers
if (args->rf.rx_gain < 0) {
phy.set_agc_enable(true);
}
// PHY initis in background, start before radio // PHY initis in background, start before radio
args->expert.phy.nof_rx_ant = args->rf.nof_rx_ant; args->expert.phy.nof_rx_ant = args->rf.nof_rx_ant;
phy.init(&radio, &mac, &rrc, phy_log, &args->expert.phy); phy.init(&radio, &mac, &rrc, phy_log, &args->expert.phy);
@ -160,8 +164,6 @@ bool ue::init(all_args_t *args_)
if (args->rf.rx_gain < 0) { if (args->rf.rx_gain < 0) {
radio.start_agc(false); radio.start_agc(false);
radio.set_tx_rx_gain_offset(10);
phy.set_agc_enable(true);
} else { } else {
radio.set_rx_gain(args->rf.rx_gain); radio.set_rx_gain(args->rf.rx_gain);
} }

Loading…
Cancel
Save