3 * Copyright 2007,2008,2010 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
27 #include <gr_ofdm_sampler.h>
28 #include <gr_io_signature.h>
33 gr_make_ofdm_sampler (unsigned int fft_length,
34 unsigned int symbol_length,
37 return gr_ofdm_sampler_sptr (new gr_ofdm_sampler (fft_length, symbol_length, timeout));
40 gr_ofdm_sampler::gr_ofdm_sampler (unsigned int fft_length,
41 unsigned int symbol_length,
43 : gr_block ("ofdm_sampler",
44 gr_make_io_signature2 (2, 2, sizeof (gr_complex), sizeof(char)),
45 gr_make_io_signature2 (2, 2, sizeof (gr_complex)*fft_length, sizeof(char)*fft_length)),
46 d_state(STATE_NO_SIG), d_timeout_max(timeout), d_fft_length(fft_length), d_symbol_length(symbol_length)
48 set_relative_rate(1.0/(double) fft_length); // buffer allocator hint
52 gr_ofdm_sampler::forecast (int noutput_items, gr_vector_int &ninput_items_required)
54 // FIXME do we need more
55 //int nreqd = (noutput_items-1) * d_symbol_length + d_fft_length;
56 int nreqd = d_symbol_length + d_fft_length;
57 unsigned ninputs = ninput_items_required.size ();
58 for (unsigned i = 0; i < ninputs; i++)
59 ninput_items_required[i] = nreqd;
64 gr_ofdm_sampler::general_work (int noutput_items,
65 gr_vector_int &ninput_items,
66 gr_vector_const_void_star &input_items,
67 gr_vector_void_star &output_items)
69 const gr_complex *iptr = (const gr_complex *) input_items[0];
70 const char *trigger = (const char *) input_items[1];
72 gr_complex *optr = (gr_complex *) output_items[0];
73 char *outsig = (char *) output_items[1];
75 //FIXME: we only process a single OFDM symbol at a time; after the preamble, we can
76 // process a few at a time as long as we always look out for the next preamble.
78 unsigned int index=d_fft_length; // start one fft length into the input so we can always look back this far
80 outsig[0] = 0; // set output to no signal by default
82 // Search for a preamble trigger signal during the next symbol length
83 while((d_state != STATE_PREAMBLE) && (index <= (d_symbol_length+d_fft_length))) {
85 outsig[0] = 1; // tell the next block there is a preamble coming
86 d_state = STATE_PREAMBLE;
92 unsigned int i, pos, ret;
95 // When we found a preamble trigger, get it and set the symbol boundary here
96 for(i = (index - d_fft_length + 1); i <= index; i++) {
100 d_timeout = d_timeout_max; // tell the system to expect at least this many symbols for a frame
101 d_state = STATE_FRAME;
102 consume_each(index - d_fft_length + 1); // consume up to one fft_length away to keep the history
107 // use this state when we have processed a preamble and are getting the rest of the frames
108 //FIXME: we could also have a power squelch system here to enter STATE_NO_SIG if no power is received
110 // skip over fft length history and cyclic prefix
111 pos = d_symbol_length; // keeps track of where we are in the input buffer
112 while(pos < d_symbol_length + d_fft_length) {
113 *optr++ = iptr[pos++];
116 if(d_timeout-- == 0) {
118 d_state = STATE_NO_SIG;
121 consume_each(d_symbol_length); // jump up by 1 fft length and the cyclic prefix length
127 consume_each(index-d_fft_length); // consume everything we've gone through so far leaving the fft length history