summaryrefslogtreecommitdiff
path: root/cesar/ce/rx/bitloading/inc/ber.h
blob: 2d3b268e750696ceec2c88f1a8244ce0c14c184e (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
#ifndef ce_rx_bitloading_inc_ber_h
#define ce_rx_bitloading_inc_ber_h
/* Cesar project {{{
 *
 * Copyright (C) 2009 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    ce/rx/bitloading/inc/ber.h
 * \brief   Functions to compute BER.
 * \ingroup ce_rx
 *
 * This module contains some sets of functions to compute the BER from a given
 * NSR and modulation.
 */

#include "ce/rx/bitloading/bitloading.h"
#include "ce/common/mod.h"
#include "hal/phy/defs.h"
#include "ce/rx/inc/measure.h"

/**
 * Degree maximum of polynomial.
 */
#define CE_RX_BL_BER_POLY_MAX_DEGREE 2

/**
 * Default theoretical BER value when NSR is under range.
 */
#define CE_RX_BL_BER_DEFAULT_UNDER 0

/**
 * Default theoretical BER value when NSR is over range.
 */
#define CE_RX_BL_BER_DEFAULT_OVER (1ll << 52)

/**
 * BER quantification factor.
 */
#define CE_RX_BL_BER_QUANT_FACTOR (1ll << 53)

/**
 * Number maximum of polynomial per modulation.
 */
#define CE_RX_BL_BER_POLY_PER_MOD 10

/**
 * Quantification factor for the bit per tone.
 */
#define CE_RX_BL_BPT_QUANT_FACTOR (1ull << 8)

/**
 * Polynomials for each modulation to compute BER.
 */
struct ce_rx_bl_ber_poly_coef_t
{
    /**
     * Count of polynomial.
     */
    u8 poly_count;
    /**
     * Polynomial degree.
     */
    u8 degree[CE_RX_BL_BER_POLY_PER_MOD];
    /**
     * Table of coefficients.
     */
    s64 coef[CE_RX_BL_BER_POLY_PER_MOD][CE_RX_BL_BER_POLY_MAX_DEGREE + 1];
    /**
     * Range of NSR (entry) value supported by the polynomial function.
     * First index is min, last one is max.
     */
    u32 range[1 + CE_RX_BL_BER_POLY_PER_MOD];
};
typedef struct ce_rx_bl_ber_poly_coef_t ce_rx_bl_ber_poly_coef_t;

/**
 * Polynomials coefficients for the bit loading.
 * They work for NSR based on sound and data.
 */
extern ce_rx_bl_ber_poly_coef_t
ce_rx_bl_ber_poly_coef[CE_MOD_COUNT - 1];

/**
 * Initial value of the bit per tone goal to reach for the bit loading
 * initial.
 * It depends on the FEC rate. It corresponds to the "worst case" consign.
 */
extern const u64 ce_rx_bl_initial_bpt[PHY_FEC_RATE_NB];

/**
 * Margin to apply to BER target before usage in bit loading algorithm.
 */
extern s64 ce_rx_bl_ber_margin_[PHY_FEC_RATE_NB];

BEGIN_DECLS

/**
 * Compute the theoretical BER from a NSR and a modulation.
 * \param  poly  the polynomial to use.
 * \param  nsr  the current NSR.
 * \param  mod_index  the index of the modulation.
 * \return  the computed BER for this modulation and current NSR.
 */
u64
ce_rx_bl_ber_for_mod (ce_rx_bl_ber_poly_coef_t poly[CE_MOD_COUNT - 1],
                      u32 nsr, u8 mod_index);

/**
 * Compute the theoretical BER from a NSR (sound based) and a modulation.
 * \param  nsr  the current NSR.
 * \param  mod_index  the index of the modulation.
 * \return  the computed BER for this modulation and current NSR.
 */
#define ce_rx_bl_ber_for_mod_initial(nsr, mod_index) \
    ce_rx_bl_ber_for_mod (ce_rx_bl_ber_poly_coef, (nsr), (mod_index))

/**
 * Get modulations around a corresponding to a BER consign based on a NSR.
 * \param[in]  poly  polynomial coefficient to use.
 * \param[in]  nsr  mean of NSR.
 * \param[in]  ber_pt  BER consign.
 * \param[out]  mod_lower  modulation just under ber_pt.
 * \param[out]  ber_lower  BER of the modulation just under ber_pt.
 * \param[out]  ber_upper  BER of the modulation just over ber_pt.
 *
 * This function is used when you want to know the modulation that will
 * respect a given BER consign for a specific NSR.
 */
void
ce_rx_bl_ber_vs_nsr (ce_rx_bl_ber_poly_coef_t poly[CE_MOD_COUNT - 1], u32 nsr,
                     u64 ber_pt, u8 *mod_lower, u64 *ber_lower,
                     u64 *ber_upper);

/**
 * Compute the BER pt to reach according to the FEC rate, the number of used
 * carrier in the tone mask and the bits per tone.
 * \param  fec_rate  the FEC rate.
 * \param  carrier_nb  number of used carrier in tone mask.
 * \param  bpt  bit per tone.
 * \return  the BER pt.
 */
u64
ce_rx_bl_ber_pt_bpt (phy_fecrate_t fec_rate, uint carrier_nb, u64 bpt);

/**
 * Change margin to apply to BER target before usage in the bit loading
 * algorithms.
 * \param  margin_q  margin to apply to BER target (depend on FEC rate)
 */
void
ce_rx_bl_ber_margin_set (s64 margin_q[PHY_FEC_RATE_NB]);

/**
 * Update BER sliding means with received measures on a frame.
 * \param  bl  the bit loading structure of the station
 * \param  ber  the BER in quantified on the received frame
 */
void
ce_rx_bl_ber_sliding_mean_update (ce_rx_bitloading_t *bl, u64 ber);

/**
 * From a BER sum on a frame, compute the BER in quantified.
 * \param  ber_sum  the sum of BER on a frame
 * \param  good_crc_pb_count  the count of PB with good CRC on the frame
 * \param  pb_size  the size of the PB
 * \return  the BER in in quantified format
 */
u64
ce_rx_bl_ber_quantify (ce_rx_measure_mbox_t *measure, u64 ber_reached,
                       u16 pb_size);

/**
 * Get theoretical BER target for a ROBO tone map.
 * \param  carrier_nb  number of used carrier in tone mask.
 * \return  theoretical BER target of a ROBO tone map.
 */
u64
ce_rx_bl_ber_pt_robo (uint carrier_nb);

END_DECLS

#endif /* ce_rx_bitloading_inc_ber_h */