root / gnuradio-core / src / lib / general / gr_ofdm_sampler.cc @ 9967e2e7
History | View | Annotate | Download (2.8 kB)
| 1 | /* -*- c++ -*- */
|
|---|---|
| 2 | /*
|
| 3 | * Copyright 2007 Free Software Foundation, Inc. |
| 4 | * |
| 5 | * This file is part of GNU Radio |
| 6 | * |
| 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) |
| 10 | * any later version. |
| 11 | * |
| 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. |
| 16 | * |
| 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. |
| 21 | */ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_H
|
| 24 | #include "config.h" |
| 25 | #endif
|
| 26 | |
| 27 | #include <gr_ofdm_sampler.h> |
| 28 | #include <gr_io_signature.h> |
| 29 | #include <gr_expj.h> |
| 30 | |
| 31 | gr_ofdm_sampler_sptr |
| 32 | gr_make_ofdm_sampler (unsigned int fft_length, |
| 33 | unsigned int symbol_length) |
| 34 | {
|
| 35 | return gr_ofdm_sampler_sptr (new gr_ofdm_sampler (fft_length, symbol_length)); |
| 36 | } |
| 37 | |
| 38 | gr_ofdm_sampler::gr_ofdm_sampler (unsigned int fft_length, |
| 39 | unsigned int symbol_length) |
| 40 | : gr_block ("ofdm_sampler",
|
| 41 | gr_make_io_signature2 (2, 2, sizeof (gr_complex), sizeof(char)), |
| 42 | gr_make_io_signature (1, 1, sizeof (gr_complex)*fft_length)), |
| 43 | d_fft_length(fft_length), d_symbol_length(symbol_length) |
| 44 | {
|
| 45 | } |
| 46 | |
| 47 | void
|
| 48 | gr_ofdm_sampler::forecast (int noutput_items, gr_vector_int &ninput_items_required)
|
| 49 | {
|
| 50 | // FIXME do we need more
|
| 51 | int nreqd = (noutput_items-1) * d_symbol_length + d_fft_length; |
| 52 | unsigned ninputs = ninput_items_required.size ();
|
| 53 | for (unsigned i = 0; i < ninputs; i++) |
| 54 | ninput_items_required[i] = nreqd; |
| 55 | } |
| 56 | |
| 57 | int
|
| 58 | gr_ofdm_sampler::general_work (int noutput_items,
|
| 59 | gr_vector_int &ninput_items, |
| 60 | gr_vector_const_void_star &input_items, |
| 61 | gr_vector_void_star &output_items) |
| 62 | {
|
| 63 | gr_complex *iptr = (gr_complex *) input_items[0];
|
| 64 | char *trigger = (char *) input_items[1]; |
| 65 | |
| 66 | gr_complex *optr = (gr_complex *) output_items[0];
|
| 67 | |
| 68 | int found=0; |
| 69 | |
| 70 | int i=d_fft_length-1; |
| 71 | |
| 72 | while(!found && i<std::min(ninput_items[0],ninput_items[1]) ) { |
| 73 | if(trigger[i])
|
| 74 | found = 1;
|
| 75 | else
|
| 76 | i++; |
| 77 | } |
| 78 | |
| 79 | if(found) {
|
| 80 | assert(i-d_fft_length+1 >= 0); |
| 81 | for(int j=i-d_fft_length+1;j<=i;j++) |
| 82 | *optr++ = iptr[j]; |
| 83 | consume_each(i-d_fft_length+2);
|
| 84 | //printf("OFDM Sampler found: ninput_items: %d/%d noutput_items: %d consumed: %d found: %d\n",
|
| 85 | // ninput_items[0], ninput_items[1], noutput_items, (i-d_fft_length+2), found);
|
| 86 | } |
| 87 | else {
|
| 88 | consume_each(i-d_fft_length+1);
|
| 89 | //printf("OFDM Sampler not found: ninput_items: %d/%d noutput_items: %d consumed: %d found: %d\n",
|
| 90 | // ninput_items[0], ninput_items[1], noutput_items, (i-d_fft_length+1), found);
|
| 91 | } |
| 92 | |
| 93 | return found;
|
| 94 | } |