From d5d2b09fe8bd190c5ffb45b7935a18df436000fb Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Wed, 14 Sep 2022 18:13:48 +0100 Subject: [PATCH 1/3] Restrict CW mode amplitude to 127. --- host/hackrf-tools/src/hackrf_transfer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index 41061ff0..399bbaef 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -629,7 +629,7 @@ static void usage() printf("\t[-S buf_size] # Enable receive streaming with buffer size buf_size.\n"); #endif printf("\t[-B] # Print buffer statistics during transfer\n"); - printf("\t[-c amplitude] # CW signal source mode, amplitude 0-128 (DC value to DAC).\n"); + printf("\t[-c amplitude] # CW signal source mode, amplitude 0-127 (DC value to DAC).\n"); printf("\t[-R] # Repeat TX mode (default is off) \n"); printf("\t[-b baseband_filter_bw_hz] # Set baseband filter bandwidth in Hz.\n"); printf("\tPossible values: 1.75/2.5/3.5/5/5.5/6/7/8/9/10/12/14/15/20/24/28MHz, default <= 0.75 * sample_rate_hz.\n"); @@ -1019,9 +1019,9 @@ int main(int argc, char** argv) if (signalsource) { transceiver_mode = TRANSCEIVER_MODE_SS; - if (amplitude > 128) { + if (amplitude > 127) { fprintf(stderr, - "argument error: amplitude must be between 0 and 128.\n"); + "argument error: amplitude must be between 0 and 127.\n"); usage(); return EXIT_FAILURE; } From 66fa76c55002be28bc7df67ba66293def85fc305 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Wed, 14 Sep 2022 18:14:59 +0100 Subject: [PATCH 2/3] In CW mode, set only the I component to the specified amplitude. --- host/hackrf-tools/src/hackrf_transfer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index 399bbaef..2a4d7b7f 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -506,8 +506,10 @@ int tx_callback(hackrf_transfer* transfer) bytes_to_xfer -= bytes_to_read; } - for (i = 0; i < bytes_to_read; i++) - transfer->buffer[i] = -(uint8_t) amplitude; + for (i = 0; i < bytes_to_read; i += 2) { + transfer->buffer[i] = amplitude; + transfer->buffer[i + 1] = 0; + } if (limit_num_samples && (bytes_to_xfer == 0)) { stop_main_loop(); From f1e34b7ceabd666120a9e942b233b0985e4f49c6 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Wed, 14 Sep 2022 18:15:44 +0100 Subject: [PATCH 3/3] Correct the calculation of dBfs signal level. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dBFS is defined in AES Standard AES17-1998, IEC 61606, and ITU-T Recs. P.381 and P.382, such that the RMS value of a full-scale sine wave is designated 0 dBFS. A full scale sine wave on HackRF has the range -127 to 127. We calculate the full scale ratio relative to a signal in which both I and Q are held at 127. This represents a signal with sqrt(2) times the amplitude, and thus twice the power, of a full scale sine wave. Therefore to obtain dBfs by the above definition, we add 3dB. --- host/hackrf-tools/src/hackrf_transfer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index 2a4d7b7f..654e4af2 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -1357,8 +1357,8 @@ int main(int argc, char** argv) fprintf(stderr, "Waiting for sync...\n"); } else { double full_scale_ratio = (double) stream_power_now / - (byte_count_now * 128 * 128); - double dB_full_scale = 10 * log10(full_scale_ratio); + (byte_count_now * 127 * 127); + double dB_full_scale = 10 * log10(full_scale_ratio) + 3.0; fprintf(stderr, "%4.1f MiB / %5.3f sec = %4.1f MiB/second, average power %3.1f dBfs", (byte_count_now / 1e6f),