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