From f9a6535e108a10170569bc1b5ac981382f84128d Mon Sep 17 00:00:00 2001 From: ha7ilm Date: Thu, 18 May 2017 23:43:40 +0200 Subject: [PATCH] Edited Makefile Changed functionality of pack_bits_8to1_u8_u8 Added pack_bits_1to8_u8_u8, pattern_search_u8_u8, dbpsk_decoder_c_u8, bfsk_demod_cf --- Makefile | 3 + README.md | 12 +- csdr.c | 173 +++++++++++++++++- grc_tests/psk31_sigmodel.m | 32 +++- .../test_bpsk_costas_loop_convertwavs.sh | 1 + libcsdr.c | 64 ++++++- libcsdr.h | 8 +- 7 files changed, 271 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 905bf3a..a82a63e 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,7 @@ PARAMS_MISC = -Wno-unused-result #DEBUG_ON = 0 #debug is always on by now (anyway it could be compiled with `make DEBUG_ON=1`) #PARAMS_DEBUG = $(if $(DEBUG_ON),-g,) FFTW_PACKAGE = fftw-3.3.3 +PARSEVECT ?= yes .PHONY: clean-vect clean codequality all: codequality csdr nmux @@ -51,7 +52,9 @@ libcsdr.so: fft_fftw.c fft_rpi.c libcsdr_wrapper.c libcsdr.c libcsdr_gpl.c fastd @echo rm -f dumpvect*.vect gcc -std=gnu99 $(PARAMS_LOOPVECT) $(PARAMS_SIMD) $(LIBSOURCES) $(PARAMS_LIBS) $(PARAMS_MISC) -fpic -shared -o libcsdr.so +ifeq ($(PARSEVECT),yes) -./parsevect dumpvect*.vect +endif csdr: csdr.c libcsdr.so gcc -std=gnu99 $(PARAMS_LOOPVECT) $(PARAMS_SIMD) csdr.c $(PARAMS_LIBS) -L. -lcsdr $(PARAMS_MISC) -o csdr ddcd: ddcd.cpp libcsdr.so ddcd.h diff --git a/README.md b/README.md index c133c91..1bdc57e 100755 --- a/README.md +++ b/README.md @@ -832,7 +832,7 @@ For this input, the output of `psk31_varicode_encoder_u8_u8` will be the followi Syntax: - csdr repeat_u8 [resonator_rate × N]\n" + csdr repeat_u8 It repeatedly outputs a set of data bytes (given with decimal numbers). @@ -871,6 +871,16 @@ Syntax: csdr pack_bits_8to1_u8_u8 +TODO + +---- + +### [pack_bits_1to8_u8_u8](#pack_bits_1to8_u8_u8) + +Syntax: + + csdr pack_bits_1to8_u8_u8 + It serializes the bytes on the input: it outputs each bit of the input byte as a single byte valued 0x00 or 0x01, starting from the lowest bit and going to the highest bit. The output is 8 times as large in size as the input. diff --git a/csdr.c b/csdr.c index ad1d30d..58edba7 100755 --- a/csdr.c +++ b/csdr.c @@ -146,6 +146,7 @@ char usage[]= " gaussian_noise_c\n" " awgn_cc [--snrshow]\n" " pack_bits_8to1_u8_u8\n" +" pack_bits_1to8_u8_u8\n" " firdes_pulse_shaping_filter_f (RRC | COSINE )\n" " pulse_shaping_filter_cc (RRC | COSINE )\n" " add_n_zero_samples_at_beginning_f \n" @@ -154,6 +155,9 @@ char usage[]= " add_const_cc \n" " tee [buffers]\n" " pll_cc (1 [alpha] |2 [bandwidth [damping_factor [ko [kd]]]])\n" +" pattern_search_u8_u8 \n" +" dbpsk_decoder_c_u8\n" +" bfsk_demod_cf \n" " ?\n" " =\n" " \n" @@ -2723,7 +2727,7 @@ int main(int argc, char *argv[]) } } - if(!strcmp(argv[1],"pack_bits_8to1_u8_u8")) + if(!strcmp(argv[1],"pack_bits_1to8_u8_u8")) { if(!initialize_buffers()) return -2; sendbufsize(the_bufsize*8); @@ -2733,12 +2737,27 @@ int main(int argc, char *argv[]) { FEOF_CHECK; fread((void*)local_input_buffer, sizeof(unsigned char), the_bufsize, stdin); - pack_bits_8to1_u8_u8(local_input_buffer, local_output_buffer, the_bufsize); + pack_bits_1to8_u8_u8(local_input_buffer, local_output_buffer, the_bufsize); fwrite((void*)local_output_buffer, sizeof(unsigned char), the_bufsize*8, stdout); TRY_YIELD; } } + if(!strcmp(argv[1],"pack_bits_8to1_u8_u8")) + { + if(!initialize_buffers()) return -2; + sendbufsize(1); + char local_input_buffer[8]; + for(;;) + { + FEOF_CHECK; + fread((void*)local_input_buffer, sizeof(unsigned char), 8, stdin); + unsigned char c = pack_bits_8to1_u8_u8(local_input_buffer); + fwrite(&c, sizeof(unsigned char), 1, stdout); + TRY_YIELD; + } + } + if(!strcmp(argv[1],"psk31_varicode_encoder_u8_u8")) { if(!initialize_buffers()) return -2; @@ -2914,7 +2933,7 @@ int main(int argc, char *argv[]) complexf* taps=(complexf*)malloc(sizeof(complexf)*length); //Make the filter - firdes_add_resonator_c(taps, length, rate, window, 0, 1); + firdes_add_peak_c(taps, length, rate, window, 0, 1); //Do the output if(octave) printf("taps=["); @@ -2960,7 +2979,7 @@ int main(int argc, char *argv[]) for(int i=0; i + { + float frequency_shift = 0; + if(argc<=2) return badsyntax("required parameter is missing."); + sscanf(argv[2],"%f",&frequency_shift); + + int filter_length = 0; + if(argc<=3) return badsyntax("required parameter is missing."); + sscanf(argv[3],"%d",&filter_length); + + complexf* mark_filter = (complexf*)malloc(sizeof(complexf)*filter_length); + complexf* space_filter = (complexf*)malloc(sizeof(complexf)*filter_length); + firdes_add_peak_c(mark_filter, filter_length, frequency_shift/2, WINDOW_DEFAULT, 0, 1); + firdes_add_peak_c(space_filter, filter_length, -frequency_shift/2, WINDOW_DEFAULT, 0, 1); + + if(!sendbufsize(initialize_buffers())) return -2; + + int input_skip=0; + int output_size=0; + FREAD_C; + for(;;) + { + FEOF_CHECK; + output_size=bfsk_demod_cf((complexf*)input_buffer, output_buffer, the_bufsize, mark_filter, space_filter, filter_length); + fwrite(output_buffer, sizeof(float), output_size, stdout); + TRY_YIELD; + memmove((complexf*)input_buffer,((complexf*)input_buffer)+output_size,(the_bufsize-output_size)*sizeof(complexf)); + fread(((complexf*)input_buffer)+(the_bufsize-output_size), sizeof(complexf), output_size, stdin); + } + return 0; + } + if(!strcmp(argv[1], "add_const_cc")) // { complexf x; @@ -3411,6 +3477,105 @@ int main(int argc, char *argv[]) TRY_YIELD; } } +/* + if(!strcmp(argv[1],"syncword_search")) + { + if(argc<3) return badsyntax("need required parameter (syncword)"); + unsigned long syncword=0UL; + int syncword_length=strlen(argv[2]); + for(int i=0; i='0') cval = c-'0'; + if(c<='f'&&c>='a') cval = c-'a'+10; + syncword|=cval; + } + errhead(); fprintf("syncword = 0x%0x, syncword_length=%d\n", syncword, syncword_length); + if(argc<4) return badsyntax("need required parameter (bits_after)"); + int bits_after = 0; + sscanf(argv[3], &bits_after); + if(bits_after<0) return badsyntax("bits_after should be >0"); + unsigned char* syncword_bits = malloc(sizeof(unsigned char)*syncword_length*4); + int k=0; + for(int i=0;i>j + } + } + malloc + + } +*/ + if(!strcmp(argv[1],"pattern_search_u8_u8")) // + { + if(argc<3) return badsyntax("need required parameter (values_after)"); + int values_after = 0; + sscanf(argv[2], "%d", &values_after); + if(argc<4) return badsyntax("need required parameter (pattern_values × N)"); + int pattern_values_length = argc-3; + unsigned* pattern_values = (unsigned*)malloc(sizeof(unsigned)*pattern_values_length); + for(int i=0;i=pattern_values_length) input_index=0; + int match=1; + //fprintf(stderr, "ov1: "); + //for(int i=0;i>bi)&1; } + +unsigned char pack_bits_8to1_u8_u8(unsigned char* input) +{ + unsigned char output; + for(int i=0;i<8;i++) + { + output<<=1; + output|=!!input[i]; + } + return output; +} unsigned char differential_codec(unsigned char* input, unsigned char* output, int input_size, int encode, unsigned char state) { if(!encode) @@ -2081,7 +2092,8 @@ void init_bpsk_costas_loop_cc(bpsk_costas_loop_state_t* s, int decision_directed s->alpha = (4*damping_factor*bandwidth_omega)/denomiator; s->beta = (4*bandwidth_omega*bandwidth_omega)/denomiator; s->current_freq = s->dphase = s->nco_phase = 0; - s->dphase_max=bandwidth*PI; //this has been determined by experiment: if dphase is out of [-dphase_max; dphase_max] it might actually hang and not come back + s->dphase_max=bandwidth_omega; //this has been determined by experiment: if dphase is out of [-dphase_max; dphase_max] it might actually hang and not come back + s->dphase_max_reset_to_zero=0; } void bpsk_costas_loop_cc(complexf* input, complexf* output, int input_size, float* output_error, float* output_dphase, complexf* output_nco, bpsk_costas_loop_state_t* s) @@ -2106,10 +2118,10 @@ void bpsk_costas_loop_cc(complexf* input, complexf* output, int input_size, floa } else error = PI*iof(output,i)*qof(output,i); if(output_error) output_error[i]=error; - s->current_freq += error * s->beta; + s->current_freq += error * s->beta; s->dphase = error * s->alpha + s->current_freq; - if(s->dphase>s->dphase_max) s->dphase=s->dphase_max; - if(s->dphase<-s->dphase_max) s->dphase=-s->dphase_max; + if(s->dphase>s->dphase_max) s->dphase = (s->dphase_max_reset_to_zero) ? 0 : s->dphase_max; + if(s->dphase<-s->dphase_max) s->dphase = (s->dphase_max_reset_to_zero) ? 0 : -s->dphase_max; if(output_dphase) output_dphase[i]=s->dphase; //fprintf(stderr, " error = %f; dphase = %f; nco_phase = %f;\n", error, s->dphase, s->nco_phase); @@ -2195,7 +2207,7 @@ void simple_agc_cc(complexf* input, complexf* output, int input_size, float rate } } -void firdes_add_resonator_c(complexf* output, int length, float rate, window_t window, int add, int normalize) +void firdes_add_peak_c(complexf* output, int length, float rate, window_t window, int add, int normalize) { //add=0: malloc output previously //add=1: calloc output previously @@ -2203,7 +2215,7 @@ void firdes_add_resonator_c(complexf* output, int length, float rate, window_t w int middle=length/2; float phase = 0, phase_addition = -rate*M_PI*2; float (*window_function)(float) = firdes_get_window_kernel(window); - for(int i=0; i=PI) dphase-=2*PI; + if( (dphase>(PI/2)) || (dphase<(-PI/2)) ) output[i]=0; + else output[i]=1; + last_input = input[i]; + } +} + +int bfsk_demod_cf(complexf* input, float* output, int input_size, complexf* mark_filter, complexf* space_filter, int taps_length) +{ + complexf acc_space, acc_mark; + for(int i=0; i