From 1bd471a70362f4634d5cde195250d37c29c10fc7 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sun, 5 Dec 2021 11:46:57 +0100 Subject: [PATCH] When a transmitter is off, send absolutely nothing This is done by shifting away the transmitter from center (DC) freqency. Useless code was removed, since there is nothing to be transmitted. --- src/libfm/fm.c | 22 +++------------------ src/libsdr/sdr.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/libfm/fm.c b/src/libfm/fm.c index 8463dc5d..079491cd 100644 --- a/src/libfm/fm.c +++ b/src/libfm/fm.c @@ -194,27 +194,11 @@ again: mod->state = MOD_STATE_RAMP_UP; break; } - /* deviation is defined by the frequency value and the offset */ - dev = offset + *frequency++; + /* just count, and add nothing */ + frequency++; power++; length--; - if (fast_math) { - phase += 65536.0 * dev / rate; - if (phase < 0.0) - phase += 65536.0; - else if (phase >= 65536.0) - phase -= 65536.0; - *baseband++ += cos_tab[(uint16_t)phase] * amplitude * ramp_tab[ramp]; - *baseband++ += sin_tab[(uint16_t)phase] * amplitude * ramp_tab[ramp]; - } else { - phase += 2.0 * M_PI * dev / rate; - if (phase < 0.0) - phase += 2.0 * M_PI; - else if (phase >= 2.0 * M_PI) - phase -= 2.0 * M_PI; - *baseband++ += cos(phase) * amplitude * ramp_tab[ramp]; - *baseband++ += sin(phase) * amplitude * ramp_tab[ramp]; - } + baseband += 2; } break; case MOD_STATE_RAMP_UP: diff --git a/src/libsdr/sdr.c b/src/libsdr/sdr.c index 6d41e533..45615c56 100644 --- a/src/libsdr/sdr.c +++ b/src/libsdr/sdr.c @@ -295,6 +295,57 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque } tx_center_frequency = (tx_high_frequency + tx_low_frequency) / 2.0; + /* prevent channel bandwidth from overlapping with the center frequency */ + if (channels == 1 && !sdr->paging_channel) { + /* simple: just move off the center by two times half of the bandwidth */ + tx_center_frequency -= 2.0 * bandwidth / 2.0; + /* Note: tx_low_frequency is kept at old center. + Calculation of 'low_side' will become 0. + This is correct, since there is no bandwidth + below new center frequency. + */ + PDEBUG(DSDR, DEBUG_INFO, "We shift center frequency %.0f KHz down (half bandwidth), to prevent channel from overlap with DC level.\n", bandwidth / 2.0 / 1e3); + } else { + /* find two channels that are aside the center */ + double low_dist, high_dist, dist; + int low_c = -1, high_c = -1; + for (c = 0; c < channels; c++) { + dist = fabs(tx_center_frequency - sdr->chan[c].tx_frequency); + if (round(sdr->chan[c].tx_frequency) >= round(tx_center_frequency)) { + if (high_c < 0 || dist < high_dist) { + high_dist = dist; + high_c = c; + } + } else { + if (low_c < 0 || dist < low_dist) { + low_dist = dist; + low_c = c; + } + } + } + if (sdr->paging_channel) { + dist = fabs(tx_center_frequency - sdr->chan[sdr->paging_channel].tx_frequency); + if (round(sdr->chan[sdr->paging_channel].tx_frequency) >= round(tx_center_frequency)) { + if (high_c < 0 || dist < high_dist) { + high_dist = dist; + high_c = sdr->paging_channel; + } + } else { + if (low_c < 0 || dist < low_dist) { + low_dist = dist; + low_c = sdr->paging_channel; + } + } + } + /* new center = center of the two frequencies aside old center */ + if (low_c >= 0 && high_c >= 0) { + tx_center_frequency = + ((sdr->chan[low_c].tx_frequency) + + (sdr->chan[high_c].tx_frequency)) / 2.0; + PDEBUG(DSDR, DEBUG_INFO, "We move center freqeuency between the two channels in the middle, to prevent them from overlap with DC level.\n"); + } + } + /* show spectrum */ show_spectrum("TX", (double)samplerate / 2.0, tx_center_frequency, tx_frequency, paging_frequency, channels);