[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r5695 - in gnuradio/branches/features/ofdm/sync/gnurad
From: |
eb |
Subject: |
[Commit-gnuradio] r5695 - in gnuradio/branches/features/ofdm/sync/gnuradio-core/src: lib/general python/gnuradio/gr |
Date: |
Tue, 5 Jun 2007 16:37:08 -0600 (MDT) |
Author: eb
Date: 2007-06-05 16:37:05 -0600 (Tue, 05 Jun 2007)
New Revision: 5695
Added:
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_insert_preamble.cc
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_insert_preamble.h
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_insert_preamble.i
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/python/gnuradio/gr/qa_ofdm_insert_preamble.py
Modified:
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/Makefile.am
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/general.i
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/python/gnuradio/gr/Makefile.am
Log:
added gr_ofdm_insert_preamble and QA code
Modified:
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/Makefile.am
===================================================================
---
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/Makefile.am
2007-06-05 19:35:41 UTC (rev 5694)
+++
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/Makefile.am
2007-06-05 22:37:05 UTC (rev 5695)
@@ -103,6 +103,7 @@
gr_ofdm_bpsk_demapper.cc \
gr_ofdm_bpsk_mapper.cc \
gr_ofdm_frame_sink.cc \
+ gr_ofdm_insert_preamble.cc \
gr_ofdm_sampler.cc \
gr_pa_2x2_phase_combiner.cc \
gr_packet_sink.cc \
@@ -243,6 +244,7 @@
gr_ofdm_bpsk_mapper.h \
gr_ofdm_bpsk_demapper.h \
gr_ofdm_frame_sink.h \
+ gr_ofdm_insert_preamble.h \
gr_ofdm_sampler.h \
gr_pa_2x2_phase_combiner.h \
gr_packet_sink.h \
@@ -384,6 +386,7 @@
gr_ofdm_bpsk_demapper.i \
gr_ofdm_bpsk_mapper.i \
gr_ofdm_frame_sink.i \
+ gr_ofdm_insert_preamble.i \
gr_ofdm_sampler.i \
gr_pa_2x2_phase_combiner.i \
gr_packet_sink.i \
Modified:
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/general.i
===================================================================
---
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/general.i
2007-06-05 19:35:41 UTC (rev 5694)
+++
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/general.i
2007-06-05 22:37:05 UTC (rev 5695)
@@ -98,6 +98,7 @@
#include <gr_ofdm_bpsk_demapper.h>
#include <gr_ofdm_bpsk_mapper.h>
#include <gr_ofdm_frame_sink.h>
+#include <gr_ofdm_insert_preamble.h>
#include <gr_ofdm_sampler.h>
#include <gr_regenerate_bb.h>
#include <gr_costas_loop_cc.h>
@@ -202,6 +203,7 @@
%include "gr_ofdm_bpsk_demapper.i"
%include "gr_ofdm_bpsk_mapper.i"
%include "gr_ofdm_frame_sink.i"
+%include "gr_ofdm_insert_preamble.i"
%include "gr_ofdm_sampler.i"
%include "gr_regenerate_bb.i"
%include "gr_costas_loop_cc.i"
Added:
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_insert_preamble.cc
===================================================================
---
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_insert_preamble.cc
(rev 0)
+++
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_insert_preamble.cc
2007-06-05 22:37:05 UTC (rev 5695)
@@ -0,0 +1,186 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 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 2, 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gr_ofdm_insert_preamble.h>
+#include <gr_io_signature.h>
+#include <stdexcept>
+#include <iostream>
+
+gr_ofdm_insert_preamble_sptr
+gr_make_ofdm_insert_preamble(int fft_length,
+ const std::vector<std::vector<gr_complex> >
&preamble)
+{
+ return gr_ofdm_insert_preamble_sptr(new gr_ofdm_insert_preamble(fft_length,
+ preamble));
+}
+
+gr_ofdm_insert_preamble::gr_ofdm_insert_preamble
+ (int fft_length,
+ const std::vector<std::vector<gr_complex> > &preamble)
+ : gr_block("ofdm_insert_preamble",
+ gr_make_io_signature2(2, 2,
+ sizeof(gr_complex)*fft_length,
+ sizeof(char)),
+ gr_make_io_signature2(1, 2,
+ sizeof(gr_complex)*fft_length,
+ sizeof(char))),
+ d_fft_length(fft_length),
+ d_preamble(preamble),
+ d_state(ST_IDLE),
+ d_nsymbols_output(0),
+ d_pending_flag(0)
+{
+ // sanity check preamble symbols
+ for (size_t i = 0; i < d_preamble.size(); i++){
+ if (d_preamble[i].size() != (size_t) d_fft_length)
+ throw std::invalid_argument("gr_ofdm_insert_preamble: invalid length for
preamble symbol");
+ }
+
+ enter_idle();
+}
+
+
+gr_ofdm_insert_preamble::~gr_ofdm_insert_preamble()
+{
+}
+
+int
+gr_ofdm_insert_preamble::general_work (int noutput_items,
+ gr_vector_int &ninput_items_v,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ int ninput_items = std::min(ninput_items_v[0], ninput_items_v[1]);
+ const gr_complex *in_sym = (const gr_complex *) input_items[0];
+ const unsigned char *in_flag = (const unsigned char *) input_items[1];
+
+ gr_complex *out_sym = (gr_complex *) output_items[0];
+ unsigned char *out_flag = 0;
+ if (output_items.size() == 2)
+ out_flag = (unsigned char *) output_items[1];
+
+
+ int no = 0; // number items output
+ int ni = 0; // number items read from input
+
+
+#define write_out_flag() \
+ do { if (out_flag) \
+ out_flag[no] = d_pending_flag; \
+ d_pending_flag = 0; \
+ } while(0)
+
+
+ while (no < noutput_items && ni < ninput_items){
+ switch(d_state){
+ case ST_IDLE:
+ if (in_flag[ni] & 0x1) // this is first symbol of new payload
+ enter_preamble();
+ else
+ ni++; // eat one input symbol
+ break;
+
+ case ST_PREAMBLE:
+ assert(in_flag[ni] & 0x1);
+ if (d_nsymbols_output >= (int) d_preamble.size()){
+ // we've output all the preamble
+ enter_first_payload();
+ }
+ else {
+ memcpy(&out_sym[no * d_fft_length],
+ &d_preamble[d_nsymbols_output][0],
+ d_fft_length*sizeof(gr_complex));
+
+ write_out_flag();
+ no++;
+ d_nsymbols_output++;
+ }
+ break;
+
+ case ST_FIRST_PAYLOAD:
+ // copy first payload symbol from input to output
+ memcpy(&out_sym[no * d_fft_length],
+ &in_sym[ni * d_fft_length],
+ d_fft_length * sizeof(gr_complex));
+
+ write_out_flag();
+ no++;
+ ni++;
+ enter_payload();
+ break;
+
+ case ST_PAYLOAD:
+ if (in_flag[ni] & 0x1){ // this is first symbol of a new payload
+ enter_preamble();
+ break;
+ }
+
+ // copy a symbol from input to output
+ memcpy(&out_sym[no * d_fft_length],
+ &in_sym[ni * d_fft_length],
+ d_fft_length * sizeof(gr_complex));
+
+ write_out_flag();
+ no++;
+ ni++;
+ break;
+
+ default:
+ std::cerr << "gr_ofdm_insert_preamble: (can't happen) invalid state,
resetting\n";
+ enter_idle();
+ }
+ }
+
+ consume_each(ni);
+ return no;
+}
+
+void
+gr_ofdm_insert_preamble::enter_idle()
+{
+ d_state = ST_IDLE;
+ d_nsymbols_output = 0;
+ d_pending_flag = 0;
+}
+
+void
+gr_ofdm_insert_preamble::enter_preamble()
+{
+ d_state = ST_PREAMBLE;
+ d_nsymbols_output = 0;
+ d_pending_flag = 1;
+}
+
+void
+gr_ofdm_insert_preamble::enter_first_payload()
+{
+ d_state = ST_FIRST_PAYLOAD;
+}
+
+void
+gr_ofdm_insert_preamble::enter_payload()
+{
+ d_state = ST_PAYLOAD;
+}
Property changes on:
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_insert_preamble.cc
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_insert_preamble.h
===================================================================
---
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_insert_preamble.h
(rev 0)
+++
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_insert_preamble.h
2007-06-05 22:37:05 UTC (rev 5695)
@@ -0,0 +1,102 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 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 2, 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef INCLUDED_GR_OFDM_INSERT_PREAMBLE_H
+#define INCLUDED_GR_OFDM_INSERT_PREAMBLE_H
+
+#include <gr_block.h>
+#include <vector>
+
+class gr_ofdm_insert_preamble;
+typedef boost::shared_ptr<gr_ofdm_insert_preamble>
gr_ofdm_insert_preamble_sptr;
+
+gr_ofdm_insert_preamble_sptr
+gr_make_ofdm_insert_preamble(int fft_length,
+ const std::vector<std::vector<gr_complex> >
&preamble);
+
+/*!
+ * \brief insert "pre-modulated" preamble symbols before each payload.
+ *
+ * <pre>
+ * input 1: stream of vectors of gr_complex [fft_length]
+ * These are the modulated symbols of the payload.
+ *
+ * input 2: stream of char. The LSB indicates whether the corresponding
+ * symbol on input 1 is the first symbol of the payload or not.
+ * It's a 1 if the corresponding symbol is the first symbol,
+ * otherwise 0.
+ *
+ * N.B., this implies that there must be at least 1 symbol in the payload.
+ *
+ *
+ * output 1: stream of vectors of gr_complex [fft_length]
+ * These include the preamble symbols and the payload symbols.
+ *
+ * output 2: stream of char. The LSB indicates whether the corresponding
+ * symbol on input 1 is the first symbol of a packet (i.e., the
+ * first symbol of the preamble.) It's a 1 if the corresponding
+ * symbol is the first symbol, otherwise 0.
+ * </pre>
+ *
+ * \param fft_length length of each symbol in samples.
+ * \param preamble vector of symbols that represent the pre-modulated
preamble.
+ */
+
+class gr_ofdm_insert_preamble : public gr_block
+{
+ friend gr_ofdm_insert_preamble_sptr
+ gr_make_ofdm_insert_preamble(int fft_length,
+ const std::vector<std::vector<gr_complex> >
&preamble);
+
+protected:
+ gr_ofdm_insert_preamble(int fft_length,
+ const std::vector<std::vector<gr_complex> >
&preamble);
+
+private:
+ enum state_t {
+ ST_IDLE,
+ ST_PREAMBLE,
+ ST_FIRST_PAYLOAD,
+ ST_PAYLOAD
+ };
+
+ int d_fft_length;
+ const std::vector<std::vector<gr_complex> > d_preamble;
+ state_t d_state;
+ int d_nsymbols_output;
+ int d_pending_flag;
+
+ void enter_idle();
+ void enter_preamble();
+ void enter_first_payload();
+ void enter_payload();
+
+
+public:
+ ~gr_ofdm_insert_preamble();
+
+ 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_GR_OFDM_INSERT_PREAMBLE_H */
Property changes on:
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_insert_preamble.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_insert_preamble.i
===================================================================
---
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_insert_preamble.i
(rev 0)
+++
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_insert_preamble.i
2007-06-05 22:37:05 UTC (rev 5695)
@@ -0,0 +1,35 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 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 2, 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.
+ */
+
+GR_SWIG_BLOCK_MAGIC(gr,ofdm_insert_preamble);
+
+gr_ofdm_insert_preamble_sptr
+gr_make_ofdm_insert_preamble(int fft_length,
+ const std::vector<std::vector<gr_complex> >
&preamble);
+
+
+class gr_ofdm_insert_preamble : public gr_block
+{
+ protected:
+ gr_ofdm_insert_preamble(int fft_length,
+ const std::vector<std::vector<gr_complex> >
&preamble);
+};
Modified:
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/python/gnuradio/gr/Makefile.am
===================================================================
---
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/python/gnuradio/gr/Makefile.am
2007-06-05 19:35:41 UTC (rev 5694)
+++
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/python/gnuradio/gr/Makefile.am
2007-06-05 22:37:05 UTC (rev 5695)
@@ -80,6 +80,7 @@
qa_mute.py \
qa_nlog10.py \
qa_noise.py \
+ qa_ofdm_insert_preamble.py \
qa_packed_to_unpacked.py \
qa_pipe_fittings.py \
qa_pll_carriertracking.py \
Added:
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/python/gnuradio/gr/qa_ofdm_insert_preamble.py
===================================================================
---
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/python/gnuradio/gr/qa_ofdm_insert_preamble.py
(rev 0)
+++
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/python/gnuradio/gr/qa_ofdm_insert_preamble.py
2007-06-05 22:37:05 UTC (rev 5695)
@@ -0,0 +1,179 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 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 2, 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.
+#
+
+from gnuradio import gr, gr_unittest
+from pprint import pprint
+
+class testing (gr_unittest.TestCase):
+
+ def setUp (self):
+ self.fg = gr.flow_graph ()
+
+ def tearDown (self):
+ self.fg = None
+
+ def helper(self, v0, v1, fft_length, preamble):
+ fg = self.fg
+ src0 = gr.vector_source_c(v0)
+ src1 = gr.vector_source_b(v1)
+
+ s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_length)
+
+ # print "len(v) = %d" % (len(v))
+
+ op = gr.ofdm_insert_preamble(fft_length, preamble)
+
+ v2s = gr.vector_to_stream(gr.sizeof_gr_complex, fft_length)
+ dst0 = gr.vector_sink_c()
+ dst1 = gr.vector_sink_b()
+
+ fg.connect(src0, s2v, (op, 0))
+ fg.connect(src1, (op, 1))
+ fg.connect((op, 0), v2s, dst0)
+ fg.connect((op, 1), dst1)
+
+ fg.run()
+ r0 = dst0.data()
+ r0v = []
+ for i in range(len(r0)//fft_length):
+ r0v.append(r0[i*fft_length:(i+1)*fft_length])
+
+ r1 = dst1.data()
+ self.assertEqual(len(r0v), len(r1))
+ return (r1, r0v)
+
+ def check_match(self, actual, expected_list):
+ lst = []
+ map(lambda x: lst.append(x), expected_list)
+ self.assertEqual(actual, lst)
+
+
+ # ----------------------------------------------------------------
+
+ def test_000(self):
+ # no preamble, 1 symbol payloads
+
+ preamble = ()
+ fft_length = 8
+ npayloads = 8
+ v = []
+ p = []
+ for i in range(npayloads):
+ t = fft_length*[(i + i*1j)]
+ p.append(tuple(t))
+ v += t
+
+ p = tuple(p)
+
+ r = self.helper(v, npayloads*[1], fft_length, preamble)
+ # pprint(r)
+
+ self.assertEqual(r[0], tuple(npayloads*[1]))
+ self.check_match(r[1], (p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]))
+
+
+ def test_001(self):
+ # 1 symbol preamble, 1 symbol payloads
+ preamble = ((100, 101, 102, 103, 104, 105, 106, 107),)
+ p0 = preamble[0]
+ fft_length = 8
+ npayloads = 8
+ v = []
+ p = []
+ for i in range(npayloads):
+ t = fft_length*[(i + i*1j)]
+ p.append(tuple(t))
+ v += t
+
+
+ r = self.helper(v, npayloads*[1], fft_length, preamble)
+
+ self.assertEqual(r[0], tuple(npayloads*[1, 0]))
+ self.check_match(r[1], (p0, p[0],
+ p0, p[1],
+ p0, p[2],
+ p0, p[3],
+ p0, p[4],
+ p0, p[5],
+ p0, p[6],
+ p0, p[7]))
+
+ def test_002(self):
+ # 2 symbol preamble, 1 symbol payloads
+ preamble = ((100, 101, 102, 103, 104, 105, 106, 107),
+ (200, 201, 202, 203, 204, 205, 206, 207))
+ p0 = preamble[0]
+ p1 = preamble[1]
+
+ fft_length = 8
+ npayloads = 8
+ v = []
+ p = []
+ for i in range(npayloads):
+ t = fft_length*[(i + i*1j)]
+ p.append(tuple(t))
+ v += t
+
+ r = self.helper(v, npayloads*[1], fft_length, preamble)
+
+ self.assertEqual(r[0], tuple(npayloads*[1, 0, 0]))
+ self.check_match(r[1], (p0, p1, p[0],
+ p0, p1, p[1],
+ p0, p1, p[2],
+ p0, p1, p[3],
+ p0, p1, p[4],
+ p0, p1, p[5],
+ p0, p1, p[6],
+ p0, p1, p[7]))
+
+
+ def xtest_003_preamble(self):
+ # 2 symbol preamble, 2 symbol payloads
+ preamble = ((100, 101, 102, 103, 104, 105, 106, 107),
+ (200, 201, 202, 203, 204, 205, 206, 207))
+ p0 = preamble[0]
+ p1 = preamble[1]
+
+ fft_length = 8
+ npayloads = 8
+ v = []
+ p = []
+ for i in range(npayloads * 2):
+ t = fft_length*[(i + i*1j)]
+ p.append(tuple(t))
+ v += t
+
+ r = self.helper(v, npayloads*[1, 0], fft_length, preamble)
+
+ self.assertEqual(r[0], tuple(npayloads*[1, 0, 0, 0]))
+ self.check_match(r[1], (p0, p1, p[0], p[1],
+ p0, p1, p[2], p[3],
+ p0, p1, p[4], p[5],
+ p0, p1, p[6], p[7],
+ p0, p1, p[8], p[9],
+ p0, p1, p[10], p[11],
+ p0, p1, p[12], p[13],
+ p0, p1, p[14], p[15]))
+
+
+if __name__ == '__main__':
+ gr_unittest.main ()
Property changes on:
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/python/gnuradio/gr/qa_ofdm_insert_preamble.py
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:eol-style
+ native
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r5695 - in gnuradio/branches/features/ofdm/sync/gnuradio-core/src: lib/general python/gnuradio/gr,
eb <=