diff --git a/gr-hamnet70/lib/correct_frequency_from_pilot_syms_impl.cc b/gr-hamnet70/lib/correct_frequency_from_pilot_syms_impl.cc
index 1fe3bdc..7fce134 100644
--- a/gr-hamnet70/lib/correct_frequency_from_pilot_syms_impl.cc
+++ b/gr-hamnet70/lib/correct_frequency_from_pilot_syms_impl.cc
@@ -126,7 +126,11 @@ namespace gr {
size_t last_off = d_phase_ref_offset;
float last_phase = 0.0f;
- for(size_t off: d_offsets) {
+ // method 1: average over the complex vectors of the de-rotated pilot
+ // symbols in each block, then calculate the phase and average the
+ // phases change from one block to the next
+
+ /*for(size_t off: d_offsets) {
gr_complex sum(0, 0);
size_t n = 0;
@@ -138,12 +142,33 @@ namespace gr {
sum /= n;
float phase = gr::fast_atan2f(sum); // FIXME? unwrap
- phase_sum += (phase - last_phase) / (off - last_off);
+ phase_sum += (phase - last_phase) / (off - last_off + d_pilot_sequence.size()/2);
last_phase = phase;
last_off = off;
}
- d_phase_inc_per_symbol = -phase_sum / d_offsets.size();
+ d_phase_inc_per_symbol = -phase_sum / d_offsets.size();*/
+
+ // method 2: calculate the frequency offset for each pilot symbol in
+ // each block with respect to the reference position. Then average
+ // over all frequency offsets.
+
+ float phase_inc_per_symbol_sum = 0.0f;
+
+ for(size_t off: d_offsets) {
+
+ size_t n = 0;
+ for(const gr_complex &ref_sym: d_pilot_sequence) {
+ gr_complex derot_symbol = d_packet[off+n] * conj(ref_sym);
+ float phase = gr::fast_atan2f(derot_symbol);
+
+ phase_inc_per_symbol_sum += phase / (off + n - d_phase_ref_offset);
+ n++;
+ }
+ }
+
+ d_phase_inc_per_symbol = -phase_inc_per_symbol_sum / (d_pilot_sequence.size() * d_offsets.size());
+
d_current_phase = (-(int)d_phase_ref_offset - 1) * d_phase_inc_per_symbol;
//std::cout << "initial phase: " << d_current_phase << std::endl;
diff --git a/grc/hamnet70_demod_sc16qam.grc b/grc/hamnet70_demod_sc16qam.grc
index fad5d65..9b45890 100644
--- a/grc/hamnet70_demod_sc16qam.grc
+++ b/grc/hamnet70_demod_sc16qam.grc
@@ -351,6 +351,60 @@
[0, 1, 3, 2]
+
+ variable
+
+ comment
+
+
+
+ _enabled
+ 1
+
+
+ _coordinate
+ (1525, 75)
+
+
+ _rotation
+ 0
+
+
+ id
+ pilot_offset
+
+
+ value
+ 256
+
+
+
+ variable
+
+ comment
+
+
+
+ _enabled
+ 1
+
+
+ _coordinate
+ (1525, 11)
+
+
+ _rotation
+ 0
+
+
+ id
+ pilot_sequence
+
+
+ value
+ [1.+1.j, 1.+1.j, -1.+1.j, 1.+1.j, -1.+1.j, 1.+1.j, 1.-1.j, -1.+1.j, 1.+1.j, 1.-1.j, 1.-1.j, 1.+1.j, -1.+1.j, 1.-1.j, 1.+1.j, -1.-1.j]
+
+
variable
@@ -1928,7 +1982,7 @@
offsets
- [len(preamble)+128, len(preamble)+256+4]
+ [len(preamble)+pilot_offset]
maxoutbuf
@@ -1944,7 +1998,7 @@
pilot_sequence
- [1+1j, -1-1j, 1-1j, -1+1j]
+ pilot_sequence
start_tag
@@ -2112,7 +2166,7 @@
_enabled
- True
+ 0
_coordinate
diff --git a/grc/hamnet70_mod_sc16qam.grc b/grc/hamnet70_mod_sc16qam.grc
index c399346..a067527 100644
--- a/grc/hamnet70_mod_sc16qam.grc
+++ b/grc/hamnet70_mod_sc16qam.grc
@@ -316,6 +316,60 @@
[0, 1, 3, 2]
+
+ variable
+
+ comment
+
+
+
+ _enabled
+ 1
+
+
+ _coordinate
+ (1333, 75)
+
+
+ _rotation
+ 0
+
+
+ id
+ pilot_offset
+
+
+ value
+ 256
+
+
+
+ variable
+
+ comment
+
+
+
+ _enabled
+ 1
+
+
+ _coordinate
+ (1333, 11)
+
+
+ _rotation
+ 0
+
+
+ id
+ pilot_sequence
+
+
+ value
+ [1.+1.j, 1.+1.j, -1.+1.j, 1.+1.j, -1.+1.j, 1.+1.j, 1.-1.j, -1.+1.j, 1.+1.j, 1.-1.j, 1.-1.j, 1.+1.j, -1.+1.j, 1.-1.j, 1.+1.j, -1.-1.j]
+
+
variable
@@ -1148,7 +1202,7 @@
offsets
- [len(preamble)+128, len(preamble)+256]
+ [len(preamble)+pilot_offset]
length_tag
@@ -1164,7 +1218,7 @@
pilot_sequence
- [1+1j, -1-1j, 1-1j, -1+1j]
+ pilot_sequence
diff --git a/tmp/test_sc16qam.grc b/tmp/test_sc16qam.grc
index 236b168..4021336 100644
--- a/tmp/test_sc16qam.grc
+++ b/tmp/test_sc16qam.grc
@@ -794,6 +794,353 @@
import numpy as np
+
+ qtgui_const_sink_x
+
+ autoscale
+ False
+
+
+ axislabels
+ True
+
+
+ alias
+
+
+
+ comment
+
+
+
+ affinity
+
+
+
+ _enabled
+ True
+
+
+ _coordinate
+ (726, 403)
+
+
+ gui_hint
+
+
+
+ _rotation
+ 0
+
+
+ grid
+ False
+
+
+ id
+ qtgui_const_sink_x_0
+
+
+ legend
+ True
+
+
+ alpha1
+ 1.0
+
+
+ color1
+ "blue"
+
+
+ label1
+
+
+
+ marker1
+ 0
+
+
+ style1
+ 0
+
+
+ width1
+ 1
+
+
+ alpha10
+ 1.0
+
+
+ color10
+ "red"
+
+
+ label10
+
+
+
+ marker10
+ 0
+
+
+ style10
+ 0
+
+
+ width10
+ 1
+
+
+ alpha2
+ 1.0
+
+
+ color2
+ "red"
+
+
+ label2
+
+
+
+ marker2
+ 0
+
+
+ style2
+ 0
+
+
+ width2
+ 1
+
+
+ alpha3
+ 1.0
+
+
+ color3
+ "red"
+
+
+ label3
+
+
+
+ marker3
+ 0
+
+
+ style3
+ 0
+
+
+ width3
+ 1
+
+
+ alpha4
+ 1.0
+
+
+ color4
+ "red"
+
+
+ label4
+
+
+
+ marker4
+ 0
+
+
+ style4
+ 0
+
+
+ width4
+ 1
+
+
+ alpha5
+ 1.0
+
+
+ color5
+ "red"
+
+
+ label5
+
+
+
+ marker5
+ 0
+
+
+ style5
+ 0
+
+
+ width5
+ 1
+
+
+ alpha6
+ 1.0
+
+
+ color6
+ "red"
+
+
+ label6
+
+
+
+ marker6
+ 0
+
+
+ style6
+ 0
+
+
+ width6
+ 1
+
+
+ alpha7
+ 1.0
+
+
+ color7
+ "red"
+
+
+ label7
+
+
+
+ marker7
+ 0
+
+
+ style7
+ 0
+
+
+ width7
+ 1
+
+
+ alpha8
+ 1.0
+
+
+ color8
+ "red"
+
+
+ label8
+
+
+
+ marker8
+ 0
+
+
+ style8
+ 0
+
+
+ width8
+ 1
+
+
+ alpha9
+ 1.0
+
+
+ color9
+ "red"
+
+
+ label9
+
+
+
+ marker9
+ 0
+
+
+ style9
+ 0
+
+
+ width9
+ 1
+
+
+ name
+ "Synced symbols"
+
+
+ nconnections
+ 1
+
+
+ size
+ 2048
+
+
+ tr_chan
+ 0
+
+
+ tr_level
+ 0.0
+
+
+ tr_mode
+ qtgui.TRIG_MODE_TAG
+
+
+ tr_slope
+ qtgui.TRIG_SLOPE_POS
+
+
+ tr_tag
+ "corr_est"
+
+
+ type
+ complex
+
+
+ update_time
+ 0.5
+
+
+ xmax
+ 2
+
+
+ xmin
+ -2
+
+
+ ymax
+ 2
+
+
+ ymin
+ -2
+
+
qtgui_number_sink
@@ -1383,7 +1730,7 @@
_enabled
- 1
+ 0
fftsize
@@ -2254,6 +2601,12 @@
pdu_out
print_pdu
+
+ hamnet70_demod_sc16qam_0
+ qtgui_const_sink_x_0
+ 1
+ 0
+
hamnet70_demod_sc16qam_0
qtgui_sink_x_1