Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@
LIBSOURCES = fft_fftw.c libcsdr_wrapper.c
#SOURCES = csdr.c $(LIBSOURCES)
cpufeature = $(if $(findstring $(1),$(shell cat /proc/cpuinfo)),$(2))
kcmdfeature = $(if $(findstring $(1),$(shell cat /proc/cmdline)),$(2))
dpkghostarch = $(if $(findstring $(1),$(shell dpkg --print-architecture)),$(2))
PARAMS_SSE = $(call cpufeature,sse,-msse) $(call cpufeature,sse2,-msse2) $(call cpufeature,sse3,-msse3) $(call cpufeature,sse4a,-msse4a) $(call cpufeature,sse4_1,-msse4.1) $(call cpufeature,sse4_2,-msse4.2 -msse4) -mfpmath=sse
PARAMS_NEON = -mfloat-abi=hard -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mvectorize-with-neon-quad -funsafe-math-optimizations -Wformat=0 -DNEON_OPTS
#tnx Jan Szumiec for the Raspberry Pi support
PARAMS_RASPI = -mfloat-abi=hard -mcpu=arm1176jzf-s -mfpu=vfp -funsafe-math-optimizations -Wformat=0
PARAMS_ARM = $(if $(call cpufeature,BCM2708,dummy-text),$(PARAMS_RASPI),$(PARAMS_NEON))
PARAMS_RASPI_3 = -mfloat-abi=hard -mcpu=arm1176jzf-s -mfpu=vfp -funsafe-math-optimizations -Wformat=0
PARAMS_RASPI_4_ARMHF = -mcpu=cortex-a72 -mfloat-abi=hard -mfpu=neon-fp-armv8 -mneon-for-64bits -mtune=cortex-a72 -funsafe-math-optimizations -Wformat=0
PARAMS_RASPI_4_ARM64 = -mcpu=cortex-a72 -mtune=cortex-a72 -funsafe-math-optimizations -Wformat=0
PARAMS_RASPI_4 = $(if $(call dpkghostarch,arm64,dummy-text),$(PARAMS_RASPI_4_ARM64),$(PARAMS_RASPI_4_ARMHF))
PARAMS_RASPI = $(if $(call kcmdfeature,bcm2709,dummy-text),$(PARAMS_RASPI_4),$(PARAMS_RASPI_3))
PARAMS_ARM = $(if $(call kcmdfeature,bcm270,dummy-text),$(PARAMS_RASPI),$(PARAMS_NEON))
PARAMS_SIMD = $(if $(call cpufeature,sse,dummy-text),$(PARAMS_SSE),$(PARAMS_ARM))
PARAMS_LOOPVECT = -O3 -ffast-math -fdump-tree-vect-details -dumpbase dumpvect
PARAMS_LIBS = -g -lm -lrt -lfftw3f -DUSE_FFTW -DLIBCSDR_GPL -DUSE_IMA_ADPCM
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,31 @@ Syntax:

----

### [binary_decoder_f_u8](#binary_decoder_f_u8)

Syntax:

csdr binary_decoder_f_u8 <samples_per_symbol> [min_samples_per_symbol]

It tries to find symbol boundaries then has an algorithm for deciding whether each symbol is a 1 or a 0 the result of which it then outputs.
For this to function, a data preamble of either 5's or A's is helpful.

If a symbol boundary occurs before samples_per_symbol samples have been processed since the last symbol boundary, what has been processed so far is output as a valid symbol only if at least min_samples_per_symbol have been processed (otherwise it is discarded).
min_samples_per_symbol defaults to 3/4 of samples_per_symbol.

----

### [binary_to_ascii_u8_u8](#binary_to_ascii_u8_u8)

Syntax:

csdr binary_to_ascii_u8_u8

* If the input sample is 0, it outputs '0' (0x30).
* If the input sample is not 0, it outputs '1' (0x31).

----

### [serial_line_decoder_f_u8](#serial_line_decoder_f_u8)

Syntax:
Expand Down
50 changes: 50 additions & 0 deletions csdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ char usage[]=
" duplicate_samples_ntimes_u8_u8 <sample_size_bytes> <ntimes>\n"
" bpsk_costas_loop_cc <loop_bandwidth> <damping_factor> [--dd | --decision_directed] [--output_error | --output_dphase | --output_nco | --output_combined <error_file> <dphase_file> <nco_file>]\n"
" binary_slicer_f_u8\n"
" binary_decoder_f_u8 <samples_per_symbol> [min_samples_per_symbol]\n"
" binary_to_ascii_u8_u8\n"
" simple_agc_cc <rate> [reference [max_gain]]\n"
" firdes_peak_c <rate> <length> [window [--octave]]\n"
" peaks_fir_cc <taps_length> [peak_rate × N]\n"
Expand Down Expand Up @@ -2487,6 +2489,54 @@ int main(int argc, char *argv[])
return 0;
}

if(!strcmp(argv[1],"binary_decoder_f_u8"))
{
int samples_per_symbol;
int min_samples_per_symbol;
int output_size;

if(argc<=2) return badsyntax("need required parameter (samples_per_symbol)");
sscanf(argv[2],"%d",&samples_per_symbol);

if(argc>3)
{
sscanf(argv[3],"%d",&min_samples_per_symbol);
}
else
{
min_samples_per_symbol = (samples_per_symbol*3)/4;
}

if(!sendbufsize(initialize_buffers())) return -2;
for(;;)
{
FEOF_CHECK;
if(!FREAD_R) break;
output_size = binary_decoder_f_u8( input_buffer,
(unsigned char*)output_buffer,
the_bufsize,
samples_per_symbol,
min_samples_per_symbol);
fwrite(output_buffer, sizeof(unsigned char), output_size, stdout);
TRY_YIELD;
}
return 0;
}

if(!strcmp(argv[1],"binary_to_ascii_u8_u8"))
{
if(!sendbufsize(initialize_buffers())) return -2;
for(;;)
{
FEOF_CHECK;
if(!FREAD_U8) break;
binary_to_ascii_u8_u8((unsigned char*)input_buffer, (unsigned char*)output_buffer, the_bufsize);
FWRITE_U8;
TRY_YIELD;
}
return 0;
}

if(!strcmp(argv[1],"serial_line_decoder_f_u8")) //<samples_per_bits> [databits [stopbits]]
{
bigbufs=1;
Expand Down
69 changes: 65 additions & 4 deletions libcsdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1277,10 +1277,10 @@ void apply_precalculated_window_c(complexf* input, complexf* output, int size, f

void apply_precalculated_window_f(float* input, float* output, int size, float *windowt)
{
for(int i=0;i<size;i++) //@apply_precalculated_window_f
{
output[i] = input[i] * windowt[i];
}
for(int i=0;i<size;i++) //@apply_precalculated_window_f
{
output[i] = input[i] * windowt[i];
}
}

void apply_window_f(float* input, float* output, int size, window_t window)
Expand Down Expand Up @@ -1769,6 +1769,67 @@ void binary_slicer_f_u8(float* input, unsigned char* output, int input_size)
for(int i=0;i<input_size;i++) output[i] = input[i] > 0;
}

int binary_decoder_f_u8(float* input,
unsigned char* output,
int input_size,
int samples_per_symbol,
int min_samples_per_symbol)
{
static float previous_sample;
static float sample_accumulator;
static int sample_offset;

int i;
int output_size = 0;
float sample;

//notice rising edges crossing zero and assume they coincide with a symbol boundary.
//add all samples within a symbol and base the output on whether this accumulation is overall positive or negative.

for(i=0;i<input_size;i++)
{
sample = input[i];

//calibrate symbol position at a cross over (could have used either edge).
if ((previous_sample < 0) && (sample >= 0))
{
//if we've almost got a symbol, accept it and publish early.
if(sample_offset >= min_samples_per_symbol)
{
output[output_size] = (sample_accumulator > 0);
output_size++;
//fprintf(stderr, "symbol (%d:%f:%d)\n", sample_offset, sample_accumulator, output[output_size]);
}

sample_accumulator = 0;
sample_offset = 0;
}

sample_accumulator += sample;
sample_offset++;
if(sample_offset == samples_per_symbol)
{
output[output_size] = (sample_accumulator > 0);
output_size++;
//fprintf(stderr, "symbol (%d:%f:%d)\n", sample_offset, sample_accumulator, output[output_size]);

sample_accumulator = 0;
sample_offset = 0;
}

previous_sample = input[i];
}

return(output_size);
}

void binary_to_ascii_u8_u8(unsigned char* input,
unsigned char* output,
int input_size)
{
for(int i=0;i<input_size;i++) output[i] = input[i] ? '1' : '0';
}

void psk_modulator_u8_c(unsigned char* input, complexf* output, int input_size, int n_psk)
{
//outputs one complex sample per input symbol
Expand Down
9 changes: 9 additions & 0 deletions libcsdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ typedef struct serial_line_s
void serial_line_decoder_f_u8(serial_line_t* s, float* input, unsigned char* output, int input_size);
void binary_slicer_f_u8(float* input, unsigned char* output, int input_size);

int binary_decoder_f_u8(float* input,
unsigned char* output,
int input_size,
int samples_per_symbol,
int min_samples_per_symbol);

void binary_to_ascii_u8_u8(unsigned char* input,
unsigned char* output,
int input_size);

typedef enum pll_type_e
{
Expand Down