GNU Radio 3.5.1 C++ API
digital_ofdm_frame_acquisition.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2006,2007,2011 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef INCLUDED_DIGITAL_OFDM_FRAME_ACQUISITION_H
00024 #define INCLUDED_DIGITAL_OFDM_FRAME_ACQUISITION_H
00025 
00026 #include <digital_api.h>
00027 #include <gr_block.h>
00028 #include <vector>
00029 
00030 class digital_ofdm_frame_acquisition;
00031 typedef boost::shared_ptr<digital_ofdm_frame_acquisition> digital_ofdm_frame_acquisition_sptr;
00032 
00033 digital_ofdm_frame_acquisition_sptr 
00034 DIGITAL_API digital_make_ofdm_frame_acquisition (unsigned int occupied_carriers, unsigned int fft_length,
00035                                 unsigned int cplen,
00036                                 const std::vector<gr_complex> &known_symbol, 
00037                                 unsigned int max_fft_shift_len=10);
00038 
00039 /*!
00040  * \brief take a vector of complex constellation points in from an FFT
00041  * and performs a correlation and equalization.
00042  * \ingroup demodulation_blk
00043  * \ingroup ofdm_blk
00044  *
00045  * This block takes the output of an FFT of a received OFDM symbol and finds the 
00046  * start of a frame based on two known symbols. It also looks at the surrounding
00047  * bins in the FFT output for the correlation in case there is a large frequency
00048  * shift in the data. This block assumes that the fine frequency shift has already
00049  * been corrected and that the samples fall in the middle of one FFT bin.
00050  *
00051  * It then uses one of those known
00052  * symbols to estimate the channel response over all subcarriers and does a simple 
00053  * 1-tap equalization on all subcarriers. This corrects for the phase and amplitude
00054  * distortion caused by the channel.
00055  */
00056 
00057 class DIGITAL_API digital_ofdm_frame_acquisition : public gr_block
00058 {
00059   /*! 
00060    * \brief Build an OFDM correlator and equalizer.
00061    * \param occupied_carriers   The number of subcarriers with data in the received symbol
00062    * \param fft_length          The size of the FFT vector (occupied_carriers + unused carriers)
00063    * \param cplen               The length of the cycle prefix
00064    * \param known_symbol        A vector of complex numbers representing a known symbol at the
00065    *                            start of a frame (usually a BPSK PN sequence)
00066    * \param max_fft_shift_len   Set's the maximum distance you can look between bins for correlation
00067    */
00068   friend DIGITAL_API digital_ofdm_frame_acquisition_sptr
00069   digital_make_ofdm_frame_acquisition (unsigned int occupied_carriers, unsigned int fft_length,
00070                                   unsigned int cplen,
00071                                   const std::vector<gr_complex> &known_symbol, 
00072                                   unsigned int max_fft_shift_len);
00073   
00074 protected:
00075   digital_ofdm_frame_acquisition (unsigned int occupied_carriers, unsigned int fft_length,
00076                              unsigned int cplen,
00077                              const std::vector<gr_complex> &known_symbol, 
00078                              unsigned int max_fft_shift_len);
00079   
00080  private:
00081   unsigned char slicer(gr_complex x);
00082   void correlate(const gr_complex *symbol, int zeros_on_left);
00083   void calculate_equalizer(const gr_complex *symbol, int zeros_on_left);
00084   gr_complex coarse_freq_comp(int freq_delta, int count);
00085   
00086   unsigned int d_occupied_carriers;  // !< \brief number of subcarriers with data
00087   unsigned int d_fft_length;         // !< \brief length of FFT vector
00088   unsigned int d_cplen;              // !< \brief length of cyclic prefix in samples
00089   unsigned int d_freq_shift_len;     // !< \brief number of surrounding bins to look at for correlation
00090   std::vector<gr_complex> d_known_symbol; // !< \brief known symbols at start of frame
00091   std::vector<float> d_known_phase_diff; // !< \brief factor used in correlation from known symbol
00092   std::vector<float> d_symbol_phase_diff; // !< \brief factor used in correlation from received symbol
00093   std::vector<gr_complex> d_hestimate;  // !< channel estimate
00094   int d_coarse_freq;             // !< \brief search distance in number of bins
00095   unsigned int d_phase_count;           // !< \brief accumulator for coarse freq correction
00096   float d_snr_est;                      // !< an estimation of the signal to noise ratio
00097 
00098   gr_complex *d_phase_lut;  // !< look-up table for coarse frequency compensation
00099 
00100   void forecast(int noutput_items, gr_vector_int &ninput_items_required);
00101 
00102  public:
00103   /*!
00104    * \brief Return an estimate of the SNR of the channel
00105    */
00106   float snr() { return d_snr_est; }
00107 
00108   ~digital_ofdm_frame_acquisition(void);
00109   int general_work(int noutput_items,
00110                    gr_vector_int &ninput_items,
00111                    gr_vector_const_void_star &input_items,
00112                    gr_vector_void_star &output_items);
00113 };
00114 
00115 
00116 #endif