summaryrefslogtreecommitdiff
path: root/gr-digital/include/digital_impl_mpsk_snr_est.h
blob: df7dbadec106f830cfa45a953c089f5ebe485db5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/* -*- c++ -*- */
/*
 * Copyright 2011 Free Software Foundation, Inc.
 * 
 * This file is part of GNU Radio
 * 
 * GNU Radio is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 * 
 * GNU Radio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with GNU Radio; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */
#ifndef INCLUDED_DIGITAL_IMPL_MPSK_SNR_EST_H
#define INCLUDED_DIGITAL_IMPL_MPSK_SNR_EST_H

#include <digital_api.h>
#include <gr_sync_block.h>

//! Enum for the type of SNR estimator to select
/*! \ingroup snr_blk
 *  \anchor ref_snr_est_types
 *
 * Below are some ROUGH estimates of what values of SNR each of these
 * types of estimators is good for. In general, these offer a
 * trade-off between accuracy and performance.
 *
 * \li SNR_EST_SIMPLE:  Simple estimator (>= 7 dB)
 * \li SNR_EST_SKEW:    Skewness-base est (>= 5 dB)
 * \li SNR_EST_M2M4:    2nd & 4th moment est (>= 1 dB)
 * \li SNR_EST_SVR:     SVR-based est (>= 0dB)
*/
enum snr_est_type_t {
  SNR_EST_SIMPLE = 0,	// Simple estimator (>= 7 dB)
  SNR_EST_SKEW,	        // Skewness-base est (>= 5 dB)
  SNR_EST_M2M4,         // 2nd & 4th moment est (>= 1 dB)
  SNR_EST_SVR           // SVR-based est (>= 0dB)
};

/*! \brief A parent class for SNR estimators, specifically for M-PSK
 *  signals in AWGN channels.
 *  \ingroup snr_blk
 */
class DIGITAL_API digital_impl_mpsk_snr_est
{
 protected:
  double d_alpha, d_beta;

 public:
  /*! Constructor
   *
   *  Parameters:
   *  \param alpha: the update rate of internal running average
   *  calculations.
   */
  digital_impl_mpsk_snr_est(double alpha);
  virtual ~digital_impl_mpsk_snr_est();

  //! Get the running-average coefficient
  double alpha() const;

  //! Set the running-average coefficient
  void set_alpha(double alpha);

  //! Update the current registers
  virtual int update(int noutput_items,
		     const gr_complex *in);

  //! Use the register values to compute a new estimate
  virtual double snr();
};

  
//! \brief SNR Estimator using simple mean/variance estimates.
/*! \ingroup snr_blk
 *
 *  A very simple SNR estimator that just uses mean and variance
 *  estimates of an M-PSK constellation. This esimator is quick and
 *  cheap and accurate for high SNR (above 7 dB or so) but quickly
 *  starts to overestimate the SNR at low SNR.
 */
class DIGITAL_API digital_impl_mpsk_snr_est_simple :
  public digital_impl_mpsk_snr_est
{
 private:
  double d_y1, d_y2;
  
 public:
  /*! Constructor
   *
   *  Parameters:
   *  \param alpha: the update rate of internal running average
   *  calculations.
   */
  digital_impl_mpsk_snr_est_simple(double alpha);
  ~digital_impl_mpsk_snr_est_simple() {}

  int update(int noutput_items,
	     const gr_complex *in);
  double snr();
};


//! \brief SNR Estimator using skewness correction.
/*!  \ingroup snr_blk
 *
 *  This is an estimator that came from a discussion between Tom
 *  Rondeau and fred harris with no known paper reference. The idea is
 *  that at low SNR, the variance estimations will be affected because
 *  of fold-over around the decision boundaries, which results in a
 *  skewness to the samples. We estimate the skewness and use this as
 *  a correcting term.
 */
class DIGITAL_API digital_impl_mpsk_snr_est_skew :
  public digital_impl_mpsk_snr_est
{
 private:
  double d_y1, d_y2, d_y3;
  
 public:
  /*! Constructor
   *
   *  Parameters:
   *  \param alpha: the update rate of internal running average
   *  calculations.
   */
  digital_impl_mpsk_snr_est_skew(double alpha);
  ~digital_impl_mpsk_snr_est_skew() {}

  int update(int noutput_items,
	     const gr_complex *in);
  double snr();
};


//! \brief SNR Estimator using 2nd and 4th-order moments.
/*! \ingroup snr_blk
 *
 *  An SNR estimator for M-PSK signals that uses 2nd (M2) and 4th (M4)
 *  order moments. This estimator uses knowledge of the kurtosis of
 *  the signal (k_a) and noise (k_w) to make its estimation. We use
 *  Beaulieu's approximations here to M-PSK signals and AWGN channels
 *  such that k_a=1 and k_w=2. These approximations significantly
 *  reduce the complexity of the calculations (and computations)
 *  required.
 *
 *  Reference:
 *  D. R. Pauluzzi and N. C. Beaulieu, "A comparison of SNR
 *  estimation techniques for the AWGN channel," IEEE
 *  Trans. Communications, Vol. 48, No. 10, pp. 1681-1691, 2000.
 */
class DIGITAL_API digital_impl_mpsk_snr_est_m2m4 :
  public digital_impl_mpsk_snr_est
{
 private:
  double d_y1, d_y2;
  
 public:
  /*! Constructor
   *
   *  Parameters:
   *  \param alpha: the update rate of internal running average
   *  calculations.
   */
  digital_impl_mpsk_snr_est_m2m4(double alpha);
  ~digital_impl_mpsk_snr_est_m2m4() {}

  int update(int noutput_items,
	     const gr_complex *in);
  double snr();
};


//! \brief SNR Estimator using 2nd and 4th-order moments.
/*!  \ingroup snr_blk
 *
 *  An SNR estimator for M-PSK signals that uses 2nd (M2) and 4th (M4)
 *  order moments. This estimator uses knowledge of the kurtosis of
 *  the signal (k_a) and noise (k_w) to make its estimation. In this
 *  case, you can set your own estimations for k_a and k_w, the
 *  kurtosis of the signal and noise, to fit this estimation better to
 *  your signal and channel conditions.
 *
 *  A word of warning: this estimator has not been fully tested or
 *  proved with any amount of rigor. The estimation for M4 in
 *  particular might be ignoring effectf of when k_a and k_w are
 *  different. Use this estimator with caution and a copy of the
 *  reference on hand.
 *
 *  The digital_mpsk_snr_est_m2m4 assumes k_a and k_w to simplify the
 *  computations for M-PSK and AWGN channels. Use that estimator
 *  unless you have a way to guess or estimate these values here.
 *
 *  Original paper: 
 *  R. Matzner, "An SNR estimation algorithm for complex baseband
 *  signal using higher order statistics," Facta Universitatis
 *  (Nis), no. 6, pp. 41-52, 1993.
 *
 *  Reference used in derivation:
 *  D. R. Pauluzzi and N. C. Beaulieu, "A comparison of SNR
 *  estimation techniques for the AWGN channel," IEEE
 *  Trans. Communications, Vol. 48, No. 10, pp. 1681-1691, 2000.
 */
class DIGITAL_API digital_impl_snr_est_m2m4 :
  public digital_impl_mpsk_snr_est
{
 private:
  double d_y1, d_y2;
  double d_ka, d_kw;
  
 public:
  /*! Constructor
   *
   *  Parameters:
   *  \param alpha: the update rate of internal running average
   *  calculations.
   *  \param ka: estimate of the signal kurtosis (1 for PSK)
   *  \param kw: estimate of the channel noise kurtosis (2 for AWGN)
   */
  digital_impl_snr_est_m2m4(double alpha, double ka, double kw);
  ~digital_impl_snr_est_m2m4() {}

  int update(int noutput_items,
	     const gr_complex *in);
  double snr();
};


//! \brief Signal-to-Variation Ratio SNR Estimator.
/*! \ingroup snr_blk
 *
 *  This estimator actually comes from an SNR estimator for M-PSK
 *  signals in fading channels, but this implementation is
 *  specifically for AWGN channels. The math was simplified to assume
 *  a signal and noise kurtosis (k_a and k_w) for M-PSK signals in
 *  AWGN. These approximations significantly reduce the complexity of
 *  the calculations (and computations) required.
 *
 *  Original paper:
 *  A. L. Brandao, L. B. Lopes, and D. C. McLernon, "In-service
 *  monitoring of multipath delay and cochannel interference for
 *  indoor mobile communication systems," Proc. IEEE
 *  Int. Conf. Communications, vol. 3, pp. 1458-1462, May 1994.
 *
 *  Reference:
 *  D. R. Pauluzzi and N. C. Beaulieu, "A comparison of SNR
 *  estimation techniques for the AWGN channel," IEEE
 *  Trans. Communications, Vol. 48, No. 10, pp. 1681-1691, 2000.
 */
class DIGITAL_API digital_impl_mpsk_snr_est_svr :
  public digital_impl_mpsk_snr_est
{
 private:
  double d_y1, d_y2;
  
 public:
  /*! Constructor
   *
   *  Parameters:
   *  \param alpha: the update rate of internal running average
   *  calculations.
   */
  digital_impl_mpsk_snr_est_svr(double alpha);
  ~digital_impl_mpsk_snr_est_svr() {}

  int update(int noutput_items,
	     const gr_complex *in);
  double snr();
};

#endif /* INCLUDED_DIGITAL_IMPL_MPSK_SNR_EST_H */