commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r8448 - in gnuradio/branches/developers/cswiger/wip/gr


From: cswiger
Subject: [Commit-gnuradio] r8448 - in gnuradio/branches/developers/cswiger/wip/gr-atsc/src: lib python
Date: Mon, 19 May 2008 15:21:52 -0600 (MDT)

Author: cswiger
Date: 2008-05-19 15:21:50 -0600 (Mon, 19 May 2008)
New Revision: 8448

Added:
   gnuradio/branches/developers/cswiger/wip/gr-atsc/src/lib/atsc_cpll.cc
   gnuradio/branches/developers/cswiger/wip/gr-atsc/src/lib/atsc_cpll.h
   gnuradio/branches/developers/cswiger/wip/gr-atsc/src/python/cpll.py
Modified:
   gnuradio/branches/developers/cswiger/wip/gr-atsc/src/lib/Makefile.am
   gnuradio/branches/developers/cswiger/wip/gr-atsc/src/lib/atsc.i
Log:
Added complex phase lock loop and python script for it, atsc_cpll.


Modified: gnuradio/branches/developers/cswiger/wip/gr-atsc/src/lib/Makefile.am
===================================================================
--- gnuradio/branches/developers/cswiger/wip/gr-atsc/src/lib/Makefile.am        
2008-05-19 19:47:11 UTC (rev 8447)
+++ gnuradio/branches/developers/cswiger/wip/gr-atsc/src/lib/Makefile.am        
2008-05-19 21:21:50 UTC (rev 8448)
@@ -76,6 +76,7 @@
        atsc_fs_checker.cc                      \
        atsc_bit_timing_loop.cc                 \
        atsc_fpll.cc                            \
+       atsc_cpll.cc                            \
        atsc_depad.cc                           \
        atsc_pad.cc                             \
        atsci_basic_trellis_encoder.cc          \
@@ -137,6 +138,7 @@
        atsc_fs_checker.h                       \
        atsc_bit_timing_loop.h                  \
        atsc_fpll.h                             \
+       atsc_cpll.h                             \
        atsc_depad.h                            \
        atsc_pad.h                              \
        atsc_types.h                            \

Modified: gnuradio/branches/developers/cswiger/wip/gr-atsc/src/lib/atsc.i
===================================================================
--- gnuradio/branches/developers/cswiger/wip/gr-atsc/src/lib/atsc.i     
2008-05-19 19:47:11 UTC (rev 8447)
+++ gnuradio/branches/developers/cswiger/wip/gr-atsc/src/lib/atsc.i     
2008-05-19 21:21:50 UTC (rev 8448)
@@ -23,6 +23,7 @@
 #include <atsc_fs_checker.h>
 #include <atsc_bit_timing_loop.h>
 #include <atsc_fpll.h>
+#include <atsc_cpll.h>
 #include <atsc_depad.h>
 #include <atsc_pad.h>
 %}
@@ -254,6 +255,21 @@
 
 // ----------------------------------------------------------------
 
+GR_SWIG_BLOCK_MAGIC(atsc,cpll);
+
+atsc_cpll_sptr atsc_make_cpll();
+
+class atsc_cpll : public gr_sync_block
+{
+  atsc_cpll();
+
+public:
+  void reset();
+
+};
+
+// ----------------------------------------------------------------
+
 GR_SWIG_BLOCK_MAGIC(atsc,depad);
 
 atsc_depad_sptr atsc_make_depad();

Added: gnuradio/branches/developers/cswiger/wip/gr-atsc/src/lib/atsc_cpll.cc
===================================================================
--- gnuradio/branches/developers/cswiger/wip/gr-atsc/src/lib/atsc_cpll.cc       
                        (rev 0)
+++ gnuradio/branches/developers/cswiger/wip/gr-atsc/src/lib/atsc_cpll.cc       
2008-05-19 21:21:50 UTC (rev 8448)
@@ -0,0 +1,161 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006 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 <atsc_cpll.h>
+#include <gr_io_signature.h>
+#include <atsc_consts.h>
+#include <algorithm>
+#include "fpll_btloop_coupling.h"
+#include <math.h>
+#include <gr_math.h>
+
+#define M_TWOPI (2*M_PI)
+
+atsc_cpll_sptr
+atsc_make_cpll()
+{
+  return atsc_cpll_sptr(new atsc_cpll());
+}
+
+
+/*
+ * I strongly suggest that you not mess with these...
+ *
+ * They are strongly coupled into the symbol timing code and
+ * their value also sets the level of the symbols going
+ * into the equalizer and viterbi decoder.
+ */
+static const float CPLL_AGC_REFERENCE = 2.5 * FPLL_BTLOOP_COUPLING_CONST;
+static const float CPLL_AGC_RATE = 0.25e-6;
+
+
+
+atsc_cpll::atsc_cpll()
+  : gr_sync_block("atsc_cpll",
+                 gr_make_io_signature(1, 1, sizeof(gr_complex)),
+                 gr_make_io_signature(1, 1, sizeof(gr_complex))),
+                 initial_phase(0)
+{
+  initial_freq = 0 - 3e6 + 0.31e6 + 5e3; // a_initial_freq;
+  agc.set_rate (CPLL_AGC_RATE);
+  agc.set_reference (CPLL_AGC_REFERENCE);
+  initialize();
+}
+
+
+void
+atsc_cpll::initialize ()
+{
+  float Fs = 19.2e6;
+
+  float alpha = 1 - exp(-1.0 / Fs / 5e-6);
+
+  afci.set_taps (alpha);
+  afcq.set_taps (alpha);
+
+  printf("Setting initial_freq: %f\n",initial_freq);
+  nco.set_freq (initial_freq / Fs * 2 * M_PI);
+  nco.set_phase (initial_phase);
+}
+
+float
+atsc_cpll::mod_2pi (float in)
+{
+  if(in>M_PI)
+    return in-M_TWOPI;
+  else if(in<-M_PI)
+    return in+M_TWOPI;
+  else
+    return in;
+}
+
+float
+atsc_cpll::phase_detector(gr_complex sample,float ref_phase)
+{
+  float sample_phase;
+  //  sample_phase = atan2(sample.imag(),sample.real());
+  sample_phase = gr_fast_atan2f(sample.imag(),sample.real());
+  return mod_2pi(sample_phase-ref_phase);
+}
+  
+
+int
+atsc_cpll::work (int noutput_items,
+                      gr_vector_const_void_star &input_items,
+                      gr_vector_void_star &output_items)
+{
+  const gr_complex *in = (const gr_complex *) input_items[0];
+  gr_complex *out = (gr_complex *) output_items[0];
+
+  for (int k = 0; k < noutput_items; k++){
+
+    float a_cos, a_sin;
+
+    gr_complex input;
+    input = agc.scale (in[k]);
+
+    nco.step ();                // increment phase
+    nco.sincos (&a_sin, &a_cos);  // compute cos and sin
+
+    gr_complex IQ = input * gr_complex(a_cos,-a_sin);
+
+    out[k] = IQ;
+
+    gr_complex filtered_IQ;
+    filtered_IQ.real() = afci.filter (IQ.real());
+    filtered_IQ.imag() = afcq.filter (IQ.imag());
+
+    // phase detector
+
+    // float x = atan2 (filtered_Q, filtered_I);
+    float x = phase_detector(filtered_IQ, 0);
+
+    // avoid slamming filter with big transitions
+
+    static const float limit = M_PI / 2;
+
+    if (x > limit)
+      x = limit;
+    else if (x < -limit)
+      x = -limit;
+
+    // static const float alpha = 0.037;   // Max value
+    // static const float alpha = 0.005;   // takes about 5k samples to pull 
in, stddev = 323
+    // static const float alpha = 0.002;   // takes about 15k samples to pull 
in, stddev =  69
+                                           //  or about 120k samples on noisy 
data,
+    static const float alpha = 0.001;
+    static const float beta = alpha * alpha / 4;
+
+    nco.adjust_phase (alpha * x);
+    nco.adjust_freq (beta * x);
+
+  }
+
+  return noutput_items;
+}
+
+
+

Added: gnuradio/branches/developers/cswiger/wip/gr-atsc/src/lib/atsc_cpll.h
===================================================================
--- gnuradio/branches/developers/cswiger/wip/gr-atsc/src/lib/atsc_cpll.h        
                        (rev 0)
+++ gnuradio/branches/developers/cswiger/wip/gr-atsc/src/lib/atsc_cpll.h        
2008-05-19 21:21:50 UTC (rev 8448)
@@ -0,0 +1,81 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006 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.
+ */
+#ifndef INCLUDED_ATSC_CPLL_H
+#define INCLUDED_ATSC_CPLL_H
+
+#include <gr_sync_block.h>
+#include <gr_nco.h>
+#include <gr_single_pole_iir.h>
+#include <gri_agc_cc.h>
+#include <stdio.h>
+#include <atsci_diag_output.h>
+
+class atsc_cpll;
+typedef boost::shared_ptr<atsc_cpll> atsc_cpll_sptr;
+
+atsc_cpll_sptr atsc_make_cpll();
+
+/*!
+ * \brief ATSC CPLL (2nd Version)
+ * \ingroup atsc
+ *
+ *  A/D --> GrFIRfilterFFF ----> GrAtscFPLL ---->
+ *
+ * We use GrFIRfilterFFF to bandpass filter the signal of interest.
+ *
+ * This class accepts a single real input and produces a single real output
+ */
+
+class atsc_cpll : public gr_sync_block
+{
+  friend atsc_cpll_sptr atsc_make_cpll();
+
+  atsc_cpll();
+
+public:
+
+  int work (int noutput_items,
+           gr_vector_const_void_star &input_items,
+           gr_vector_void_star &output_items);
+
+  void reset() { /* nop */ }
+
+  void initialize () ;
+
+ protected:
+
+  double                        initial_freq;
+  double                        initial_phase;
+  bool                          debug_no_update;
+  gr_nco<float,float>           nco;
+  gri_agc_cc                    agc;    // automatic gain control
+  gr_single_pole_iir<float,float,float> afci;
+  gr_single_pole_iir<float,float,float> afcq;
+
+  float mod_2pi (float in);
+  float phase_detector(gr_complex sample, float ref_phase);
+
+
+};
+
+
+#endif /* INCLUDED_ATSC_CPLL_H */

Added: gnuradio/branches/developers/cswiger/wip/gr-atsc/src/python/cpll.py
===================================================================
--- gnuradio/branches/developers/cswiger/wip/gr-atsc/src/python/cpll.py         
                (rev 0)
+++ gnuradio/branches/developers/cswiger/wip/gr-atsc/src/python/cpll.py 
2008-05-19 21:21:50 UTC (rev 8448)
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+#
+# Copyright 2004,2005 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., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+# 
+
+from gnuradio import gr, atsc
+import math, os
+
+def main():
+
+       print os.getpid()
+
+       tb = gr.top_block()
+
+        u = gr.file_source(gr.sizeof_gr_complex,"/tmp/atsc_pipe_1")
+
+        input_rate = 19.2e6
+       IF_freq = 5.75e6
+
+
+       # 1/2 as wide because we're designing lp filter
+       symbol_rate = atsc.ATSC_SYMBOL_RATE/2. 
+       NTAPS = 279
+       tt = gr.firdes.root_raised_cosine (1.0, input_rate, symbol_rate, .115, 
NTAPS)
+  # heterodyne the low pass coefficients up to the specified bandpass
+  # center frequency.  Note that when we do this, the filter bandwidth
+  # is effectively twice the low pass (2.69 * 2 = 5.38) and hence
+  # matches the diagram in the ATSC spec.
+       arg = 2. * math.pi * IF_freq / input_rate
+       t=[]
+       for i in range(len(tt)):
+         t += [tt[i] * 2. * math.cos(arg * i)]
+       rrc = gr.fir_filter_fff(1, t)
+
+       cpll = atsc.cpll()
+       c2f = gr.complex_to_float()
+
+       pilot_freq = IF_freq - 3e6 + 0.31e6
+       lower_edge = 6e6 - 0.31e6
+       upper_edge = IF_freq - 3e6 + pilot_freq
+       transition_width = upper_edge - lower_edge
+       lp_coeffs = gr.firdes.low_pass (1.0,
+                          input_rate,
+                          (lower_edge + upper_edge) * 0.5,
+                           transition_width,
+                           gr.firdes.WIN_HAMMING);
+
+       lp_filter = gr.fir_filter_fff (1,lp_coeffs)
+
+       alpha = 1e-5
+       iir = gr.single_pole_iir_filter_ff(alpha)
+       remove_dc = gr.sub_ff()
+
+       out = gr.file_sink(gr.sizeof_float,"/tmp/atsc_pipe_3")
+       # out = gr.file_sink(gr.sizeof_float,"/mnt/sata/atsc_data_float")
+
+        tb.connect(u, cpll, c2f, lp_filter)
+       tb.connect(lp_filter, iir)
+       tb.connect(lp_filter, (remove_dc,0))
+       tb.connect(iir, (remove_dc,1))
+       tb.connect(remove_dc, out)
+
+       tb.run()
+
+
+if __name__ == '__main__':
+    main ()
+
+
+


Property changes on: 
gnuradio/branches/developers/cswiger/wip/gr-atsc/src/python/cpll.py
___________________________________________________________________
Name: svn:executable
   + *





reply via email to

[Prev in Thread] Current Thread [Next in Thread]