firdes_carrier_c to firdes_add_carrier_c

This commit is contained in:
ha7ilm 2017-04-08 16:36:10 +02:00
parent cdc2996dcc
commit 874d6b7c06
3 changed files with 16 additions and 10 deletions

4
csdr.c
View file

@ -2721,10 +2721,10 @@ int main(int argc, char *argv[])
int octave=(argc>=6 && !strcmp("--octave",argv[5]));
complexf* taps=(complexf*)malloc(sizeof(complexf)*length);
complexf* taps=(complexf*)calloc(sizeof(complexf),length);
//Make the filter
firdes_carrier_c(taps, length, rate, window);
firdes_add_carrier_c(taps, length, rate, window);
//Do the output
if(octave) printf("taps=[");

View file

@ -2009,17 +2009,18 @@ void simple_agc_cc(complexf* input, complexf* output, int input_size, float rate
}
}
void firdes_carrier_c(complexf* output, int length, float rate, window_t window)
void firdes_add_carrier_c(complexf* output, int length, float rate, window_t window)
{
complexf* taps = (complexf*)malloc(sizeof(complexf)*length);
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<length; i++) //@@firdes_carrier_c: calculate taps
{
e_powj(&output[i], phase);
e_powj(&taps[i], phase);
float window_multiplier = window_function(fabs((float)(middle-i)/middle));
output[i].i *= window_multiplier;
output[i].q *= window_multiplier;
taps[i].i *= window_multiplier;
taps[i].q *= window_multiplier;
phase += phase_addition;
while(phase>2*M_PI) phase-=2*M_PI;
}
@ -2028,12 +2029,17 @@ void firdes_carrier_c(complexf* output, int length, float rate, window_t window)
float sum=0;
for(int i=0;i<length;i++) //@firdes_carrier_c: normalize pass 1
{
sum+=sqrt(output[i].i*output[i].i + output[i].q*output[i].q);
sum+=sqrt(taps[i].i*taps[i].i + taps[i].q*taps[i].q);
}
for(int i=0;i<length;i++) //@firdes_carrier_c: normalize pass 2
{
output[i].i/=sum;
output[i].q/=sum;
taps[i].i/=sum;
taps[i].q/=sum;
}
for(int i=0;i<length;i++)
{
output[i].i += taps[i].i;
output[i].q += taps[i].q;
}
}

View file

@ -338,4 +338,4 @@ typedef struct bpsk_costas_loop_state_s
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 simple_agc_cc(complexf* input, complexf* output, int input_size, float rate, float reference, float max_gain, float* current_gain);
void firdes_carrier_c(complexf* output, int length, float rate, window_t window);
void firdes_add_carrier_c(complexf* output, int length, float rate, window_t window);