diff --git a/grc_tests/test_bpsk_costas_loop.grc b/grc_tests/test_bpsk_costas_loop.grc
index 7ce3934..82ac291 100644
--- a/grc_tests/test_bpsk_costas_loop.grc
+++ b/grc_tests/test_bpsk_costas_loop.grc
@@ -69,6 +69,65 @@
+
+ variable_slider
+
+ comment
+
+
+
+ converver
+ float_converter
+
+
+ value
+ 1
+
+
+ _enabled
+ True
+
+
+ _coordinate
+ (480, 3)
+
+
+ _rotation
+ 0
+
+
+ grid_pos
+
+
+
+ id
+ amplitude
+
+
+ label
+
+
+
+ max
+ 2
+
+
+ min
+ 0
+
+
+ notebook
+
+
+
+ num_steps
+ 100
+
+
+ style
+ wx.SL_HORIZONTAL
+
+
variable_slider
@@ -109,11 +168,11 @@
max
- samp_rate*0.01
+ samp_rate*0.5
min
- -samp_rate*0.01
+ -samp_rate*0.5
notebook
@@ -128,6 +187,65 @@
wx.SL_HORIZONTAL
+
+ variable_slider
+
+ comment
+
+
+
+ converver
+ float_converter
+
+
+ value
+ 0.3
+
+
+ _enabled
+ True
+
+
+ _coordinate
+ (712, 571)
+
+
+ _rotation
+ 0
+
+
+ grid_pos
+
+
+
+ id
+ loop_bw
+
+
+ label
+
+
+
+ max
+ 0.5
+
+
+ min
+ 0
+
+
+ notebook
+ nb, 1
+
+
+ num_steps
+ 100
+
+
+ style
+ wx.SL_HORIZONTAL
+
+
variable
@@ -312,6 +430,57 @@
1
+
+ blocks_multiply_const_vxx
+
+ alias
+
+
+
+ comment
+
+
+
+ const
+ amplitude
+
+
+ affinity
+
+
+
+ _enabled
+ True
+
+
+ _coordinate
+ (496, 155)
+
+
+ _rotation
+ 0
+
+
+ id
+ blocks_multiply_const_vxx_0
+
+
+ type
+ complex
+
+
+ maxoutbuf
+ 0
+
+
+ minoutbuf
+ 0
+
+
+ vlen
+ 1
+
+
blocks_throttle
@@ -332,7 +501,7 @@
_coordinate
- (456, 211)
+ (488, 211)
_rotation
@@ -367,6 +536,57 @@
1
+
+ digital_costas_loop_cc
+
+ alias
+
+
+
+ comment
+
+
+
+ affinity
+
+
+
+ _enabled
+ True
+
+
+ _coordinate
+ (928, 537)
+
+
+ _rotation
+ 0
+
+
+ id
+ digital_costas_loop_cc_0
+
+
+ w
+ loop_bw
+
+
+ maxoutbuf
+ 0
+
+
+ minoutbuf
+ 0
+
+
+ order
+ 2
+
+
+ use_snr
+ False
+
+
digital_psk_mod
@@ -599,7 +819,7 @@
_coordinate
- (432, 411)
+ (400, 411)
_rotation
@@ -622,6 +842,49 @@
cc
+
+ notebook
+
+ alias
+
+
+
+ comment
+
+
+
+ _enabled
+ True
+
+
+ _coordinate
+ (16, 83)
+
+
+ _rotation
+ 0
+
+
+ grid_pos
+
+
+
+ id
+ nb
+
+
+ labels
+ ['1', '2']
+
+
+ notebook
+
+
+
+ style
+ wx.NB_TOP
+
+
wxgui_fftsink2
@@ -749,7 +1012,7 @@
_coordinate
- (824, 507)
+ (632, 379)
_rotation
@@ -852,8 +1115,95 @@
notebook
+ nb, 0
+
+
+ num_inputs
+ 1
+
+
+ samp_rate
+ (samp_rate/256)*8
+
+
+ t_scale
+ 0
+
+
+ title
+ After Costas Loop
+
+
+ trig_mode
+ wxgui.TRIG_MODE_AUTO
+
+
+ type
+ complex
+
+
+ v_offset
+ 0
+
+
+ v_scale
+ 0
+
+
+ win_size
+
+ xy_mode
+ True
+
+
+ y_axis_label
+ Counts
+
+
+
+ wxgui_scopesink2
+
+ ac_couple
+ False
+
+
+ alias
+
+
+
+ comment
+
+
+
+ affinity
+
+
+
+ _enabled
+ 1
+
+
+ _coordinate
+ (1112, 491)
+
+
+ _rotation
+ 0
+
+
+ grid_pos
+
+
+
+ id
+ wxgui_scopesink2_0_0_0
+
+
+ notebook
+ nb, 1
+
num_inputs
1
@@ -1010,15 +1360,27 @@
0
0
+
+ blocks_multiply_const_vxx_0
+ blocks_throttle_0
+ 0
+ 0
+
blocks_throttle_0
freq_xlating_fir_filter_xxx_0
0
0
+
+ digital_costas_loop_cc_0
+ wxgui_scopesink2_0_0_0
+ 0
+ 0
+
digital_psk_mod_0
- blocks_throttle_0
+ blocks_multiply_const_vxx_0
0
0
@@ -1028,6 +1390,12 @@
0
0
+
+ freq_xlating_fir_filter_xxx_0
+ digital_costas_loop_cc_0
+ 0
+ 0
+
freq_xlating_fir_filter_xxx_0
ha5kfu_execproc_xx_0
diff --git a/libcsdr.c b/libcsdr.c
index 4aeecf1..cbfddd7 100644
--- a/libcsdr.c
+++ b/libcsdr.c
@@ -1942,7 +1942,8 @@ bpsk_costas_loop_state_t init_bpsk_costas_loop_cc(float samples_per_bits)
float virtual_sampling_rate = 10000;
float virtual_data_rate = virtual_sampling_rate / samples_per_bits;
fprintf(stderr, "virtual_sampling_rate = %g, virtual_data_rate = %g\n", virtual_sampling_rate, virtual_data_rate);
- float rc_filter_cutoff = virtual_data_rate/2;
+ //float rc_filter_cutoff = virtual_data_rate * 2; //this is so far the best
+ float rc_filter_cutoff = virtual_data_rate * 2;
float rc_filter_rc = 1/(2*M_PI*rc_filter_cutoff); //as of Equation 24 in Feigin
float virtual_sampling_dt = 1.0/virtual_sampling_rate;
fprintf(stderr, "rc_filter_cutoff = %g, rc_filter_rc = %g, virtual_sampling_dt = %g\n",
@@ -1966,18 +1967,24 @@ void bpsk_costas_loop_cc(complexf* input, complexf* output, int input_size, bpsk
if(debug) fprintf(stderr, "%g | %g\n", input_and_vco_mixed_phase, input_phase), debug--;
complexf input_and_vco_mixed_sample;
e_powj(&input_and_vco_mixed_sample, input_and_vco_mixed_phase);
+
+ complexf vco_sample;
+ e_powj(&vco_sample, -state->vco_phase);
+ //cmult(&input_and_vco_mixed_sample, &input[i], &vco_sample);//if this is enabled, the real input sample is used, not the amplitude normalized
+
float loop_output_i =
input_and_vco_mixed_sample.i * state->rc_filter_alpha + state->last_lpfi_output * (1-state->rc_filter_alpha);
float loop_output_q =
input_and_vco_mixed_sample.q * state->rc_filter_alpha + state->last_lpfq_output * (1-state->rc_filter_alpha);
+ //loop_output_i = input_and_vco_mixed_sample.i;
+ //loop_output_q = input_and_vco_mixed_sample.q;
state->last_lpfi_output = loop_output_i;
state->last_lpfq_output = loop_output_q;
float vco_phase_addition = loop_output_i * loop_output_q * state->vco_phase_addition_multiplier;
state->vco_phase += vco_phase_addition;
while(state->vco_phase>PI) state->vco_phase-=2*PI;
while(state->vco_phase<-PI) state->vco_phase+=2*PI;
- output[i].i = loop_output_i;
- output[i].q = loop_output_q;
+ cmult(&output[i], &input[i], &vco_sample);
}
}