Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / general / gr_ofdm_frame_acquisition.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006, 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 #ifndef INCLUDED_GR_OFDM_FRAME_ACQUISITION_H
24 #define INCLUDED_GR_OFDM_FRAME_ACQUISITION_H
25
26
27 #include <gr_block.h>
28 #include <vector>
29
30 class gr_ofdm_frame_acquisition;
31 typedef boost::shared_ptr<gr_ofdm_frame_acquisition> gr_ofdm_frame_acquisition_sptr;
32
33 gr_ofdm_frame_acquisition_sptr 
34 gr_make_ofdm_frame_acquisition (unsigned int occupied_carriers, unsigned int fft_length,
35                                 unsigned int cplen,
36                                 const std::vector<gr_complex> &known_symbol, 
37                                 unsigned int max_fft_shift_len=10);
38
39 /*!
40  * \brief take a vector of complex constellation points in from an FFT
41  * and performs a correlation and equalization.
42  * \ingroup demodulation_blk
43  * \ingroup ofdm_blk
44  *
45  * This block takes the output of an FFT of a received OFDM symbol and finds the 
46  * start of a frame based on two known symbols. It also looks at the surrounding
47  * bins in the FFT output for the correlation in case there is a large frequency
48  * shift in the data. This block assumes that the fine frequency shift has already
49  * been corrected and that the samples fall in the middle of one FFT bin.
50  *
51  * It then uses one of those known
52  * symbols to estimate the channel response over all subcarriers and does a simple 
53  * 1-tap equalization on all subcarriers. This corrects for the phase and amplitude
54  * distortion caused by the channel.
55  */
56
57 class gr_ofdm_frame_acquisition : public gr_block
58 {
59   /*! 
60    * \brief Build an OFDM correlator and equalizer.
61    * \param occupied_carriers   The number of subcarriers with data in the received symbol
62    * \param fft_length          The size of the FFT vector (occupied_carriers + unused carriers)
63    * \param cplen               The length of the cycle prefix
64    * \param known_symbol        A vector of complex numbers representing a known symbol at the
65    *                            start of a frame (usually a BPSK PN sequence)
66    * \param max_fft_shift_len   Set's the maximum distance you can look between bins for correlation
67    */
68   friend gr_ofdm_frame_acquisition_sptr
69   gr_make_ofdm_frame_acquisition (unsigned int occupied_carriers, unsigned int fft_length,
70                                   unsigned int cplen,
71                                   const std::vector<gr_complex> &known_symbol, 
72                                   unsigned int max_fft_shift_len);
73   
74 protected:
75   gr_ofdm_frame_acquisition (unsigned int occupied_carriers, unsigned int fft_length,
76                              unsigned int cplen,
77                              const std::vector<gr_complex> &known_symbol, 
78                              unsigned int max_fft_shift_len);
79   
80  private:
81   unsigned char slicer(gr_complex x);
82   void correlate(const gr_complex *symbol, int zeros_on_left);
83   void calculate_equalizer(const gr_complex *symbol, int zeros_on_left);
84   gr_complex coarse_freq_comp(int freq_delta, int count);
85   
86   unsigned int d_occupied_carriers;  // !< \brief number of subcarriers with data
87   unsigned int d_fft_length;         // !< \brief length of FFT vector
88   unsigned int d_cplen;              // !< \brief length of cyclic prefix in samples
89   unsigned int d_freq_shift_len;     // !< \brief number of surrounding bins to look at for correlation
90   std::vector<gr_complex> d_known_symbol; // !< \brief known symbols at start of frame
91   std::vector<float> d_known_phase_diff; // !< \brief factor used in correlation from known symbol
92   std::vector<float> d_symbol_phase_diff; // !< \brief factor used in correlation from received symbol
93   std::vector<gr_complex> d_hestimate;  // !< channel estimate
94   int d_coarse_freq;             // !< \brief search distance in number of bins
95   unsigned int d_phase_count;           // !< \brief accumulator for coarse freq correction
96   float d_snr_est;                      // !< an estimation of the signal to noise ratio
97
98   gr_complex *d_phase_lut;  // !< look-up table for coarse frequency compensation
99
100   void forecast(int noutput_items, gr_vector_int &ninput_items_required);
101
102  public:
103   /*!
104    * \brief Return an estimate of the SNR of the channel
105    */
106   float snr() { return d_snr_est; }
107
108   ~gr_ofdm_frame_acquisition(void);
109   int general_work(int noutput_items,
110                    gr_vector_int &ninput_items,
111                    gr_vector_const_void_star &input_items,
112                    gr_vector_void_star &output_items);
113 };
114
115
116 #endif