From 2628e9cddc43d57a3346e240c8f7e58722bc61f1 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sun, 20 Sep 2009 12:47:34 -0700 Subject: [PATCH] Add HRPT word output to deframer Put in half bit width matched filter Change default sync_alpha to 0.05 --- gr-noaa/apps/usrp_rx_hrpt.grc | 545 ++++++++++------------------- gr-noaa/apps/usrp_rx_hrpt.py | 46 +-- gr-noaa/grc/noaa_hrpt_deframer.xml | 4 + gr-noaa/lib/noaa_hrpt_deframer.cc | 61 +++- gr-noaa/lib/noaa_hrpt_deframer.h | 21 +- 5 files changed, 270 insertions(+), 407 deletions(-) diff --git a/gr-noaa/apps/usrp_rx_hrpt.grc b/gr-noaa/apps/usrp_rx_hrpt.grc index 71584674..c8e09961 100644 --- a/gr-noaa/apps/usrp_rx_hrpt.grc +++ b/gr-noaa/apps/usrp_rx_hrpt.grc @@ -1,6 +1,6 @@ - Tue Sep 8 21:03:12 2009 + Sun Sep 20 12:45:30 2009 options @@ -75,37 +75,6 @@ 0 - - gr_throttle - - id - throttle - - - _enabled - True - - - type - complex - - - samples_per_second - sample_rate - - - vlen - 1 - - - _coordinate - (79, 518) - - - _rotation - 0 - - variable @@ -276,61 +245,6 @@ 0 - - variable_slider - - id - sync_alpha - - - _enabled - True - - - label - SYNC Alpha - - - value - 0.001 - - - min - 0.0 - - - max - 0.5 - - - num_steps - 500 - - - style - wx.SL_HORIZONTAL - - - converver - float_converter - - - grid_pos - 0, 1, 1, 1 - - - notebook - - - - _coordinate - (344, 101) - - - _rotation - 0 - - variable @@ -378,38 +292,34 @@ - gr_agc_xx + notebook id - agr + displays _enabled True - type - complex - - - rate - 1e-6 + style + wx.NB_TOP - reference - 1.0 + labels + ['RX','PLL/SYNC'] - gain - 1.0 + grid_pos + 1, 0, 1, 2 - max_gain - 1.0 + notebook + _coordinate - (261, 494) + (9, 99) _rotation @@ -417,22 +327,18 @@ - virtual_source + noaa_hrpt_deframer id - virtual_source_0 + noaa_hrpt_deframer_0 _enabled True - - stream_id - bits - _coordinate - (283, 919) + (1112, 649) _rotation @@ -440,88 +346,89 @@ - notebook + wxgui_scopesink2 id - displays + wxgui_scopesink2_0_0 _enabled True - style - wx.NB_TOP - - - labels - ['RX','PLL/SYNC'] + type + float - grid_pos - 1, 0, 1, 2 + title + Post-PLL - notebook - + samp_rate + sample_rate - _coordinate - (9, 99) + v_scale + 0.5 - _rotation - 0 + t_scale + 20.0/sample_rate - - - noaa_hrpt_pll_cf - id - noaa_hrpt_pll_cf_0 + ac_couple + False - _enabled - True + xy_mode + False - alpha - pll_alpha + num_inputs + 1 - beta - pll_alpha**2/4.0 + grid_pos + 0, 0, 1, 1 - max_offset - max_carrier_offset + notebook + displays, 1 _coordinate - (639, 502) + (624, 462) _rotation - 0 + 180 - virtual_sink + gr_throttle id - virtual_sink_1 + throttle _enabled True - stream_id - bits + type + complex + + + samples_per_second + sample_rate + + + vlen + 1 _coordinate - (1126, 518) + (85, 645) _rotation @@ -529,81 +436,82 @@ - gr_char_to_float + wxgui_fftsink2 id - gr_char_to_float_0 + rx_fftsink _enabled True - _coordinate - (477, 923) + type + complex - _rotation - 0 + title + RX Spectrum - - - wxgui_scopesink2 - id - wxgui_scopesink2_0_0_0_0 + samp_rate + sample_rate - _enabled - True + baseband_freq + 1698e6 - type - float + y_per_div + 5 - title - Post-SYNC + y_divs + 8 - samp_rate - sym_rate + ref_level + -5 - v_scale - 0.5 + ref_scale + 2.0 - t_scale - 20.0/sym_rate + fft_size + 1024 - ac_couple - False + fft_rate + 30 - xy_mode + peak_hold False - num_inputs - 1 + average + True + + + avg_alpha + 0.1 grid_pos - 1, 0, 1, 1 + 0, 0, 1, 1 notebook - displays, 1 + displays, 0 _coordinate - (452, 990) + (439, 309) _rotation - 180 + 0 @@ -658,7 +566,7 @@ _coordinate - (433, 570) + (440, 783) _rotation @@ -666,10 +574,10 @@ - wxgui_scopesink2 + gr_agc_xx id - wxgui_scopesink2_0_0 + agr _enabled @@ -677,58 +585,38 @@ type - float - - - title - Post-PLL - - - samp_rate - sample_rate - - - v_scale - 0.5 - - - t_scale - 20.0/sample_rate - - - ac_couple - False + complex - xy_mode - False + rate + 1e-6 - num_inputs - 1 + reference + 1.0 - grid_pos - 0, 0, 1, 1 + gain + 1.0 - notebook - displays, 1 + max_gain + 1.0 _coordinate - (618, 335) + (267, 621) _rotation - 180 + 0 - noaa_hrpt_sync_fb + noaa_hrpt_pll_cf id - noaa_hrpt_sync_fb_0 + noaa_hrpt_pll_cf_0 _enabled @@ -736,42 +624,19 @@ alpha - 0.001 + pll_alpha beta - 0.001**2/4.0 - - - sps - sps + pll_alpha**2/4.0 max_offset - max_sync_offset - - - _coordinate - (856, 494) - - - _rotation - 0 - - - - noaa_hrpt_deframer - - id - noaa_hrpt_deframer_0 - - - _enabled - True + max_carrier_offset _coordinate - (1110, 631) + (645, 629) _rotation @@ -779,10 +644,10 @@ - gr_file_source + gr_file_sink id - src + gr_file_sink_1 _enabled @@ -790,15 +655,11 @@ file - poes-d16.dat + frames.dat type - complex - - - repeat - True + short vlen @@ -806,7 +667,7 @@ _coordinate - (34, 423) + (1125, 758) _rotation @@ -814,49 +675,34 @@ - gr_add_const_vxx + gr_moving_average_xx id - gr_add_const_vxx_0 + matched_filter _enabled - False + True type - float + complex - const - 48.0 + length + hs - vlen - 1 + scale + 1.0/hs - _coordinate - (692, 919) - - - _rotation - 0 - - - - gr_float_to_char - - id - gr_float_to_char_0 - - - _enabled - False + max_iter + 4000 _coordinate - (848, 923) + (444, 629) _rotation @@ -864,22 +710,26 @@ - gr_file_sink + gr_file_source id - gr_file_sink_0 + src _enabled - False + True file - bits.dat + poes-d16.dat type - byte + complex + + + repeat + False vlen @@ -887,7 +737,7 @@ _coordinate - (1020, 919) + (79, 541) _rotation @@ -895,78 +745,89 @@ - wxgui_fftsink2 + noaa_hrpt_sync_fb id - rx_fftsink + noaa_hrpt_sync_fb_0 _enabled True - type - complex + alpha + sync_alpha - title - RX Spectrum + beta + sync_alpha**2/4.0 - samp_rate - sample_rate + sps + sps - baseband_freq - 1698e6 + max_offset + max_sync_offset - y_per_div - 5 + _coordinate + (862, 621) - y_divs - 8 + _rotation + 0 + + + variable_slider - ref_level - -5 + id + sync_alpha - ref_scale - 2.0 + _enabled + True - fft_size - 1024 + label + SYNC Alpha - fft_rate - 30 + value + 0.005 - peak_hold - False + min + 0.0 - average - True + max + 0.5 - avg_alpha - 0.1 + num_steps + 500 + + + style + wx.SL_HORIZONTAL + + + converver + float_converter grid_pos - 0, 0, 1, 1 + 0, 1, 1, 1 notebook - displays, 0 + _coordinate - (434, 269) + (344, 101) _rotation @@ -974,86 +835,62 @@ - src - throttle - 0 - 0 - - - throttle - agr - 0 - 0 - - - agr - rx_fftsink - 0 - 0 - - - agr - wxgui_scopesink2_0 + noaa_hrpt_deframer_0 + gr_file_sink_1 0 0 - agr - noaa_hrpt_pll_cf_0 + noaa_hrpt_sync_fb_0 + noaa_hrpt_deframer_0 0 0 noaa_hrpt_pll_cf_0 - wxgui_scopesink2_0_0 - 0 - 0 - - - virtual_source_0 - gr_char_to_float_0 + noaa_hrpt_sync_fb_0 0 0 noaa_hrpt_pll_cf_0 - noaa_hrpt_sync_fb_0 + wxgui_scopesink2_0_0 0 0 - noaa_hrpt_sync_fb_0 - virtual_sink_1 + agr + wxgui_scopesink2_0 0 0 - gr_char_to_float_0 - wxgui_scopesink2_0_0_0_0 + agr + rx_fftsink 0 0 - gr_char_to_float_0 - gr_add_const_vxx_0 + throttle + agr 0 0 - gr_add_const_vxx_0 - gr_float_to_char_0 + src + throttle 0 0 - gr_float_to_char_0 - gr_file_sink_0 + agr + matched_filter 0 0 - noaa_hrpt_sync_fb_0 - noaa_hrpt_deframer_0 + matched_filter + noaa_hrpt_pll_cf_0 0 0 diff --git a/gr-noaa/apps/usrp_rx_hrpt.py b/gr-noaa/apps/usrp_rx_hrpt.py index 40cc517f..032db315 100755 --- a/gr-noaa/apps/usrp_rx_hrpt.py +++ b/gr-noaa/apps/usrp_rx_hrpt.py @@ -2,7 +2,7 @@ ################################################## # Gnuradio Python Flow Graph # Title: USRP HRPT Receiver -# Generated: Tue Sep 8 21:03:12 2009 +# Generated: Sun Sep 20 12:45:30 2009 ################################################## from gnuradio import eng_notation @@ -30,7 +30,7 @@ class usrp_rx_hrpt(grc_wxgui.top_block_gui): self.sym_rate = sym_rate = 600*1109 self.sample_rate = sample_rate = 64e6/decim self.sps = sps = sample_rate/sym_rate - self.sync_alpha = sync_alpha = 0.001 + self.sync_alpha = sync_alpha = 0.005 self.pll_alpha = pll_alpha = 0.001 self.max_sync_offset = max_sync_offset = 0.01 self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate @@ -98,10 +98,11 @@ class usrp_rx_hrpt(grc_wxgui.top_block_gui): # Blocks ################################################## self.agr = gr.agc_cc(1e-6, 1.0, 1.0, 1.0) - self.gr_char_to_float_0 = gr.char_to_float() + self.gr_file_sink_1 = gr.file_sink(gr.sizeof_short*1, "frames.dat") + self.matched_filter = gr.moving_average_cc(hs, 1.0/hs, 4000) self.noaa_hrpt_deframer_0 = noaa.hrpt_deframer() self.noaa_hrpt_pll_cf_0 = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset) - self.noaa_hrpt_sync_fb_0 = noaa.hrpt_sync_fb(0.001, 0.001**2/4.0, sps, max_sync_offset) + self.noaa_hrpt_sync_fb_0 = noaa.hrpt_sync_fb(sync_alpha, sync_alpha**2/4.0, sps, max_sync_offset) self.rx_fftsink = fftsink2.fft_sink_c( self.displays.GetPage(0).GetWin(), baseband_freq=1698e6, @@ -118,7 +119,7 @@ class usrp_rx_hrpt(grc_wxgui.top_block_gui): peak_hold=False, ) self.displays.GetPage(0).GridAdd(self.rx_fftsink.win, 0, 0, 1, 1) - self.src = gr.file_source(gr.sizeof_gr_complex*1, "poes-d16.dat", True) + self.src = gr.file_source(gr.sizeof_gr_complex*1, "poes-d16.dat", False) self.throttle = gr.throttle(gr.sizeof_gr_complex*1, sample_rate) self.wxgui_scopesink2_0 = scopesink2.scope_sink_c( self.displays.GetPage(0).GetWin(), @@ -142,31 +143,20 @@ class usrp_rx_hrpt(grc_wxgui.top_block_gui): num_inputs=1, ) self.displays.GetPage(1).GridAdd(self.wxgui_scopesink2_0_0.win, 0, 0, 1, 1) - self.wxgui_scopesink2_0_0_0_0 = scopesink2.scope_sink_f( - self.displays.GetPage(1).GetWin(), - title="Post-SYNC", - sample_rate=sym_rate, - v_scale=0.5, - t_scale=20.0/sym_rate, - ac_couple=False, - xy_mode=False, - num_inputs=1, - ) - self.displays.GetPage(1).GridAdd(self.wxgui_scopesink2_0_0_0_0.win, 1, 0, 1, 1) ################################################## # Connections ################################################## - self.connect((self.src, 0), (self.throttle, 0)) - self.connect((self.throttle, 0), (self.agr, 0)) - self.connect((self.agr, 0), (self.rx_fftsink, 0)) - self.connect((self.agr, 0), (self.wxgui_scopesink2_0, 0)) - self.connect((self.agr, 0), (self.noaa_hrpt_pll_cf_0, 0)) - self.connect((self.noaa_hrpt_pll_cf_0, 0), (self.wxgui_scopesink2_0_0, 0)) - self.connect((self.noaa_hrpt_sync_fb_0, 0), (self.gr_char_to_float_0, 0)) - self.connect((self.noaa_hrpt_pll_cf_0, 0), (self.noaa_hrpt_sync_fb_0, 0)) - self.connect((self.gr_char_to_float_0, 0), (self.wxgui_scopesink2_0_0_0_0, 0)) + self.connect((self.noaa_hrpt_deframer_0, 0), (self.gr_file_sink_1, 0)) self.connect((self.noaa_hrpt_sync_fb_0, 0), (self.noaa_hrpt_deframer_0, 0)) + self.connect((self.noaa_hrpt_pll_cf_0, 0), (self.noaa_hrpt_sync_fb_0, 0)) + self.connect((self.noaa_hrpt_pll_cf_0, 0), (self.wxgui_scopesink2_0_0, 0)) + self.connect((self.agr, 0), (self.wxgui_scopesink2_0, 0)) + self.connect((self.agr, 0), (self.rx_fftsink, 0)) + self.connect((self.throttle, 0), (self.agr, 0)) + self.connect((self.src, 0), (self.throttle, 0)) + self.connect((self.agr, 0), (self.matched_filter, 0)) + self.connect((self.matched_filter, 0), (self.noaa_hrpt_pll_cf_0, 0)) def set_decim(self, decim): self.decim = decim @@ -175,15 +165,14 @@ class usrp_rx_hrpt(grc_wxgui.top_block_gui): def set_sym_rate(self, sym_rate): self.sym_rate = sym_rate self.set_sps(self.sample_rate/self.sym_rate) - self.wxgui_scopesink2_0_0_0_0.set_sample_rate(self.sym_rate) def set_sample_rate(self, sample_rate): self.sample_rate = sample_rate self.set_sps(self.sample_rate/self.sym_rate) self.set_max_carrier_offset(2*math.pi*100e3/self.sample_rate) - self.wxgui_scopesink2_0.set_sample_rate(self.sample_rate) self.wxgui_scopesink2_0_0.set_sample_rate(self.sample_rate) self.rx_fftsink.set_sample_rate(self.sample_rate) + self.wxgui_scopesink2_0.set_sample_rate(self.sample_rate) def set_sps(self, sps): self.sps = sps @@ -191,6 +180,8 @@ class usrp_rx_hrpt(grc_wxgui.top_block_gui): def set_sync_alpha(self, sync_alpha): self.sync_alpha = sync_alpha + self.noaa_hrpt_sync_fb_0.set_alpha(self.sync_alpha) + self.noaa_hrpt_sync_fb_0.set_beta(self.sync_alpha**2/4.0) self._sync_alpha_slider.set_value(self.sync_alpha) self._sync_alpha_text_box.set_value(self.sync_alpha) @@ -211,6 +202,7 @@ class usrp_rx_hrpt(grc_wxgui.top_block_gui): def set_hs(self, hs): self.hs = hs + self.matched_filter.set_length_and_scale(self.hs, 1.0/self.hs) if __name__ == '__main__': parser = OptionParser(option_class=eng_option, usage="%prog: [options]") diff --git a/gr-noaa/grc/noaa_hrpt_deframer.xml b/gr-noaa/grc/noaa_hrpt_deframer.xml index bc68f71d..af36abf2 100644 --- a/gr-noaa/grc/noaa_hrpt_deframer.xml +++ b/gr-noaa/grc/noaa_hrpt_deframer.xml @@ -9,4 +9,8 @@ in byte + + out + short + diff --git a/gr-noaa/lib/noaa_hrpt_deframer.cc b/gr-noaa/lib/noaa_hrpt_deframer.cc index 71712277..b0de09c9 100644 --- a/gr-noaa/lib/noaa_hrpt_deframer.cc +++ b/gr-noaa/lib/noaa_hrpt_deframer.cc @@ -26,13 +26,19 @@ #include #include +#include #define ST_IDLE 0 #define ST_SYNCED 1 -#define HRPT_MINOR_FRAME_SYNC 0x0A116FD719D83C95LL -#define HRPT_BITS_PER_MINOR_FRAME 11090*10 -#define HRPT_SYNC_LENGTH 6*10 +#define SYNC1 0x0284 +#define SYNC2 0x016F +#define SYNC3 0x035C +#define SYNC4 0x019D +#define SYNC5 0x020F +#define SYNC6 0x0095 + +#define HRPT_MINOR_FRAME_SYNC 0x0A116FD719D83C95LL static int frames_seen = 0; @@ -43,10 +49,11 @@ noaa_make_hrpt_deframer() } noaa_hrpt_deframer::noaa_hrpt_deframer() - : gr_sync_block("noaa_hrpt_deframer", - gr_make_io_signature(1, 1, sizeof(char)), - gr_make_io_signature(0, 0, 0)) + : gr_block("noaa_hrpt_deframer", + gr_make_io_signature(1, 1, sizeof(char)), + gr_make_io_signature(1, 1, sizeof(short))) { + set_output_multiple(6); // room for writing full sync when received enter_idle(); } @@ -60,36 +67,51 @@ void noaa_hrpt_deframer::enter_synced() { d_state = ST_SYNCED; - d_count = HRPT_BITS_PER_MINOR_FRAME-HRPT_SYNC_LENGTH; + d_bit_count = HRPT_BITS_PER_WORD; + d_word_count = HRPT_MINOR_FRAME_WORDS-HRPT_SYNC_WORDS; + d_word = 0; } int -noaa_hrpt_deframer::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +noaa_hrpt_deframer::general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { + int ninputs = ninput_items[0]; const char *in = (const char *)input_items[0]; + unsigned short *out = (unsigned short *)output_items[0]; - int i = 0; - while (i < noutput_items) { + int i = 0, j = 0; + while (i < ninputs && j < noutput_items) { char bit = in[i++]; - if (d_state != ST_SYNCED) - fprintf(stderr, "."); switch (d_state) { case ST_IDLE: d_shifter = (d_shifter << 1) | bit; // MSB transmitted first if ((d_shifter & 0x0FFFFFFFFFFFFFFF) == HRPT_MINOR_FRAME_SYNC) { - fprintf(stderr, "\nSYNC #%i...", frames_seen++); + fprintf(stderr, "SYNC #%i", frames_seen++); + out[j++] = SYNC1; + out[j++] = SYNC2; + out[j++] = SYNC3; + out[j++] = SYNC4; + out[j++] = SYNC5; + out[j++] = SYNC6; enter_synced(); } break; case ST_SYNCED: - if (--d_count == 0) { - fprintf(stderr, "done."); - enter_idle(); + d_word = (d_word << 1) | bit; // MSB transmitted first + if (--d_bit_count == 0) { + out[j++] = d_word; + d_word = 0; + d_bit_count = HRPT_BITS_PER_WORD; + if (--d_word_count == 0) { + fprintf(stderr, "...done\n"); + enter_idle(); + } } break; @@ -98,5 +120,6 @@ noaa_hrpt_deframer::work(int noutput_items, } } - return i; + consume_each(i); + return j; } diff --git a/gr-noaa/lib/noaa_hrpt_deframer.h b/gr-noaa/lib/noaa_hrpt_deframer.h index bc91bc89..0aeb16a2 100644 --- a/gr-noaa/lib/noaa_hrpt_deframer.h +++ b/gr-noaa/lib/noaa_hrpt_deframer.h @@ -23,7 +23,11 @@ #ifndef INCLUDED_NOAA_HRPT_DEFRAMER_H #define INCLUDED_NOAA_HRPT_DEFRAMER_H -#include +#define HRPT_SYNC_WORDS 6 +#define HRPT_MINOR_FRAME_WORDS 11090 +#define HRPT_BITS_PER_WORD 10 + +#include class noaa_hrpt_deframer; typedef boost::shared_ptr noaa_hrpt_deframer_sptr; @@ -31,22 +35,25 @@ typedef boost::shared_ptr noaa_hrpt_deframer_sptr; noaa_hrpt_deframer_sptr noaa_make_hrpt_deframer(); -class noaa_hrpt_deframer : public gr_sync_block +class noaa_hrpt_deframer : public gr_block { friend noaa_hrpt_deframer_sptr noaa_make_hrpt_deframer(); noaa_hrpt_deframer(); unsigned int d_state; - unsigned int d_count; - unsigned long long d_shifter; // 60 bit sync word + unsigned int d_bit_count; + unsigned int d_word_count; + unsigned long long d_shifter; // 60 bit sync word + unsigned short d_word; // 10 bit HRPT word void enter_idle(); void enter_synced(); public: - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); }; #endif /* INCLUDED_NOAA_HRPT_DEFRAMER_H */ -- 2.39.5