summaryrefslogtreecommitdiff
path: root/gr-noaa/lib/noaa_hrpt_sync_fb.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gr-noaa/lib/noaa_hrpt_sync_fb.cc')
-rw-r--r--gr-noaa/lib/noaa_hrpt_sync_fb.cc90
1 files changed, 90 insertions, 0 deletions
diff --git a/gr-noaa/lib/noaa_hrpt_sync_fb.cc b/gr-noaa/lib/noaa_hrpt_sync_fb.cc
new file mode 100644
index 000000000..f99947f82
--- /dev/null
+++ b/gr-noaa/lib/noaa_hrpt_sync_fb.cc
@@ -0,0 +1,90 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <noaa_hrpt_sync_fb.h>
+#include <gr_io_signature.h>
+
+inline int signum(float f)
+{
+ return f >= 0.0 ? 1 : -1;
+}
+
+noaa_hrpt_sync_fb_sptr
+noaa_make_hrpt_sync_fb(float alpha, float beta, float sps, float max_offset)
+{
+ return gnuradio::get_initial_sptr(new noaa_hrpt_sync_fb(alpha, beta, sps, max_offset));
+}
+
+noaa_hrpt_sync_fb::noaa_hrpt_sync_fb(float alpha, float beta, float sps, float max_offset)
+ : gr_block("noaa_hrpt_sync_fb",
+ gr_make_io_signature(1, 1, sizeof(float)),
+ gr_make_io_signature(1, 1, sizeof(char))),
+ d_alpha(alpha), d_beta(beta),
+ d_sps(sps), d_max_offset(max_offset),
+ d_phase(0.0), d_freq(1.0/sps),
+ d_last_sign(1)
+{
+}
+
+int
+noaa_hrpt_sync_fb::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 float *in = (const float *)input_items[0];
+ char *out = (char *)output_items[0];
+
+ int i = 0, j = 0;
+ while (i < ninputs && j < noutput_items) {
+ float sample = in[i++];
+ int sign = signum(sample);
+ d_phase += d_freq;
+
+ // Train on zero crossings in center region of symbol
+ if (sign != d_last_sign) {
+ if (d_phase > 0.25 && d_phase < 0.75) {
+ float phase_err = d_phase-0.5;
+ d_phase -= phase_err*d_alpha; // 1st order phase adjustment
+ d_freq -= phase_err*d_beta; // 2nd order frequency adjustment
+ }
+
+ d_last_sign = sign;
+ }
+
+ if (d_phase > 1.0) {
+ if (sample < 0.0)
+ out[j++] = 1;
+ else
+ out[j++] = 0;
+ d_phase -= 1.0;
+ }
+ }
+
+ consume_each(i);
+ return j;
+}