Improved handling of up- and downsampling

This commit is contained in:
Thomas Kolb 2024-01-02 23:49:55 +01:00
parent d55e3ab902
commit ef0fad4335
3 changed files with 30 additions and 18 deletions

View file

@ -3,6 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <liquid/liquid.h>
@ -154,9 +155,9 @@ static result_t transmit_in_chunks(sdr_ctx_t *sdr, const float complex *samples,
to_transmit_bb = CHUNKSIZE_BB;
}
RESULT_CHECK(sdr_baseband_to_rf(sdr, samples + transmitted, to_transmit_bb, rf_samples, CHUNKSIZE_RF));
size_t to_transmit_rf = CHUNKSIZE_RF;
size_t to_transmit_rf = to_transmit_bb * SDR_OVERSAMPLING;
RESULT_CHECK(sdr_baseband_to_rf(sdr, samples + transmitted, to_transmit_bb, rf_samples, &to_transmit_rf));
result_t result = sdr_transmit(sdr, rf_samples, to_transmit_rf, 100000);
@ -261,7 +262,7 @@ int main(void)
dump_array_cf(whole_burst, burst_len, 1.0f, "/tmp/tx.cpx");
if(!on_air) {
//RESULT_CHECK(sdr_stop_rx(&sdr));
RESULT_CHECK(sdr_stop_rx(&sdr));
RESULT_CHECK(sdr_start_tx(&sdr, burst_len * SDR_OVERSAMPLING));
// hopefully no longer needed with latest libhackrf
@ -274,8 +275,8 @@ int main(void)
} else if(on_air) { // ret == 0
//RESULT_CHECK(sdr_flush_tx_buffer(&sdr));
//RESULT_CHECK(sdr_stop_tx(&sdr));
//RESULT_CHECK(sdr_start_rx(&sdr));
RESULT_CHECK(sdr_stop_tx(&sdr));
RESULT_CHECK(sdr_start_rx(&sdr));
on_air = false;
block_tx_for(TX_SWITCH_BACKOFF_AFTER_RX_ON);
@ -289,7 +290,7 @@ int main(void)
float complex bb_samples[CHUNKSIZE_BB];
size_t n_rf_samples = CHUNKSIZE_RF;
size_t n_bb_samples;
size_t n_bb_samples = CHUNKSIZE_BB;
if(sdr_receive(&sdr, rf_samples, &n_rf_samples, 100000) != OK) {
rx_retries++;
@ -301,6 +302,12 @@ int main(void)
}
}
if(n_rf_samples == 0) {
struct timespec ts_1ms = {0, 1000000};
nanosleep(&ts_1ms, NULL);
continue;
}
total_samples += n_rf_samples;
double new = get_hires_time();
@ -323,9 +330,7 @@ int main(void)
fprintf(stderr, "r");
RESULT_CHECK(sdr_rf_to_baseband(&sdr, rf_samples, n_rf_samples, bb_samples, CHUNKSIZE_BB));
n_bb_samples = n_rf_samples / SDR_OVERSAMPLING;
RESULT_CHECK(sdr_rf_to_baseband(&sdr, rf_samples, n_rf_samples, bb_samples, &n_bb_samples));
RESULT_CHECK(layer1_rx_process(&rx, bb_samples, n_bb_samples));
} else {

View file

@ -7,6 +7,7 @@
#include <math.h>
#include <string.h>
#include <time.h>
#include <assert.h>
#include "config.h"
@ -342,16 +343,20 @@ result_t sdr_flush_tx_buffer(sdr_ctx_t *ctx)
result_t sdr_rf_to_baseband(sdr_ctx_t *ctx,
const float complex *rf_samples, size_t nrf,
float complex *bb_samples, size_t nbb)
float complex *bb_samples, size_t *nbb)
{
if((nbb * SDR_OVERSAMPLING) < nrf) {
fprintf(stderr, "sdr_rf_to_baseband: result would not fit in output: %zd * %d < %zd\n", nbb, SDR_OVERSAMPLING, nrf);
if((*nbb * SDR_OVERSAMPLING) < nrf) {
fprintf(stderr, "sdr_rf_to_baseband: result would not fit in output: %zd * %d < %zd\n", *nbb, SDR_OVERSAMPLING, nrf);
return ERR_SIZE;
}
for(size_t i = 0; i < nbb; i++) {
*nbb = nrf / SDR_OVERSAMPLING;
for(size_t i = 0; i < *nbb; i++) {
float complex tmp[SDR_OVERSAMPLING];
assert(i*SDR_OVERSAMPLING < nrf);
nco_crcf_mix_block_down(ctx->rx_nco,
(complex float*)(rf_samples + i * SDR_OVERSAMPLING),
tmp,
@ -366,13 +371,15 @@ result_t sdr_rf_to_baseband(sdr_ctx_t *ctx,
result_t sdr_baseband_to_rf(sdr_ctx_t *ctx,
const float complex *bb_samples, size_t nbb,
float complex *rf_samples, size_t nrf)
float complex *rf_samples, size_t *nrf)
{
if((nbb * SDR_OVERSAMPLING) > nrf) {
fprintf(stderr, "sdr_baseband_to_rf: result would not fit in output: %zd * %d > %zd\n", nbb, SDR_OVERSAMPLING, nrf);
if((nbb * SDR_OVERSAMPLING) > *nrf) {
fprintf(stderr, "sdr_baseband_to_rf: result would not fit in output: %zd * %d > %zd\n", nbb, SDR_OVERSAMPLING, *nrf);
return ERR_SIZE;
}
*nrf = nbb * SDR_OVERSAMPLING;
for(size_t i = 0; i < nbb; i++) {
float complex tmp[SDR_OVERSAMPLING];

View file

@ -51,13 +51,13 @@ result_t sdr_flush_tx_buffer(sdr_ctx_t *ctx);
*/
result_t sdr_rf_to_baseband(sdr_ctx_t *ctx,
const float complex *rf_samples, size_t nrf,
float complex *bb_samples, size_t nbb);
float complex *bb_samples, size_t *nbb);
/*!
* \brief Convert and resample a baseband signal for transmission.
*/
result_t sdr_baseband_to_rf(sdr_ctx_t *ctx,
const float complex *bb_samples, size_t nbb,
float complex *rf_samples, size_t nrf);
float complex *rf_samples, size_t *nrf);
#endif // SDR_SDR_H