GNU Radio C++ API
digital_mpsk_receiver_cc.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,2007,2011 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_DIGITAL_MPSK_RECEIVER_CC_H
24 #define INCLUDED_DIGITAL_MPSK_RECEIVER_CC_H
25 
26 #include <digital_api.h>
27 #include <gruel/attributes.h>
28 #include <gri_control_loop.h>
29 #include <gr_block.h>
30 #include <gr_complex.h>
31 #include <fstream>
32 
34 
37 
38 // public constructor
40 digital_make_mpsk_receiver_cc (unsigned int M, float theta,
41  float loop_bw,
42  float fmin, float fmax,
43  float mu, float gain_mu,
44  float omega, float gain_omega, float omega_rel);
45 
46 /*!
47  * \brief This block takes care of receiving M-PSK modulated signals
48  * through phase, frequency, and symbol synchronization.
49  * \ingroup sync_blk
50  * \ingroup demod_blk
51  * \ingroup digital
52  *
53  * This block takes care of receiving M-PSK modulated signals through
54  * phase, frequency, and symbol synchronization. It performs carrier
55  * frequency and phase locking as well as symbol timing recovery. It
56  * works with (D)BPSK, (D)QPSK, and (D)8PSK as tested currently. It
57  * should also work for OQPSK and PI/4 DQPSK.
58  *
59  * The phase and frequency synchronization are based on a Costas loop
60  * that finds the error of the incoming signal point compared to its
61  * nearest constellation point. The frequency and phase of the NCO are
62  * updated according to this error. There are optimized phase error
63  * detectors for BPSK and QPSK, but 8PSK is done using a brute-force
64  * computation of the constellation points to find the minimum.
65  *
66  * The symbol synchronization is done using a modified Mueller and
67  * Muller circuit from the paper:
68  *
69  * G. R. Danesfahani, T.G. Jeans, "Optimisation of modified Mueller
70  * and Muller algorithm," Electronics Letters, Vol. 31, no. 13, 22
71  * June 1995, pp. 1032 - 1033.
72  *
73  * This circuit interpolates the downconverted sample (using the NCO
74  * developed by the Costas loop) every mu samples, then it finds the
75  * sampling error based on this and the past symbols and the decision
76  * made on the samples. Like the phase error detector, there are
77  * optimized decision algorithms for BPSK and QPKS, but 8PSK uses
78  * another brute force computation against all possible symbols. The
79  * modifications to the M&M used here reduce self-noise.
80  *
81  */
82 
84 {
85  public:
87  void forecast(int noutput_items, gr_vector_int &ninput_items_required);
88  int general_work (int noutput_items,
89  gr_vector_int &ninput_items,
90  gr_vector_const_void_star &input_items,
91  gr_vector_void_star &output_items);
92 
93 
94  // Member functions related to the symbol tracking portion of the receiver
95  //! (M&M) Returns current value of mu
96  float mu() const { return d_mu;}
97 
98  //! (M&M) Returns current value of omega
99  float omega() const { return d_omega;}
100 
101  //! (M&M) Returns mu gain factor
102  float gain_mu() const { return d_gain_mu;}
103 
104  //! (M&M) Returns omega gain factor
105  float gain_omega() const { return d_gain_omega;}
106 
107  //! (M&M) Sets value of mu
108  void set_mu (float mu) { d_mu = mu; }
109 
110  //! (M&M) Sets value of omega and its min and max values
111  void set_omega (float omega) {
112  d_omega = omega;
113  d_min_omega = omega*(1.0 - d_omega_rel);
114  d_max_omega = omega*(1.0 + d_omega_rel);
115  d_omega_mid = 0.5*(d_min_omega+d_max_omega);
116  }
117 
118  //! (M&M) Sets value for mu gain factor
119  void set_gain_mu (float gain_mu) { d_gain_mu = gain_mu; }
120 
121  //! (M&M) Sets value for omega gain factor
122  void set_gain_omega (float gain_omega) { d_gain_omega = gain_omega; }
123 
124 protected:
125 
126  /*!
127  * \brief Constructor to synchronize incoming M-PSK symbols
128  *
129  * \param M modulation order of the M-PSK modulation
130  * \param theta any constant phase rotation from the real axis of the constellation
131  * \param loop_bw Loop bandwidth to set gains of phase/freq tracking loop
132  * \param fmin minimum normalized frequency value the loop can achieve
133  * \param fmax maximum normalized frequency value the loop can achieve
134  * \param mu initial parameter for the interpolator [0,1]
135  * \param gain_mu gain parameter of the M&M error signal to adjust mu (~0.05)
136  * \param omega initial value for the number of symbols between samples (~number of samples/symbol)
137  * \param gain_omega gain parameter to adjust omega based on the error (~omega^2/4)
138  * \param omega_rel sets the maximum (omega*(1+omega_rel)) and minimum (omega*(1+omega_rel)) omega (~0.005)
139  *
140  * The constructor also chooses which phase detector and decision maker to use in the work loop based on the
141  * value of M.
142  */
143  digital_mpsk_receiver_cc (unsigned int M, float theta,
144  float loop_bw,
145  float fmin, float fmax,
146  float mu, float gain_mu,
147  float omega, float gain_omega, float omega_rel);
148 
149  void make_constellation();
150  void mm_sampler(const gr_complex symbol);
151  void mm_error_tracking(gr_complex sample);
152  void phase_error_tracking(gr_complex sample);
153 
154 
155  /*!
156  * \brief Phase error detector for MPSK modulations.
157  *
158  * \param sample the I&Q sample from which to determine the phase error
159  *
160  * This function determines the phase error for any MPSK signal by
161  * creating a set of PSK constellation points and doing a
162  * brute-force search to see which point minimizes the Euclidean
163  * distance. This point is then used to derotate the sample to the
164  * real-axis and a atan (using the fast approximation function) to
165  * determine the phase difference between the incoming sample and
166  * the real constellation point
167  *
168  * This should be cleaned up and made more efficient.
169  *
170  * \returns the approximated phase error.
171  */
172  float phase_error_detector_generic(gr_complex sample) const; // generic for M but more costly
173 
174  /*!
175  * \brief Phase error detector for BPSK modulation.
176  *
177  * \param sample the I&Q sample from which to determine the phase error
178  *
179  * This function determines the phase error using a simple BPSK
180  * phase error detector by multiplying the real and imaginary (the
181  * error signal) components together. As the imaginary part goes to
182  * 0, so does this error.
183  *
184  * \returns the approximated phase error.
185  */
186  float phase_error_detector_bpsk(gr_complex sample) const; // optimized for BPSK
187 
188  /*!
189  * \brief Phase error detector for QPSK modulation.
190  *
191  * \param sample the I&Q sample from which to determine the phase error
192  *
193  * This function determines the phase error using the limiter
194  * approach in a standard 4th order Costas loop
195  *
196  * \returns the approximated phase error.
197  */
198  float phase_error_detector_qpsk(gr_complex sample) const;
199 
200 
201 
202  /*!
203  * \brief Decision maker for a generic MPSK constellation.
204  *
205  * \param sample the baseband I&Q sample from which to make the decision
206  *
207  * This decision maker is a generic implementation that does a
208  * brute-force search for the constellation point that minimizes the
209  * error between it and the incoming signal.
210  *
211  * \returns the index to d_constellation that minimizes the error/
212  */
213  unsigned int decision_generic(gr_complex sample) const;
214 
215 
216  /*!
217  * \brief Decision maker for BPSK constellation.
218  *
219  * \param sample the baseband I&Q sample from which to make the decision
220  *
221  * This decision maker is a simple slicer function that makes a
222  * decision on the symbol based on its placement on the real axis of
223  * greater than 0 or less than 0; the quadrature component is always
224  * 0.
225  *
226  * \returns the index to d_constellation that minimizes the error/
227  */
228  unsigned int decision_bpsk(gr_complex sample) const;
229 
230 
231  /*!
232  * \brief Decision maker for QPSK constellation.
233  *
234  * \param sample the baseband I&Q sample from which to make the decision
235  *
236  * This decision maker is a simple slicer function that makes a
237  * decision on the symbol based on its placement versus both axes
238  * and returns which quadrant the symbol is in.
239  *
240  * \returns the index to d_constellation that minimizes the error/
241  */
242  unsigned int decision_qpsk(gr_complex sample) const;
243 
244 private:
245  unsigned int d_M;
246  float d_theta;
247 
248  /*!
249  * \brief Decision maker function pointer
250  *
251  * \param sample the baseband I&Q sample from which to make the decision
252  *
253  * This is a function pointer that is set in the constructor to
254  * point to the proper decision function for the specified
255  * constellation order.
256  *
257  * \return index into d_constellation point that is the closest to the recieved sample
258  */
259  unsigned int (digital_mpsk_receiver_cc::*d_decision)(gr_complex sample) const; // pointer to decision function
260 
261 
262  std::vector<gr_complex> d_constellation;
263  unsigned int d_current_const_point;
264 
265  // Members related to symbol timing
266  float d_mu, d_gain_mu;
267  float d_omega, d_gain_omega, d_omega_rel, d_max_omega, d_min_omega, d_omega_mid;
268  gr_complex d_p_2T, d_p_1T, d_p_0T;
269  gr_complex d_c_2T, d_c_1T, d_c_0T;
270 
271  /*!
272  * \brief Phase error detector function pointer
273  *
274  * \param sample the I&Q sample from which to determine the phase error
275  *
276  * This is a function pointer that is set in the constructor to
277  * point to the proper phase error detector function for the
278  * specified constellation order.
279  */
280  float (digital_mpsk_receiver_cc::*d_phase_error_detector)(gr_complex sample) const;
281 
282 
283  //! get interpolated value
285 
286  //! delay line length.
287  static const unsigned int DLLEN = 8;
288 
289  //! delay line plus some length for overflow protection
290  __GR_ATTR_ALIGNED(8) gr_complex d_dl[2*DLLEN];
291 
292  //! index to delay line
293  unsigned int d_dl_idx;
294 
296  digital_make_mpsk_receiver_cc (unsigned int M, float theta,
297  float loop_bw,
298  float fmin, float fmax,
299  float mu, float gain_mu,
300  float omega, float gain_omega, float omega_rel);
301 };
302 
303 #endif