Fixed generic slicer, etc.

This commit is contained in:
ha7ilm 2017-05-20 21:02:18 +02:00
parent 978289e76b
commit ee5b546439
3 changed files with 33 additions and 31 deletions

9
csdr.c
View file

@ -144,7 +144,7 @@ char usage[]=
" repeat_u8 <data_bytes × N>\n"
" uniform_noise_f\n"
" gaussian_noise_c\n"
" awgn_cc <snr_db> [--snrshow]\n"
" awgn_cc <snr_db> [--awgnfile <file>] [--snrshow]\n"
" pack_bits_8to1_u8_u8\n"
" pack_bits_1to8_u8_u8\n"
" firdes_pulse_shaping_filter_f (RRC <samples_per_symbol> <num_taps> <beta> | COSINE <samples_per_symbol>)\n"
@ -158,7 +158,9 @@ char usage[]=
" pattern_search_u8_u8 <values_after> <pattern_values × N>\n"
" dbpsk_decoder_c_u8\n"
" bfsk_demod_cf <spacing> <filter_length>\n"
" normalized_timing_variance_u32_f <samples_per_symbol> <initial_sample_offset> [--debug]\n"
" ?<search_the_function_list>\n"
" ??<jump_to_function_docs_on_github>\n"
" =<evaluate_python_expression>\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;

View file

@ -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

View file

@ -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<input_size;i++)
for(int j=0;j<n_symbols;i++)
for(int j=0;j<n_symbols;j++)
{
float symbol_center = -1+j*symbol_distance;
float symbol_low_limit = symbol_center-(symbol_distance/2);
float symbol_high_limit = symbol_center+(symbol_distance/2);
if(j==0)
{
if(input[i]<symbol_high_limit) output[i]=j;
break;
if(input[i]<symbol_high_limit)
{
output[i]=j;
break;
}
}
else if (j==n_symbols-1)
{
if(input[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_high_limit) output[i]=j;
break;
if(input[i]>=symbol_low_limit && input[i]<symbol_high_limit)
{
output[i]=j;
break;
}
}
}
}