GNU Radio 3.6.3.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 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  //! Returns the modulation order (M) currently set
95  float modulation_order() const { return d_M; }
96 
97  //! Returns current value of theta
98  float theta() const { return d_theta; }
99 
100  //! Returns current value of mu
101  float mu() const { return d_mu; }
102 
103  //! Returns current value of omega
104  float omega() const { return d_omega; }
105 
106  //! Returns mu gain factor
107  float gain_mu() const { return d_gain_mu; }
108 
109  //! Returns omega gain factor
110  float gain_omega() const { return d_gain_omega; }
111 
112  //! Returns the relative omega limit
113  float gain_omega_rel() const {return d_omega_rel; }
114 
115  //! Sets the modulation order (M) currently
116  void set_modulation_order(unsigned int M);
117 
118  //! Sets value of theta
119  void set_theta(float theta) { d_theta = theta; }
120 
121  //! Sets value of mu
122  void set_mu (float mu) { d_mu = mu; }
123 
124  //! Sets value of omega and its min and max values
125  void set_omega (float omega) {
126  d_omega = omega;
127  d_min_omega = omega*(1.0 - d_omega_rel);
128  d_max_omega = omega*(1.0 + d_omega_rel);
129  d_omega_mid = 0.5*(d_min_omega+d_max_omega);
130  }
131 
132  //! Sets value for mu gain factor
133  void set_gain_mu (float gain_mu) { d_gain_mu = gain_mu; }
134 
135  //! Sets value for omega gain factor
136  void set_gain_omega (float gain_omega) { d_gain_omega = gain_omega; }
137 
138  //! Sets the relative omega limit and resets omega min/max values
139  void set_gain_omega_rel(float omega_rel);
140 
141 protected:
142 
143  /*!
144  * \brief Constructor to synchronize incoming M-PSK symbols
145  *
146  * \param M modulation order of the M-PSK modulation
147  * \param theta any constant phase rotation from the real axis of the constellation
148  * \param loop_bw Loop bandwidth to set gains of phase/freq tracking loop
149  * \param fmin minimum normalized frequency value the loop can achieve
150  * \param fmax maximum normalized frequency value the loop can achieve
151  * \param mu initial parameter for the interpolator [0,1]
152  * \param gain_mu gain parameter of the M&M error signal to adjust mu (~0.05)
153  * \param omega initial value for the number of symbols between samples (~number of samples/symbol)
154  * \param gain_omega gain parameter to adjust omega based on the error (~omega^2/4)
155  * \param omega_rel sets the maximum (omega*(1+omega_rel)) and minimum (omega*(1+omega_rel)) omega (~0.005)
156  *
157  * The constructor also chooses which phase detector and decision maker to use in the work loop based on the
158  * value of M.
159  */
160  digital_mpsk_receiver_cc (unsigned int M, float theta,
161  float loop_bw,
162  float fmin, float fmax,
163  float mu, float gain_mu,
164  float omega, float gain_omega, float omega_rel);
165 
166  void make_constellation();
167  void mm_sampler(const gr_complex symbol);
168  void mm_error_tracking(gr_complex sample);
169  void phase_error_tracking(gr_complex sample);
170 
171 
172  /*!
173  * \brief Phase error detector for MPSK modulations.
174  *
175  * \param sample the I&Q sample from which to determine the phase error
176  *
177  * This function determines the phase error for any MPSK signal by
178  * creating a set of PSK constellation points and doing a
179  * brute-force search to see which point minimizes the Euclidean
180  * distance. This point is then used to derotate the sample to the
181  * real-axis and a atan (using the fast approximation function) to
182  * determine the phase difference between the incoming sample and
183  * the real constellation point
184  *
185  * This should be cleaned up and made more efficient.
186  *
187  * \returns the approximated phase error.
188  */
189  float phase_error_detector_generic(gr_complex sample) const; // generic for M but more costly
190 
191  /*!
192  * \brief Phase error detector for BPSK modulation.
193  *
194  * \param sample the I&Q sample from which to determine the phase error
195  *
196  * This function determines the phase error using a simple BPSK
197  * phase error detector by multiplying the real and imaginary (the
198  * error signal) components together. As the imaginary part goes to
199  * 0, so does this error.
200  *
201  * \returns the approximated phase error.
202  */
203  float phase_error_detector_bpsk(gr_complex sample) const; // optimized for BPSK
204 
205  /*!
206  * \brief Phase error detector for QPSK modulation.
207  *
208  * \param sample the I&Q sample from which to determine the phase error
209  *
210  * This function determines the phase error using the limiter
211  * approach in a standard 4th order Costas loop
212  *
213  * \returns the approximated phase error.
214  */
215  float phase_error_detector_qpsk(gr_complex sample) const;
216 
217 
218 
219  /*!
220  * \brief Decision maker for a generic MPSK constellation.
221  *
222  * \param sample the baseband I&Q sample from which to make the decision
223  *
224  * This decision maker is a generic implementation that does a
225  * brute-force search for the constellation point that minimizes the
226  * error between it and the incoming signal.
227  *
228  * \returns the index to d_constellation that minimizes the error/
229  */
230  unsigned int decision_generic(gr_complex sample) const;
231 
232 
233  /*!
234  * \brief Decision maker for BPSK constellation.
235  *
236  * \param sample the baseband I&Q sample from which to make the decision
237  *
238  * This decision maker is a simple slicer function that makes a
239  * decision on the symbol based on its placement on the real axis of
240  * greater than 0 or less than 0; the quadrature component is always
241  * 0.
242  *
243  * \returns the index to d_constellation that minimizes the error/
244  */
245  unsigned int decision_bpsk(gr_complex sample) const;
246 
247 
248  /*!
249  * \brief Decision maker for QPSK constellation.
250  *
251  * \param sample the baseband I&Q sample from which to make the decision
252  *
253  * This decision maker is a simple slicer function that makes a
254  * decision on the symbol based on its placement versus both axes
255  * and returns which quadrant the symbol is in.
256  *
257  * \returns the index to d_constellation that minimizes the error/
258  */
259  unsigned int decision_qpsk(gr_complex sample) const;
260 
261 private:
262  unsigned int d_M;
263  float d_theta;
264 
265  /*!
266  * \brief Decision maker function pointer
267  *
268  * \param sample the baseband I&Q sample from which to make the decision
269  *
270  * This is a function pointer that is set in the constructor to
271  * point to the proper decision function for the specified
272  * constellation order.
273  *
274  * \return index into d_constellation point that is the closest to the recieved sample
275  */
276  unsigned int (digital_mpsk_receiver_cc::*d_decision)(gr_complex sample) const; // pointer to decision function
277 
278 
279  std::vector<gr_complex> d_constellation;
280  unsigned int d_current_const_point;
281 
282  // Members related to symbol timing
283  float d_mu, d_gain_mu;
284  float d_omega, d_gain_omega, d_omega_rel, d_max_omega, d_min_omega, d_omega_mid;
285  gr_complex d_p_2T, d_p_1T, d_p_0T;
286  gr_complex d_c_2T, d_c_1T, d_c_0T;
287 
288  /*!
289  * \brief Phase error detector function pointer
290  *
291  * \param sample the I&Q sample from which to determine the phase error
292  *
293  * This is a function pointer that is set in the constructor to
294  * point to the proper phase error detector function for the
295  * specified constellation order.
296  */
297  float (digital_mpsk_receiver_cc::*d_phase_error_detector)(gr_complex sample) const;
298 
299 
300  //! get interpolated value
302 
303  //! delay line length.
304  static const unsigned int DLLEN = 8;
305 
306  //! delay line plus some length for overflow protection
307  __GR_ATTR_ALIGNED(8) gr_complex d_dl[2*DLLEN];
308 
309  //! index to delay line
310  unsigned int d_dl_idx;
311 
313  digital_make_mpsk_receiver_cc (unsigned int M, float theta,
314  float loop_bw,
315  float fmin, float fmax,
316  float mu, float gain_mu,
317  float omega, float gain_omega, float omega_rel);
318 };
319 
320 #endif