40 template class ITPP_EXPORT Modulator<double>;
41 template class ITPP_EXPORT Modulator<std::complex<double> >;
53 "QAM::set_M(): M = " <<
M <<
" is not an even power of 2");
56 double average_energy = (
M - 1) * 2.0 / 3.0;
65 for (
int i = 0; i <
L; i++) {
66 for (
int j = 0; j <
L; j++) {
84 out.set_size(
k*signal.size(),
false);
86 int temp_real, temp_imag;
88 for (
int i = 0; i < signal.size(); i++) {
95 else if (temp_real > (
L - 1))
99 else if (temp_imag > (
L - 1))
101 out.replace_mid(
k*i,
bitmap.get_row(temp_imag *
L + temp_real));
128 double epsilon = delta / 10000.0;
129 std::complex<double> symb;
130 for (
int i = 0; i <
M; i++) {
131 symb = std::complex<double>(std::polar(1.0, delta * i));
132 if (std::fabs(
std::real(symb)) < epsilon) {
135 else if (std::fabs(
std::imag(symb)) < epsilon) {
157 out.set_size(
k*signal.size(),
false);
159 for (
int i = 0; i < signal.size(); i++) {
161 temp = (ang < 0) ? (
m_2pi + ang) : ang;
163 out.replace_mid(i*
k,
bitmap.get_row(est_symbol));
182 soft_bits.set_size(
k * rx_symbols.size());
183 std::complex<double> temp;
185 std::complex<double> exp_pi4 = std::complex<double>(
std::cos(
pi / 4),
187 for (
int i = 0; i < rx_symbols.size(); i++) {
188 temp = rx_symbols(i) * exp_pi4;
189 soft_bits((i << 1) + 1) =
std::real(temp) * factor;
190 soft_bits(i << 1) =
std::imag(temp) * factor;
204 double N0, vec &soft_bits,
207 soft_bits.set_size(2*rx_symbols.size(),
false);
208 std::complex<double> temp;
210 std::complex<double> exp_pi4 = std::complex<double>(
std::cos(
pi / 4),
212 for (
int i = 0; i < rx_symbols.size(); i++) {
213 temp = rx_symbols(i) *
std::conj(channel(i)) * exp_pi4;
214 soft_bits((i << 1) + 1) =
std::real(temp) * factor;
215 soft_bits(i << 1) =
std::imag(temp) * factor;
234 out.set_size(bits.size(),
false);
235 for (
int i = 0; i < bits.size(); i++) {
236 out(i) = (bits(i) == 0 ? 1.0 : -1.0);
242 cvec out(bits.size());
250 out.set_size(signal.size(),
false);
251 for (
int i = 0; i < signal.length(); i++) {
258 bvec out(signal.size());
267 double factor = 4 / N0;
268 soft_bits.set_size(rx_symbols.size(),
false);
270 for (
int i = 0; i < rx_symbols.size(); i++) {
271 soft_bits(i) = factor *
std::real(rx_symbols(i));
286 double N0, vec &soft_bits,
289 double factor = 4 / N0;
290 soft_bits.set_size(rx_symbols.size(),
false);
292 for (
int i = 0; i < rx_symbols.size(); i++) {
312 out.set_size(bits.size(),
false);
313 for (
int i = 0; i < bits.size(); i++) {
314 out(i) = (bits(i) == 0 ? 1.0 : -1.0);
320 vec out(bits.size());
328 out.set_size(signal.size(),
false);
329 for (
int i = 0; i < signal.length(); i++) {
330 out(i) = (signal(i) > 0) ?
bin(0) :
bin(1);
336 bvec out(signal.size());
345 double factor = 4 / N0;
346 soft_bits.set_size(rx_symbols.size(),
false);
348 for (
int i = 0; i < rx_symbols.size(); i++) {
349 soft_bits(i) = factor * rx_symbols(i);
363 double N0, vec &soft_bits,
366 double factor = 4 / N0;
367 soft_bits.set_size(rx_symbols.size(),
false);
369 for (
int i = 0; i < rx_symbols.size(); i++) {
370 soft_bits(i) = factor * (rx_symbols(i) * channel(i));
396 double average_energy = (
sqr(
M) - 1) / 3.0;
399 for (
int i = 0; i <
M; i++) {
414 out.set_size(
k*signal.size(),
false);
416 for (
int i = 0; i < signal.size(); i++) {
421 else if (est_symbol > (
M - 1))
423 out.replace_mid(i*
k,
bitmap.get_row(est_symbol));
429 bvec temp(signal.size());
439 double P0, P1, d0min, d1min, temp;
442 soft_bits.set_size(
k * rx_symbols.size());
445 for (
int l = 0; l < rx_symbols.size(); l++) {
446 for (
int j = 0; j <
M; j++) {
450 for (
int i = 0; i <
k; i++) {
452 for (
int j = 0; j < (M >> 1); j++) {
453 P0 += metric(
S0(i, j));
454 P1 += metric(
S1(i, j));
461 for (
int l = 0; l < rx_symbols.size(); l++) {
462 for (
int j = 0; j <
M; j++) {
465 for (
int i = 0; i <
k; i++) {
467 for (
int j = 0; j < (M >> 1); j++) {
468 temp = metric(
S0(i, j));
469 if (temp < d0min) { d0min = temp; }
470 temp = metric(
S1(i, j));
471 if (temp < d1min) { d1min = temp; }
473 soft_bits(l*
k + i) = (-d0min + d1min) / N0;
489 double N0, vec &soft_bits,
493 double P0, P1, d0min, d1min, temp;
496 soft_bits.set_size(
k * rx_symbols.size());
499 for (
int l = 0; l < rx_symbols.size(); l++) {
500 for (
int j = 0; j <
M; j++) {
502 - channel(l) *
symbols(j))) / N0);
504 for (
int i = 0; i <
k; i++) {
506 for (
int j = 0; j < (M >> 1); j++) {
507 P0 += metric(
S0(i, j));
508 P1 += metric(
S1(i, j));
515 for (
int l = 0; l < rx_symbols.size(); l++) {
516 for (
int j = 0; j <
M; j++) {
519 for (
int i = 0; i <
k; i++) {
521 for (
int j = 0; j < (M >> 1); j++) {
522 temp = metric(
S0(i, j));
523 if (temp < d0min) { d0min = temp; }
524 temp = metric(
S1(i, j));
525 if (temp < d1min) { d1min = temp; }
527 soft_bits(l*
k + i) = (-d0min + d1min) / N0;
555 double average_energy = (
sqr(
M) - 1) / 3.0;
558 for (
int i = 0; i <
M; i++) {
573 out.set_size(
k*signal.size(),
false);
575 for (
int i = 0; i < signal.size(); i++) {
579 else if (est_symbol > (
M - 1))
581 out.replace_mid(i*
k,
bitmap.get_row(est_symbol));
587 bvec temp(signal.size());
virtual void demodulate_soft_bits(const cvec &rx_symbols, double N0, vec &soft_bits, Soft_Method method=LOGMAP) const
Soft demodulator for AWGN channels.
double scaling_factor
Scaling factor used to normalize the average energy to 1.
void demodulate_bits(const cvec &signal, bvec &output) const
Hard demodulation of PAM symbols in complex domain to bits.
void set_M(int M)
Change the size of the signal constellation.
const double m_2pi
Constant 2*Pi.
int L
The square-root of M.
ITPP_EXPORT int round_i(double x)
Round to nearest integer.
int k
Number of bits per modulation symbol.
vec imag(const cvec &data)
Imaginary part of complex values.
double scaling_factor
Scaling factor of square QAM constellation (sqrt((M-1)*2/3))
vec arg(const cvec &data)
Argument (angle)
bool is_even(int x)
Return true if x is an even integer.
int M
Number of modulation symbols.
cvec conj(const cvec &x)
Conjugate of complex value.
void set_M(int M)
Change the size of the signal constellation.
void modulate_bits(const bvec &bits, cvec &output) const
Modulate bits into BPSK symbols in complex domain.
void set_size(int size, bool copy=false)
Set length of vector. if copy = true then keeping the old values.
#define it_assert(t, s)
Abort if t is not true.
void modulate_bits(const bvec &bits, vec &output) const
Modulate bits into BPSK symbols in complex domain.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
Vec< std::complex< double > > symbols
Corresponding modulation symbols (size: M)
imat S0
Matrix where row k contains the constellation points with '0' in bit position k.
void demodulate_bits(const cvec &signal, bvec &output) const
Demodulate noisy BPSK symbols in complex domain into bits.
int gray_code(int x)
Convert to Gray Code.
vec sin(const vec &x)
Sine function.
void set_M(int M)
Set the size of the signal constellation.
virtual void demodulate_soft_bits(const cvec &rx_symbols, double N0, vec &soft_bits, Soft_Method method=LOGMAP) const
Soft demodulator for AWGN channel.
const double pi
Constant Pi.
void demodulate_bits(const cvec &signal, bvec &bits) const
Hard demodulation of bits.
double scaling_factor
Scaling factor used to normalize the average energy to 1.
vec exp(const vec &x)
Exp of the elements of a vector x.
T max(const Vec< T > &v)
Maximum value of vector.
Definitions of some specific functions useful in communications.
int pow2i(int x)
Calculate two to the power of x (2^x); x is integer.
One- and two-dimensional modulators - header file.
double trunc_log(double x)
Truncated natural logarithm function.
virtual void demodulate_soft_bits(const cvec &rx_symbols, double N0, vec &soft_bits, Soft_Method method=LOGMAP) const
Soft demodulator for AWGN channel.
void demodulate_bits(const vec &signal, bvec &output) const
Demodulate noisy BPSK symbols in complex domain into bits.
bmat graycode(int m)
Generate Gray code of blocklength m.The codes are contained as binary codewords {0,1} in the rows of the returned matrix. See also the gray() function in math/scalfunc.h.
vec sqr(const cvec &data)
Absolute square of elements.
Definitions of special vectors and matrices.
Soft_Method
Soft demodulation methods.
void calculate_softbit_matrices()
This function calculates the soft bit mapping matrices S0 and S1.
Binary arithmetic (boolean) class.
virtual void demodulate_soft_bits(const vec &rx_symbols, double N0, vec &soft_bits, Soft_Method method=LOGMAP) const
Soft demodulator for AWGN channel.
Log-MAP full calculation.
vec sqrt(const vec &x)
Square root of the elements.
void demodulate_bits(const vec &signal, bvec &output) const
Hard demodulation of PAM symbols in complex domain to bits.
void set_M(int M)
Set the size of the signal constellation.
vec cos(const vec &x)
Cosine function.
void demodulate_bits(const cvec &signal, bvec &bits) const
Hard demodulation of bits.
ITPP_EXPORT int bin2dec(const bvec &inbvec, bool msb_first=true)
Convert a bvec to decimal int with the first bit as MSB if msb_first == true.
bmat bitmap
Bit to symbol mapping table (size: M x k)
Elementary mathematical functions - header file.
vec real(const cvec &data)
Real part of complex values.
imat S1
Matrix where row k contains the constellation points with '1' in bit position k.
bool setup_done
Setup indicator.
int levels2bits(int n)
Calculate the number of bits needed to represent n different values (levels).
Mat< bin > bmat
bin matrix
ivec bits2symbols
Bit to symbol mapping in decimal form (size: M)
const Array< T > concat(const Array< T > &a, const T &e)
Append element e to the end of the Array a.