[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r5720 - gnuradio/branches/features/ofdm/sync/gnuradio-
From: |
trondeau |
Subject: |
[Commit-gnuradio] r5720 - gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general |
Date: |
Wed, 6 Jun 2007 16:56:32 -0600 (MDT) |
Author: trondeau
Date: 2007-06-06 16:56:32 -0600 (Wed, 06 Jun 2007)
New Revision: 5720
Added:
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_qam_mapper.cc
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_qam_mapper.h
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_qam_mapper.i
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
Log:
adding M-QAM modulators to the OFDM tx
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-06 22:55:57 UTC (rev 5719)
+++
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/Makefile.am
2007-06-06 22:56:32 UTC (rev 5720)
@@ -103,6 +103,7 @@
gr_ofdm_bpsk_demapper.cc \
gr_ofdm_bpsk_mapper.cc \
gr_ofdm_qpsk_mapper.cc \
+ gr_ofdm_qam_mapper.cc \
gr_ofdm_bpsk_mapper0.cc \
gr_ofdm_frame_sink.cc \
gr_ofdm_insert_preamble.cc \
@@ -246,6 +247,7 @@
gr_ofdm_bpsk_mapper.h \
gr_ofdm_bpsk_mapper0.h \
gr_ofdm_qpsk_mapper.h \
+ gr_ofdm_qam_mapper.h \
gr_ofdm_bpsk_demapper.h \
gr_ofdm_frame_sink.h \
gr_ofdm_insert_preamble.h \
@@ -390,6 +392,7 @@
gr_ofdm_bpsk_demapper.i \
gr_ofdm_bpsk_mapper.i \
gr_ofdm_qpsk_mapper.i \
+ gr_ofdm_qam_mapper.i \
gr_ofdm_bpsk_mapper0.i \
gr_ofdm_frame_sink.i \
gr_ofdm_insert_preamble.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-06 22:55:57 UTC (rev 5719)
+++
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/general.i
2007-06-06 22:56:32 UTC (rev 5720)
@@ -98,6 +98,7 @@
#include <gr_ofdm_bpsk_demapper.h>
#include <gr_ofdm_bpsk_mapper.h>
#include <gr_ofdm_qpsk_mapper.h>
+#include <gr_ofdm_qam_mapper.h>
#include <gr_ofdm_frame_sink.h>
#include <gr_ofdm_insert_preamble.h>
#include <gr_ofdm_sampler.h>
@@ -204,6 +205,7 @@
%include "gr_ofdm_bpsk_demapper.i"
%include "gr_ofdm_bpsk_mapper.i"
%include "gr_ofdm_qpsk_mapper.i"
+%include "gr_ofdm_qam_mapper.i"
%include "gr_ofdm_frame_sink.i"
%include "gr_ofdm_insert_preamble.i"
%include "gr_ofdm_sampler.i"
Added:
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_qam_mapper.cc
===================================================================
---
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_qam_mapper.cc
(rev 0)
+++
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_qam_mapper.cc
2007-06-06 22:56:32 UTC (rev 5720)
@@ -0,0 +1,216 @@
+/* -*- 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_ofdm_qam_mapper.h>
+#include <gr_io_signature.h>
+#include <stdexcept>
+
+gr_ofdm_qam_mapper_sptr
+gr_make_ofdm_qam_mapper (unsigned int msgq_limit,
+ unsigned int occupied_carriers, unsigned int
fft_length,
+ int m)
+{
+ return gr_ofdm_qam_mapper_sptr (new gr_ofdm_qam_mapper (msgq_limit,
occupied_carriers, fft_length, m));
+}
+
+// Consumes 1 packet and produces as many OFDM symbols of fft_length to hold
the full packet
+gr_ofdm_qam_mapper::gr_ofdm_qam_mapper (unsigned int msgq_limit,
+ unsigned int occupied_carriers,
unsigned int fft_length,
+ int m)
+ : gr_sync_block ("ofdm_qam_mapper",
+ gr_make_io_signature (0, 0, 0),
+ gr_make_io_signature2 (1, 2, sizeof(gr_complex)*fft_length,
sizeof(char))),
+ d_msgq(gr_make_msg_queue(msgq_limit)), d_msg_offset(0), d_eof(false),
+ d_occupied_carriers(occupied_carriers),
+ d_fft_length(fft_length),
+ d_bit_offset(0),
+ d_pending_flag(0),
+ d_mod_order(m)
+{
+ if (!(d_occupied_carriers <= d_fft_length))
+ throw std::invalid_argument("gr_ofdm_qam_mapper: occupied carriers must be
<= fft_length");
+
+ bool ok = false;
+ if(m == 2) {
+ ok = true;
+ }
+ if(m == 4) {
+ ok = true;
+ }
+ if(m == 16) {
+ ok = true;
+ }
+ if(m == 64) {
+ ok = true;
+ }
+ if(m == 256) {
+ ok = true;
+ }
+
+ if(!ok)
+ throw std::invalid_argument("Order M must be [2, 4, 16, 64, 256]");
+}
+
+gr_ofdm_qam_mapper::~gr_ofdm_qam_mapper(void)
+{
+}
+
+void gr_ofdm_qam_mapper::make_constellation(int m)
+{
+ int i = 0, j = 0, ii = 0, jj = 0;
+ // number of bits/symbol (log2(M))
+ int k = (int)(log10(m) / log10(2.0));
+
+ int a, b;
+ float re, im;
+ float coeff = 1;
+ std::vector<int> bits_i, bits_q;
+
+ for(i=0; i < m; i++) {
+ a = (i & (0x01 << (k-1))) >> (k-1);
+ b = (i & (0x01 << (k-2))) >> (k-2);
+ for(j=2; j < k; j+=2) {
+ bits_i.push_back( (i & (0x01 << (k-j-1))) >> (k-j-1));
+ bits_q.push_back( (i & (0x01 << (k-(j+1)-1))) >> (k-(j+1)-1));
+ }
+
+ int ss = 0;
+ int ll = bits_i.size();
+ for(ii = 0; i < ll; i++) {
+ int rr = 0;
+ for(jj = 0; jj < (ll-ii); jj++) {
+ rr = abs(bits_i[jj] - rr);
+ ss += rr * pow(2.0, ii+1);
+ }
+ re = (2.0*a-1.0)*(ss+1.0);
+
+ ss = 0;
+ ll = bits_q.size();
+ for(ii = 0; ii < ll; ii++) {
+ rr = 0;
+ for(jj = 0; jj < (ll-ii); jj++) {
+ rr = abs(bits_q[jj] - rr);
+ }
+ ss += rr*pow(2.0, ii+1.0);
+ }
+ im = (2.0*b-1.0)*(ss+1.0);
+
+ a = std::max(re, im);
+ if(a > coeff) {
+ coeff = a;
+ }
+ d_constellation_map.push_back(gr_complex(re, im));
+ }
+
+ for(i = 0; i < d_constellation_map.size(); i++) {
+ d_constellation_map[i] /= coeff;
+ }
+ }
+}
+
+static float
+randombit()
+{
+ int r = rand()&1;
+ return (float)(-1 + 2*r);
+}
+
+int
+gr_ofdm_qam_mapper::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ gr_complex *out = (gr_complex *)output_items[0];
+
+ unsigned int i=0;
+ unsigned int unoccupied_carriers = d_fft_length - d_occupied_carriers;
+ unsigned int zeros_on_left = (unsigned)ceil(unoccupied_carriers/2.0);
+
+ //printf("OFDM QAM Mapper: ninput_items: %d noutput_items: %d\n",
ninput_items[0], noutput_items);
+
+ if(d_eof) {
+ return -1;
+ }
+
+ if(!d_msg) {
+ d_msg = d_msgq->delete_head(); // block, waiting for a message
+ d_msg_offset = 0;
+ d_bit_offset = 0;
+ d_pending_flag = 1; // new packet, write start
of packet flag
+
+ if((d_msg->length() == 0) && (d_msg->type() == 1)) {
+ d_msg.reset();
+ return -1; // We're done; no more messages coming.
+ }
+ }
+
+ char *out_flag = 0;
+ if(output_items.size() == 2)
+ out_flag = (char *) output_items[1];
+
+
+ // Build a single symbol:
+
+
+ // Initialize all bins to 0 to set unused carriers
+ memset(out, 0, d_fft_length*sizeof(gr_complex));
+
+ i = 0;
+ while((d_msg_offset < d_msg->length()) && (i < d_occupied_carriers)) {
+ unsigned char bit0 = (d_msg->msg()[d_msg_offset] >> (d_bit_offset)) & 0x01;
+ d_bit_offset++;
+
+ unsigned char bit1 = (d_msg->msg()[d_msg_offset] >> (d_bit_offset)) & 0x01;
+ d_bit_offset++;
+
+ out[i + zeros_on_left] = gr_complex(-1+2*(bit0), -1+2*(bit1) );
+ i++;
+ if(d_bit_offset == 8) {
+ d_bit_offset = 0;
+ d_msg_offset++;
+ }
+ }
+
+ // Ran out of data to put in symbol
+ if (d_msg_offset == d_msg->length()) {
+ while(i < d_occupied_carriers) { // finish filling out the symbol
+ out[i + zeros_on_left] = gr_complex(randombit(),0);
+ i++;
+ }
+
+ if (d_msg->type() == 1) // type == 1 sets EOF
+ d_eof = true;
+ d_msg.reset(); // finished packet, free message
+ assert(d_bit_offset == 0);
+ }
+
+ if (out_flag)
+ out_flag[0] = d_pending_flag;
+ d_pending_flag = 0;
+
+ return 1; // produced symbol
+}
+
Added:
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_qam_mapper.h
===================================================================
---
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_qam_mapper.h
(rev 0)
+++
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_qam_mapper.h
2007-06-06 22:56:32 UTC (rev 5720)
@@ -0,0 +1,84 @@
+/* -*- 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.
+ */
+
+#ifndef INCLUDED_GR_OFDM_QAM_MAPPER_H
+#define INCLUDED_GR_OFDM_QAM_MAPPER_H
+
+
+#include <gr_sync_block.h>
+#include <gr_message.h>
+#include <gr_msg_queue.h>
+
+class gr_ofdm_qam_mapper;
+typedef boost::shared_ptr<gr_ofdm_qam_mapper> gr_ofdm_qam_mapper_sptr;
+
+gr_ofdm_qam_mapper_sptr
+gr_make_ofdm_qam_mapper (unsigned msgq_limit,
+ unsigned occupied_carriers, unsigned int fft_length,
+ int m=4);
+
+/*!
+ * \brief take a message in and map to a vector of complex
+ * constellation points suitable for IFFT input to be used in an ofdm
+ * modulator. Simple QAM version.
+ */
+
+class gr_ofdm_qam_mapper : public gr_sync_block
+{
+ friend gr_ofdm_qam_mapper_sptr
+ gr_make_ofdm_qam_mapper (unsigned msgq_limit,
+ unsigned occupied_carriers, unsigned int fft_length,
+ int m);
+ protected:
+ gr_ofdm_qam_mapper (unsigned msgq_limit,
+ unsigned occupied_carriers, unsigned int fft_length,
+ int m);
+
+ private:
+ gr_msg_queue_sptr d_msgq;
+ gr_message_sptr d_msg;
+ unsigned d_msg_offset;
+ bool d_eof;
+
+ unsigned int d_occupied_carriers;
+ unsigned int d_fft_length;
+ unsigned int d_bit_offset;
+ int d_pending_flag;
+
+ int d_mod_order;
+ std::vector<gr_complex> d_constellation_map;
+
+ void make_constellation(int m);
+
+ public:
+ ~gr_ofdm_qam_mapper(void);
+
+ gr_msg_queue_sptr msgq() const { return d_msgq; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+};
+
+
+#endif
Added:
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_qam_mapper.i
===================================================================
---
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_qam_mapper.i
(rev 0)
+++
gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general/gr_ofdm_qam_mapper.i
2007-06-06 22:56:32 UTC (rev 5720)
@@ -0,0 +1,46 @@
+/* -*- 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_qam_mapper);
+
+gr_ofdm_qam_mapper_sptr
+gr_make_ofdm_qam_mapper (unsigned int msgq_limit,
+ unsigned int bits_per_symbol,
+ unsigned int fft_length,
+ int m=16);
+
+
+class gr_ofdm_qam_mapper : public gr_sync_block
+{
+ protected:
+ gr_ofdm_qam_mapper (unsigned int msgq_limit,
+ unsigned int bits_per_symbol,
+ unsigned int fft_length,
+ int m);
+
+ public:
+ gr_msg_queue_sptr msgq();
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r5720 - gnuradio/branches/features/ofdm/sync/gnuradio-core/src/lib/general,
trondeau <=