sdr: various fixes; use Kaiser filter for resampling

This commit is contained in:
Thomas Kolb 2022-03-05 21:37:33 +01:00
parent 85663d5304
commit 3bc1d9625f

View file

@ -5,6 +5,7 @@
#include <stdlib.h> //free
#include <complex.h>
#include <math.h>
#include <string.h>
#include "config.h"
@ -32,23 +33,23 @@ result_t sdr_init(sdr_ctx_t *ctx)
ctx->tx_stream = NULL;
ctx->rx_stream = NULL;
ctx->interp = firinterp_crcf_create_prototype(LIQUID_FIRFILT_PM, SDR_OVERSAMPLING, 10, 0.2, 0);
ctx->decim = firdecim_crcf_create_prototype(LIQUID_FIRFILT_PM, SDR_OVERSAMPLING, 10, 0.2, 0);
ctx->interp = firinterp_crcf_create_kaiser(SDR_OVERSAMPLING, 9, 60.0f);
ctx->decim = firdecim_crcf_create_kaiser(SDR_OVERSAMPLING, 9, 60.0f);
ctx->tx_nco = nco_crcf_create(LIQUID_NCO);
ctx->rx_nco = nco_crcf_create(LIQUID_NCO);
nco_crcf_set_frequency(ctx->tx_nco, -2 * M_PI * SDR_TX_IF_SHIFT / SDR_TX_SAMPLING_RATE);
nco_crcf_set_frequency(ctx->rx_nco, -2 * M_PI * SDR_RX_IF_SHIFT / SDR_TX_SAMPLING_RATE);
nco_crcf_set_frequency(ctx->tx_nco, 2 * M_PI * SDR_TX_IF_SHIFT / SDR_TX_SAMPLING_RATE);
nco_crcf_set_frequency(ctx->rx_nco, 2 * M_PI * SDR_RX_IF_SHIFT / SDR_RX_SAMPLING_RATE);
//enumerate devices
SoapySDRKwargs *results = SoapySDRDevice_enumerate(NULL, &length);
for (size_t i = 0; i < length; i++)
{
fprintf(stderr, "sdr: Found device #%d: ", (int)i);
fprintf(stderr, "sdr: Found device #%d:\n", (int)i);
for (size_t j = 0; j < results[i].size; j++)
{
fprintf(stderr, "sdr: %s=%s, ", results[i].keys[j], results[i].vals[j]);
fprintf(stderr, "sdr: - %s=%s\n", results[i].keys[j], results[i].vals[j]);
}
fprintf(stderr, "sdr: \n");
}
@ -57,6 +58,7 @@ result_t sdr_init(sdr_ctx_t *ctx)
//create device instance
//args can be user defined or from the enumeration result
SoapySDRKwargs args;
memset(&args, 0, sizeof(args));
SoapySDRKwargs_set(&args, "driver", "hackrf");
ctx->sdr = SoapySDRDevice_make(&args);
SoapySDRKwargs_clear(&args);
@ -150,7 +152,7 @@ result_t sdr_start_tx(sdr_ctx_t *ctx)
shutdown_streams(ctx);
//setup a stream (complex floats)
ctx->tx_stream = SoapySDRDevice_setupStream(ctx->sdr, SOAPY_SDR_RX, SOAPY_SDR_CF32, NULL, 0, NULL);
ctx->tx_stream = SoapySDRDevice_setupStream(ctx->sdr, SOAPY_SDR_TX, SOAPY_SDR_CF32, NULL, 0, NULL);
if(ctx->tx_stream == NULL) {
fprintf(stderr, "sdr: setupStream fail: %s\n", SoapySDRDevice_lastError());
@ -237,7 +239,7 @@ result_t sdr_baseband_to_rf(sdr_ctx_t *ctx,
for(size_t i = 0; i < nbb; i++) {
float complex tmp[SDR_OVERSAMPLING];
firinterp_crcf_execute(ctx->interp, bb_samples[i], tmp);
firinterp_crcf_execute(ctx->interp, bb_samples[i] / 2.0f, tmp);
nco_crcf_mix_block_up(ctx->tx_nco,
tmp,