Added simple_agc_cc
This commit is contained in:
parent
e7f9be41c2
commit
fc350d594c
3 changed files with 53 additions and 1 deletions
33
csdr.c
33
csdr.c
|
@ -135,6 +135,7 @@ char usage[]=
|
||||||
" duplicate_samples_ntimes_u8_u8 <sample_size_bytes> <ntimes>\n"
|
" duplicate_samples_ntimes_u8_u8 <sample_size_bytes> <ntimes>\n"
|
||||||
" bpsk_costas_loop_cc <samples_per_bits>\n"
|
" bpsk_costas_loop_cc <samples_per_bits>\n"
|
||||||
" binary_slicer_f_u8\n"
|
" binary_slicer_f_u8\n"
|
||||||
|
" simple_agc_cc <rate> [reference [max_gain]]\n"
|
||||||
" ?<search_the_function_list>\n"
|
" ?<search_the_function_list>\n"
|
||||||
" =<evaluate_python_expression>\n"
|
" =<evaluate_python_expression>\n"
|
||||||
" \n"
|
" \n"
|
||||||
|
@ -2652,7 +2653,7 @@ int main(int argc, char *argv[])
|
||||||
float samples_per_bits;
|
float samples_per_bits;
|
||||||
if(argc<=2) return badsyntax("need required parameter (samples_per_bits)");
|
if(argc<=2) return badsyntax("need required parameter (samples_per_bits)");
|
||||||
sscanf(argv[2],"%f",&samples_per_bits);
|
sscanf(argv[2],"%f",&samples_per_bits);
|
||||||
if(samples_per_bits<=0) badsyntax("samples_per_bits should be >= 0");
|
if(samples_per_bits<=0) badsyntax("samples_per_bits should be > 0");
|
||||||
|
|
||||||
bpsk_costas_loop_state_t state = init_bpsk_costas_loop_cc(samples_per_bits);
|
bpsk_costas_loop_state_t state = init_bpsk_costas_loop_cc(samples_per_bits);
|
||||||
|
|
||||||
|
@ -2669,6 +2670,36 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!strcmp(argv[1],"simple_agc_cc")) //<rate> [reference [max_gain]]
|
||||||
|
{
|
||||||
|
float rate;
|
||||||
|
if(argc<=2) return badsyntax("need required parameter (rate)");
|
||||||
|
sscanf(argv[2],"%f",&rate);
|
||||||
|
if(rate<=0) badsyntax("rate should be > 0");
|
||||||
|
|
||||||
|
float reference = 1.;
|
||||||
|
if(argc>3) sscanf(argv[3],"%f",&reference);
|
||||||
|
if(reference<=0) badsyntax("reference should be > 0");
|
||||||
|
|
||||||
|
float max_gain = 65535.;
|
||||||
|
if(argc>4) sscanf(argv[4],"%f",&max_gain);
|
||||||
|
if(max_gain<=0) badsyntax("max_gain should be > 0");
|
||||||
|
|
||||||
|
float current_gain = 1.;
|
||||||
|
|
||||||
|
if(!initialize_buffers()) return -2;
|
||||||
|
sendbufsize(the_bufsize);
|
||||||
|
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
FEOF_CHECK;
|
||||||
|
FREAD_C;
|
||||||
|
simple_agc_cc((complexf*)input_buffer, (complexf*)output_buffer, the_bufsize, rate, reference, max_gain, ¤t_gain);
|
||||||
|
FWRITE_C;
|
||||||
|
TRY_YIELD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!strcmp(argv[1],"none"))
|
if(!strcmp(argv[1],"none"))
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
20
libcsdr.c
20
libcsdr.c
|
@ -1990,6 +1990,26 @@ void bpsk_costas_loop_cc(complexf* input, complexf* output, int input_size, bpsk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void simple_agc_cc(complexf* input, complexf* output, int input_size, float rate, float reference, float max_gain, float* current_gain)
|
||||||
|
{
|
||||||
|
float rate_1minus=1-rate;
|
||||||
|
int debugn = 0;
|
||||||
|
for(int i=0;i<input_size;i++)
|
||||||
|
{
|
||||||
|
float amplitude = sqrt(input[i].i*input[i].i+input[i].q*input[i].q);
|
||||||
|
float ideal_gain = (reference/amplitude);
|
||||||
|
if(ideal_gain>max_gain) ideal_gain = max_gain;
|
||||||
|
if(ideal_gain<=0) ideal_gain = 0;
|
||||||
|
//*current_gain += (ideal_gain-(*current_gain))*rate;
|
||||||
|
*current_gain = (ideal_gain-(*current_gain))*rate + (*current_gain)*rate_1minus;
|
||||||
|
if(debugn<100) fprintf(stderr, "cgain: %g\n", *current_gain), debugn++;
|
||||||
|
output[i].i=(*current_gain)*input[i].i;
|
||||||
|
output[i].q=(*current_gain)*input[i].q;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
_____ _ _
|
_____ _ _
|
||||||
|
|
|
@ -337,3 +337,4 @@ typedef struct bpsk_costas_loop_state_s
|
||||||
|
|
||||||
bpsk_costas_loop_state_t init_bpsk_costas_loop_cc(float samples_per_bits);
|
bpsk_costas_loop_state_t init_bpsk_costas_loop_cc(float samples_per_bits);
|
||||||
void bpsk_costas_loop_cc(complexf* input, complexf* output, int input_size, bpsk_costas_loop_state_t* state);
|
void bpsk_costas_loop_cc(complexf* input, complexf* output, int input_size, bpsk_costas_loop_state_t* state);
|
||||||
|
void simple_agc_cc(complexf* input, complexf* output, int input_size, float rate, float reference, float max_gain, float* current_gain);
|
||||||
|
|
Loading…
Reference in a new issue