From 32a218b5d97d591b64bcff455f17bf6019b35dcf Mon Sep 17 00:00:00 2001 From: hayati ayguen Date: Sat, 19 Sep 2020 14:11:23 +0000 Subject: [PATCH 1/2] added simple carrier generator functions command line interface options are: gen_dc_f / gen_dc_s16, gen_pos_fs4_f / gen_pos_fs4_s16 and gen_neg_fs4_f / gen_neg_fs4_s16 Signed-off-by: hayati ayguen --- csdr.c | 77 ++++++++++++++++++++++++++++++++++++++- libcsdr.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ libcsdr.h | 9 +++++ 3 files changed, 191 insertions(+), 1 deletion(-) diff --git a/csdr.c b/csdr.c index 27dbf6dc..e6a20a3e 100755 --- a/csdr.c +++ b/csdr.c @@ -66,6 +66,12 @@ char usage[]= " convert_s16_f\n" " convert_f_s24 [--bigendian]\n" " convert_s24_f [--bigendian]\n" +" gen_dc_f\n" +" gen_dc_s16\n" +" gen_pos_fs4_f\n" +" gen_pos_fs4_s16\n" +" gen_neg_fs4_f\n" +" gen_neg_fs4_s16\n" " realpart_cf\n" " clipdetect_ff\n" " limit_ff [max_amplitude]\n" @@ -364,7 +370,7 @@ int initialize_buffers() input_buffer = (float*) malloc(the_bufsize*sizeof(float) * 2); //need the 2× because we might also put complex floats into it output_buffer = (float*) malloc(the_bufsize*sizeof(float) * 2); buffer_u8 = (unsigned char*)malloc(the_bufsize*sizeof(unsigned char)); - buffer_i16 = (short*) malloc(the_bufsize*sizeof(short)); + buffer_i16 = (short*) malloc(the_bufsize*sizeof(short) * 2); temp_f = (float*) malloc(the_bufsize*sizeof(float) * 4); if(the_bufsize<=4096) //this is hacky, should be done correctly { @@ -631,6 +637,75 @@ int main(int argc, char *argv[]) TRY_YIELD; } } + + if(!strcmp(argv[1],"gen_dc_f")) + { + if(!sendbufsize(initialize_buffers())) return -2; + for(;;) + { + FEOF_CHECK; + generate_dc_f(output_buffer, the_bufsize); + FWRITE_C; + TRY_YIELD; + } + } + if(!strcmp(argv[1],"gen_dc_s16")) + { + if(!sendbufsize(initialize_buffers())) return -2; + for(;;) + { + FEOF_CHECK; + generate_dc_s16(buffer_i16, the_bufsize); + fwrite(buffer_i16, sizeof(short)*2, the_bufsize, stdout); + TRY_YIELD; + } + } + if(!strcmp(argv[1],"gen_pos_fs4_f")) + { + if(!sendbufsize(initialize_buffers())) return -2; + for(;;) + { + FEOF_CHECK; + generate_pos_fs4_f(output_buffer, the_bufsize); + FWRITE_C; + TRY_YIELD; + } + } + if(!strcmp(argv[1],"gen_pos_fs4_s16")) + { + if(!sendbufsize(initialize_buffers())) return -2; + for(;;) + { + FEOF_CHECK; + generate_pos_fs4_s16(buffer_i16, the_bufsize); + fwrite(buffer_i16, sizeof(short)*2, the_bufsize, stdout); + TRY_YIELD; + } + } + if(!strcmp(argv[1],"gen_neg_fs4_f")) + { + if(!sendbufsize(initialize_buffers())) return -2; + for(;;) + { + FEOF_CHECK; + generate_neg_fs4_f(output_buffer, the_bufsize); + FWRITE_C; + TRY_YIELD; + } + } + if(!strcmp(argv[1],"gen_neg_fs4_s16")) + { + if(!sendbufsize(initialize_buffers())) return -2; + for(;;) + { + FEOF_CHECK; + generate_neg_fs4_s16(buffer_i16, the_bufsize); + fwrite(buffer_i16, sizeof(short)*2, the_bufsize, stdout); + TRY_YIELD; + } + } + + if(!strcmp(argv[1],"realpart_cf")) { if(!sendbufsize(initialize_buffers())) return -2; diff --git a/libcsdr.c b/libcsdr.c index 9751bba4..08ec3370 100755 --- a/libcsdr.c +++ b/libcsdr.c @@ -2436,6 +2436,112 @@ void convert_s24_f(unsigned char* input, float* output, int input_size, int bige } } + +void generate_dc_f(float* output, int size) +{ + for(int i=0;i<2*size;) + { + /* exp(i*0) = 1+i*0 */ + output[i++]=(127.0F / 128.0F); + output[i++]=0.0F; + } +} + +void generate_dc_s16(short* output, int size) +{ + for(int i=0;i<2*size;) + { + /* exp(i*0) = 1+i*0 */ + output[i++]=SHRT_MAX; + output[i++]=0; + } +} + +void generate_pos_fs4_f(float* output, int size) +{ + /* size must be multiple of 4 */ + assert(!(size&3)); + for(int i=0;i<2*size;) + { + /* exp(i*0) = 1+i*0 */ + output[i++]=(127.0F / 128.0F); + output[i++]=0.0F; + /* exp(i* +pi/2) = 0+i*1 */ + output[i++]=0.0F; + output[i++]=(127.0F / 128.0F); + /* exp(i* +pi) = -1+i*0 */ + output[i++]=(-127.0F / 128.0F); + output[i++]=0.0F; + /* exp(i* -pi/2) = 0+i*-1 */ + output[i++]=0.0F; + output[i++]=(-127.0F / 128.0F); + } +} + +void generate_pos_fs4_s16(short* output, int size) +{ + /* size must be multiple of 4 */ + assert(!(size&3)); + for(int i=0;i<2*size;) + { + /* exp(i*0) = 1+i*0 */ + output[i++]=SHRT_MAX; + output[i++]=0; + /* exp(i* +pi/2) = 0+i*1 */ + output[i++]=0; + output[i++]=SHRT_MAX; + /* exp(i* +pi) = -1+i*0 */ + output[i++]=-SHRT_MAX; + output[i++]=0; + /* exp(i* -pi/2) = 0+i*-1 */ + output[i++]=0; + output[i++]=-SHRT_MAX; + } +} + +void generate_neg_fs4_f(float* output, int size) +{ + /* size must be multiple of 4 */ + assert(!(size&3)); + for(int i=0;i<2*size;) + { + /* exp(i*0) = 1+i*0 */ + output[i++]=(127.0F / 128.0F); + output[i++]=0.0F; + /* exp(i* -pi/2) = 0+i*-1 */ + output[i++]=0.0F; + output[i++]=(-127.0F / 128.0F); + /* exp(i* +pi) = -1+i*0 */ + output[i++]=(-127.0F / 128.0F); + output[i++]=0.0F; + /* exp(i* +pi/2) = 0+i*1 */ + output[i++]=0.0F; + output[i++]=(127.0F / 128.0F); + } +} + +void generate_neg_fs4_s16(short* output, int size) +{ + /* size must be multiple of 4 */ + assert(!(size&3)); + for(int i=0;i<2*size;) + { + /* exp(i*0) = 1+i*0 */ + output[i++]=SHRT_MAX; + output[i++]=0; + /* exp(i* -pi/2) = 0+i*-1 */ + output[i++]=0; + output[i++]=-SHRT_MAX; + /* exp(i* +pi) = -1+i*0 */ + output[i++]=-SHRT_MAX; + output[i++]=0; + /* exp(i* +pi/2) = 0+i*1 */ + output[i++]=0; + output[i++]=SHRT_MAX; + } +} + + FILE* init_get_random_samples_f() { return fopen("/dev/urandom", "r"); diff --git a/libcsdr.h b/libcsdr.h index 7e472056..f8b5ac5c 100644 --- a/libcsdr.h +++ b/libcsdr.h @@ -229,6 +229,15 @@ void convert_f_s24(float* input, unsigned char* output, int input_size, int bige void convert_s24_f(unsigned char* input, float* output, int input_size, int bigendian); +/* generation functions */ +void generate_dc_f(float* output, int size); +void generate_dc_s16(short* output, int size); +void generate_pos_fs4_f(float* output, int size); +void generate_pos_fs4_s16(short* output, int size); +void generate_neg_fs4_f(float* output, int size); +void generate_neg_fs4_s16(short* output, int size); + + int is_nan(float f); //digital demod From 5295a824e82c1825f4030bac9d4a8aa192c365fe Mon Sep 17 00:00:00 2001 From: hayati ayguen Date: Fri, 2 Oct 2020 22:04:51 +0000 Subject: [PATCH 2/2] added some more simple generator functions / their combinations command line interface options are: gen_dc_pos_fs4_s16, gen_dc_neg_fs4_s16, gen_pos_neg_fs4_s16, gen_dc_pos_neg_fs4_s16, gen_pos_neg_fs2_s16, gen_dc_pos_neg_fs2_s16 Signed-off-by: hayati ayguen --- csdr.c | 77 +++++++++++++++++++++++++++++ libcsdr.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ libcsdr.h | 8 +++ 3 files changed, 228 insertions(+) diff --git a/csdr.c b/csdr.c index e6a20a3e..528dad4a 100755 --- a/csdr.c +++ b/csdr.c @@ -66,12 +66,22 @@ char usage[]= " convert_s16_f\n" " convert_f_s24 [--bigendian]\n" " convert_s24_f [--bigendian]\n" + " gen_dc_f\n" " gen_dc_s16\n" " gen_pos_fs4_f\n" " gen_pos_fs4_s16\n" " gen_neg_fs4_f\n" " gen_neg_fs4_s16\n" + +" gen_dc_pos_fs4_s16\n" +" gen_dc_neg_fs4_s16\n" +" gen_pos_neg_fs4_s16\n" +" gen_dc_pos_neg_fs4_s16\n" + +" gen_pos_neg_fs2_s16\n" +" gen_dc_pos_neg_fs2_s16\n" + " realpart_cf\n" " clipdetect_ff\n" " limit_ff [max_amplitude]\n" @@ -705,6 +715,73 @@ int main(int argc, char *argv[]) } } + if(!strcmp(argv[1],"gen_dc_pos_fs4_s16")) + { + if(!sendbufsize(initialize_buffers())) return -2; + for(;;) + { + FEOF_CHECK; + generate_dc_pos_fs4_s16(buffer_i16, the_bufsize); + fwrite(buffer_i16, sizeof(short)*2, the_bufsize, stdout); + TRY_YIELD; + } + } + if(!strcmp(argv[1],"gen_dc_neg_fs4_s16")) + { + if(!sendbufsize(initialize_buffers())) return -2; + for(;;) + { + FEOF_CHECK; + generate_dc_neg_fs4_s16(buffer_i16, the_bufsize); + fwrite(buffer_i16, sizeof(short)*2, the_bufsize, stdout); + TRY_YIELD; + } + } + if(!strcmp(argv[1],"gen_pos_neg_fs4_s16")) + { + if(!sendbufsize(initialize_buffers())) return -2; + for(;;) + { + FEOF_CHECK; + generate_pos_neg_fs4_s16(buffer_i16, the_bufsize); + fwrite(buffer_i16, sizeof(short)*2, the_bufsize, stdout); + TRY_YIELD; + } + } + if(!strcmp(argv[1],"gen_dc_pos_neg_fs4_s16")) + { + if(!sendbufsize(initialize_buffers())) return -2; + for(;;) + { + FEOF_CHECK; + generate_dc_pos_neg_fs4_s16(buffer_i16, the_bufsize); + fwrite(buffer_i16, sizeof(short)*2, the_bufsize, stdout); + TRY_YIELD; + } + } + + if(!strcmp(argv[1],"gen_pos_neg_fs2_s16")) + { + if(!sendbufsize(initialize_buffers())) return -2; + for(;;) + { + FEOF_CHECK; + generate_pos_neg_fs2_s16(buffer_i16, the_bufsize); + fwrite(buffer_i16, sizeof(short)*2, the_bufsize, stdout); + TRY_YIELD; + } + } + if(!strcmp(argv[1],"gen_dc_pos_neg_fs2_s16")) + { + if(!sendbufsize(initialize_buffers())) return -2; + for(;;) + { + FEOF_CHECK; + generate_dc_pos_neg_fs2_s16(buffer_i16, the_bufsize); + fwrite(buffer_i16, sizeof(short)*2, the_bufsize, stdout); + TRY_YIELD; + } + } if(!strcmp(argv[1],"realpart_cf")) { diff --git a/libcsdr.c b/libcsdr.c index 08ec3370..0564992e 100755 --- a/libcsdr.c +++ b/libcsdr.c @@ -2541,6 +2541,149 @@ void generate_neg_fs4_s16(short* output, int size) } } +/****************************************************/ + +void generate_dc_pos_fs4_s16(short* output, int size) +{ + const int m = SHRT_MAX / 2; + /* size must be multiple of 4 */ + assert(!(size&3)); + for(int i=0;i<2*size;) + { + /* exp(i*0) = 1+1+i*0 */ + output[i++]=m+m; + output[i++]=0; + /* exp(i* +pi/2) = 1+0+i*1 */ + output[i++]=m+0; + output[i++]=m; + /* exp(i* +pi) = 1-1+i*0 */ + output[i++]=m-m; + output[i++]=0; + /* exp(i* -pi/2) = 1+0+i*-1 */ + output[i++]=m; + output[i++]=-m; + } +} + +void generate_dc_neg_fs4_s16(short* output, int size) +{ + const int m = SHRT_MAX / 2; + /* size must be multiple of 4 */ + assert(!(size&3)); + for(int i=0;i<2*size;) + { + /* exp(i*0) = 1+1+i*0 */ + output[i++]=m+m; + output[i++]=0; + /* exp(i* -pi/2) = 1+0+i*-1 */ + output[i++]=m+0; + output[i++]=-m; + /* exp(i* +pi) = 1-1+i*0 */ + output[i++]=m-m; + output[i++]=0; + /* exp(i* +pi/2) = 1+0+i*1 */ + output[i++]=m+0; + output[i++]=m; + } +} + +void generate_pos_neg_fs4_s16(short* output, int size) +{ + const int m = SHRT_MAX / 2; + /* size must be multiple of 4 */ + assert(!(size&3)); + for(int i=0;i<2*size;) + { + /* pos(0) + neg(0) = exp(i* 0 ) + exp(i* 0 ) = 1 +i* 0 + 1 +i* 0 */ + output[i++]=m; + output[i++]=-m; + + /* pos(1) + neg(1) = exp(i* +pi/2) + exp(i* -pi/2) = 0 +i* 1 + 0 +i* -1 */ + output[i++]=-m; + output[i++]=m; + + /* pos(2) + neg(2) = exp(i* +pi ) + exp(i* +pi ) = -1 +i* 0 + -1 +i* 0 */ + output[i++]=-m; + output[i++]=m; + + /* pos(3) + neg(3) = exp(i* -pi/2) + exp(i* +pi/2) = 0 +i* -1 + 0 +i* 1 */ + output[i++]=m; + output[i++]=-m; + } +} + +void generate_dc_pos_neg_fs4_s16(short* output, int size) +{ + const int m = SHRT_MAX / 2; + /* size must be multiple of 4 */ + assert(!(size&3)); + for(int i=0;i<2*size;) + { + /* dc + pos(0) + neg(0) = dc + exp(i* 0 ) + exp(i* 0 ) = 1 +i* 0 + 1 +i* 0 */ + output[i++]=m+m; + output[i++]=-m; + + /* dc + pos(1) + neg(1) = dc + exp(i* +pi/2) + exp(i* -pi/2) = 0 +i* 1 + 0 +i* -1 */ + output[i++]=0; + output[i++]=m; + + /* dc + pos(2) + neg(2) = dc + exp(i* +pi ) + exp(i* +pi ) = -1 +i* 0 + -1 +i* 0 */ + output[i++]=0; + output[i++]=m; + + /* dc + pos(3) + neg(3) = dc + exp(i* -pi/2) + exp(i* +pi/2) = 0 +i* -1 + 0 +i* 1 */ + output[i++]=m+m; + output[i++]=-m; + } +} + + +void generate_pos_neg_fs2_s16(short* output, int size) +{ + const int m = SHRT_MAX / 2; + /* size must be multiple of 4 */ + assert(!(size&3)); + for(int i=0;i<2*size;) + { + /* dc + exp(i* 0 ) = +1 */ + output[i++]=m; + output[i++]=0; + /* dc + exp(i* pi) = -1 */ + output[i++]=-m; + output[i++]=0; + /* dc + exp(i* 0 ) = +1 */ + output[i++]=m; + output[i++]=0; + /* dc + exp(i* pi) = -1 */ + output[i++]=-m; + output[i++]=0; + } +} + +void generate_dc_pos_neg_fs2_s16(short* output, int size) +{ + const int m = SHRT_MAX / 2; + /* size must be multiple of 4 */ + assert(!(size&3)); + for(int i=0;i<2*size;) + { + /* with dc = i*1 */ + /* dc + exp(i* 0 ) = i*1 +1 */ + output[i++]=m; + output[i++]=m; + /* dc + exp(i* pi) = i*1 -1 */ + output[i++]=-m; + output[i++]=m; + /* dc + exp(i* 0 ) = i*1 +1 */ + output[i++]=m; + output[i++]=m; + /* dc + exp(i* pi) = i*1 -1 */ + output[i++]=-m; + output[i++]=m; + } +} + + FILE* init_get_random_samples_f() { diff --git a/libcsdr.h b/libcsdr.h index f8b5ac5c..2802b692 100644 --- a/libcsdr.h +++ b/libcsdr.h @@ -237,6 +237,14 @@ void generate_pos_fs4_s16(short* output, int size); void generate_neg_fs4_f(float* output, int size); void generate_neg_fs4_s16(short* output, int size); +void generate_dc_pos_fs4_s16(short* output, int size); +void generate_dc_neg_fs4_s16(short* output, int size); +void generate_pos_neg_fs4_s16(short* output, int size); +void generate_dc_pos_neg_fs4_s16(short* output, int size); + +void generate_pos_neg_fs2_s16(short* output, int size); +void generate_dc_pos_neg_fs2_s16(short* output, int size); + int is_nan(float f);