From ee5b54643931b93aadae9a609476527ee62ff6f9 Mon Sep 17 00:00:00 2001 From: ha7ilm Date: Sat, 20 May 2017 21:02:18 +0200 Subject: [PATCH] Fixed generic slicer, etc. --- csdr.c | 9 ++++++--- grc_tests/bpsk31_tedvar.m | 30 ++++++++++-------------------- libcsdr.c | 25 +++++++++++++++++-------- 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/csdr.c b/csdr.c index 60b1a98..0d2d0cb 100755 --- a/csdr.c +++ b/csdr.c @@ -144,7 +144,7 @@ char usage[]= " repeat_u8 \n" " uniform_noise_f\n" " gaussian_noise_c\n" -" awgn_cc [--snrshow]\n" +" awgn_cc [--awgnfile ] [--snrshow]\n" " pack_bits_8to1_u8_u8\n" " pack_bits_1to8_u8_u8\n" " firdes_pulse_shaping_filter_f (RRC | COSINE )\n" @@ -158,7 +158,9 @@ char usage[]= " pattern_search_u8_u8 \n" " dbpsk_decoder_c_u8\n" " bfsk_demod_cf \n" +" normalized_timing_variance_u32_f [--debug]\n" " ?\n" +" ??\n" " =\n" " \n" ; @@ -2592,11 +2594,12 @@ int main(int argc, char *argv[]) if(argc>=(7+add_q) && !strcmp(argv[6+add_q], "--output_error")) output_error = 1; float* timing_error = NULL; if(output_error) timing_error = (float*)malloc(sizeof(float)*the_bufsize); - errhead(); fprintf(stderr, "--output_error mode\n"); + if(output_error) { errhead(); fprintf(stderr, "--output_error mode\n"); } if(argc>=(7+add_q) && !strcmp(argv[6+add_q], "--output_indexes")) output_indexes = 1; unsigned* sampled_indexes = NULL; if(output_indexes) sampled_indexes = (unsigned*)malloc(sizeof(float)*the_bufsize); + if(output_indexes) { errhead(); fprintf(stderr, "--output_indexes mode\n"); } if(!initialize_buffers()) return -2; sendbufsize(the_bufsize/decimation); @@ -3595,7 +3598,7 @@ int main(int argc, char *argv[]) if(argv[1][0]=='?') { char buffer[1000]; - snprintf(buffer, 1000-1, "csdr 2>&1 | grep %s", argv[1]+1); + snprintf(buffer, 1000-1, "csdr 2>&1 | grep -i %s", argv[1]+1); fprintf(stderr, "csdr ?: %s\n", buffer); system(buffer); return 0; diff --git a/grc_tests/bpsk31_tedvar.m b/grc_tests/bpsk31_tedvar.m index 74aad13..765dc3d 100755 --- a/grc_tests/bpsk31_tedvar.m +++ b/grc_tests/bpsk31_tedvar.m @@ -15,11 +15,13 @@ function y=inarg(x) y=0; end +bpfcmd="csdr bandpass_fir_fft_cc $(csdr \"=-31.25/8e3\") $(csdr \"=31.25/8e3\") $(csdr \"=31.25/8e3\") | "; + if !inarg('--nogen') fwrite(stdout, "===========================================\nGenerating baseband signal from random data\n===========================================\n"); - system('cat /dev/urandom | csdr pack_bits_8to1_u8_u8 | csdr psk_modulator_u8_c 2 | csdr gain_ff 0.25 | csdr psk31_interpolate_sine_cc 256 | csdr add_n_zero_samples_at_beginning_f 170 | pv -ps 2g | dd iflag=fullblock bs=128M count=16 of=/tmp/psk31-raw-data'); + system(["cat /dev/urandom | csdr pack_bits_8to1_u8_u8 | csdr psk_modulator_u8_c 2 | csdr gain_ff 0.25 | csdr psk31_interpolate_sine_cc 256 | " bpfcmd "csdr add_n_zero_samples_at_beginning_f 170 | pv -ps 2g | dd iflag=fullblock bs=128M count=16 of=/tmp/psk31-raw-data"]); fwrite(stdout, "===========================================\nGenerating Gaussian white noise for agwn_cc\n===========================================\n"); - system('csdr gaussian_noise_c | pv -ps 256m | dd of=/tmp/psk31-gaussian-noise iflag=fullblock bs=256M count=1'); + system(["csdr gaussian_noise_c | " bpfcmd "pv -ps 256m | dd of=/tmp/psk31-gaussian-noise iflag=fullblock bs=256M count=1"]); end if inarg('--onlygen') exit(0) @@ -49,7 +51,7 @@ end function variance=run_var(snr, which_ted) disp('ran a command') - out_vect=shrun(sprintf('cat /tmp/psk31-raw-data | csdr awgn_cc %d --awgnfile /tmp/psk31-gaussian-noise | csdr bandpass_fir_fft_cc $(csdr "=-31.25/8e3") $(csdr "=31.25/8e3") $(csdr "=31.25/8e3") | csdr simple_agc_cc 0.0001 0.5 | csdr timing_recovery_cc %s 256 0.5 2 --add_q --output_indexes | CSDR_FIXED_BUFSIZE=1048576 csdr normalized_timing_variance_u32_f 256 85', snr, which_ted), 'float32', 1); + out_vect=shrun(sprintf('cat /tmp/psk31-raw-data | csdr awgn_cc %d --awgnfile /tmp/psk31-gaussian-noise | csdr simple_agc_cc 0.0001 0.5 | csdr timing_recovery_cc %s 256 0.5 2 --add_q --output_indexes | CSDR_FIXED_BUFSIZE=1048576 csdr normalized_timing_variance_u32_f 256 85', snr, which_ted), 'float32', 1); disp('run_var output:'); out_vect' variance=out_vect(1); @@ -77,33 +79,21 @@ function fmtplot(h) ylabel('Phase error variance [rad^2]'); end -snrs=-15:5:20 +%snrs=-10:5:10 +snrs=-10:5:25 %snrs=[10] -error_values_gardner=mkvarplot('GARDNER',snrs); -%{ -snrs_earlylate=0:256 -error_values_earlylate=mkvarplot('EARLYLATE',snrs_earlylate); -%} +error_values=mkvarplot('EARLYLATE',snrs); %graphics_toolkit("gnuplot") h=figure(1); -ebn0=snrs-13.26-10*log10(1/256.) -%13.56 dB is the difference between the real (measured) SNR and the number input to awgn_cc. -%This is because agwn_cc assumes a signal with 0dB power at te input, while our BPSK31 baseband signal is of -13.26 dB. +ebn0=snrs+9.7 -semilogy(ebn0, error_values_gardner, 'linewidth', 2); +semilogy(ebn0, error_values, 'linewidth', 2); title('Estimation variance'); fmtplot(h) pause -%{ -semilogy(snrs_earlylate, error_values_earlylate, 'linewidth', 2); -title('S-curve for early-late TED'); -fmtplot(h) -pause -%} - if !inarg('--nogen') system('rm /tmp/psk31-raw-data /tmp/psk31-gaussian-noise'); end diff --git a/libcsdr.c b/libcsdr.c index 2058cf1..1eb91b3 100755 --- a/libcsdr.c +++ b/libcsdr.c @@ -1730,27 +1730,36 @@ void serial_line_decoder_f_u8(serial_line_t* s, float* input, unsigned char* out void generic_slicer_f_u8(float* input, unsigned char* output, int input_size, int n_symbols) { - float symbol_distance = 2.0/(n_symbols+1); + float symbol_distance = 2.0/(n_symbols-1); for(int i=0;i=symbol_low_limit) output[i]=j; - break; + if(input[i]>=symbol_low_limit) + { + output[i]=j; + break; + } } else { - if(input[i]>=symbol_low_limit && input[i]=symbol_low_limit && input[i]