74 for (
int i = 0;
i <
k(
j);
i++) {
81 for (
int i = 0;
i <
k(
j);
i++) {
96 QLLRvec &
p1, QLLRvec &
p0)
100 for (
int j = 0;
j <
nt;
j++) {
101 for (
int i = 0;
i <
k(
j);
i++) {
109 for (
int j = 0;
j <
nt;
j++) {
110 for (
int i = 0;
i <
k(
j);
i++) {
137 for(
int bi = 3;
bi <
nb - 1 ;
bi++) {
174 for(
int bi = 3;
bi <
nb - 1;
bi++) {
200 else it_error(
"Improper soft demodulation method\n.");
205 using namespace itpp;
224 using namespace itpp;
252 using namespace itpp;
296 using namespace itpp;
322 using namespace itpp;
364 using namespace itpp;
455 for(
int i = 0;
i <
nt; ++
i) {
457 "The length of M vector is different than length of the symbols vector.");
466 "The number of input bits does not match.");
471 for(
int i = 0;
i <
nt; ++
i) {
488 using namespace itpp;
490 it_assert(
sum(
k) < 32,
"Number of total bits per transmission can not be larger than 32.\n");
491 it_assert(
pow2i(
sum(
k)) ==
prod(
M),
"Modulator must use exhaustive constellations, i.e., #bits=log2(#symbs).\n");
528 Soft_Demod_Method method)
530 using namespace itpp;
533 it_assert_debug(
H.rows() == y.length(),
"The dimensions are not correct.\n");
542 vec
ytil =
H.T() * y;
568 it_assert(
H.rows() >=
H.cols(),
"Modulator_NRD::demodulate_soft_bits():"
569 " ZF demodulation impossible for undetermined systems");
607 "Modulator_NRD::demodulate_soft_bits(): Wrong sizes");
609 "Modulator_NRD::demodulate_soft_bits(): Wrong sizes");
615 double moo2s2 = -1.0 / (2.0 * sigma2);
618 for(
int i = 0;
i <
nt; ++
i) {
622 for(
int j = 0;
j <
M(
i); ++
j) {
634 using namespace itpp;
655 using namespace itpp;
681 os <<
"--- REAL MIMO (NRD) CHANNEL ---------" << std::endl;
682 os <<
"Dimension (nt): " <<
mod.nt << std::endl;
683 os <<
"Bits per dimension (k): " <<
mod.k << std::endl;
684 os <<
"Symbols per dimension (M):" <<
mod.M << std::endl;
685 for(
int i = 0;
i <
mod.nt;
i++) {
686 os <<
"Bitmap for dimension " <<
i <<
": " <<
mod.bitmap(
i) << std::endl;
688 os <<
"Symbol coordinates for dimension " <<
i <<
": " <<
mod.symbols(
i).
left(
mod.M(
i)) << std::endl;
690 os <<
mod.get_llrcalc() << std::endl;
701 for(
int i = 0;
i <
nt; ++
i) {
703 "The length of M vector is different than length of the symbols vector.");
712 "The number of input bits does not match.");
717 for(
int i = 0;
i <
nt; ++
i) {
733 using namespace itpp;
735 it_assert_debug(
sum(
k) < 32,
"Number of total bits per transmission can not be larger than 32.\n");
771 Soft_Demod_Method method)
773 using namespace itpp;
776 it_assert_debug(
H.rows() == y.length(),
"The dimensions are not correct.\n");
809 it_assert(
H.rows() >=
H.cols(),
"Modulator_NCD::demodulate_soft_bits():"
810 " ZF demodulation impossible for undetermined systems");
848 "Modulator_NCD::demodulate_soft_bits(): Wrong sizes");
850 "Modulator_NCD::demodulate_soft_bits(): Wrong sizes");
856 double moos2 = -1.0 / sigma2;
859 for(
int i = 0;
i <
nt; ++
i) {
863 for(
int j = 0;
j <
M(
i); ++
j) {
874void Modulator_NCD::hxnormupdate(itpp::cvec&
Hx,
unsigned&
bitstring,
unsigned&
ind,
unsigned bit)
876 using namespace itpp;
895void Modulator_NCD::yxnormupdate(
double&
yx, itpp::QLLR&
lapr,
unsigned&
bitstring,
unsigned&
ind,
unsigned bit)
897 using namespace itpp;
925 os <<
"--- COMPLEX MIMO (NCD) CHANNEL --------" << std::endl;
926 os <<
"Dimension (nt): " <<
mod.nt << std::endl;
927 os <<
"Bits per dimension (k): " <<
mod.k << std::endl;
928 os <<
"Symbols per dimension (M):" <<
mod.M << std::endl;
929 for(
int i = 0;
i <
mod.nt;
i++) {
930 os <<
"Bitmap for dimension " <<
i <<
": "
931 <<
mod.bitmap(
i) << std::endl;
932 os <<
"Symbol coordinates for dimension " <<
i <<
": "
935 os <<
mod.get_llrcalc() << std::endl;
965 spacing.set_size(
nt);
967 for(
int i = 0;
i <
nt;
i++) {
970 "ND_UPAM::set_M(): M is not a power of 2.");
978 for(
int j = 0;
j <
M(
i); ++
j) {
987 spacing(
i) = 2.0 / scaling_factor;
991int ND_UPAM::sphere_search_SE(
const vec &
y_in,
const mat &H,
1003 mat R =
chol(
H.transpose() *
H);
1006 vec y = Q.transpose() *
y_in;
1007 mat
Vi =
Ri.transpose();
1015 mat E =
zeros(n, n);
1016 for(
int i = 0;
i < n;
i++) {
1017 for(
int j = 0;
j < n;
j++) {
1018 E(
i * n + n - 1) += y(
j) *
Vi(
j + n *
i);
1024 z(n - 1) =
floor_i(0.5 + E(n * n - 1));
1025 z(n - 1) = std::max(z(n - 1),
zrange(n - 1, 0));
1026 z(n - 1) = std::min(z(n - 1),
zrange(n - 1, 1));
1027 double p = (E(n * n - 1) - z(n - 1)) /
Vi(n * n - 1);
1029 step(n - 1) = sign_nozero_i(p);
1038 for(
int i = 0;
i <
k;
i++) {
1039 E(
k - 1 +
i * n) = E(
k +
i * n) - p *
Vi(
k +
i * n);
1047 p = (E(
k +
k * n) - z(
k)) /
Vi(
k +
k * n);
1049 step(
k) = sign_nozero_i(p);
1058 else if(
k == n - 1) {
1068 step(
k) = (-step(
k) - sign_nozero_i(step(
k)));
1077 p = (E(
k +
k * n) - z(
k)) /
Vi(
k +
k * n);
1078 step(
k) = (-step(
k) - sign_nozero_i(step(
k)));
1092 "ND_UPAM::sphere_decoding(): dimension mismatch");
1094 "ND_UPAM::sphere_decoding(): dimension mismatch");
1101 mat
Htemp(
H.rows(),
H.cols());
1102 for(
int i = 0;
i <
H.cols();
i++) {
1103 Htemp.set_col(
i,
H.get_col(
i)*spacing(
i));
1108 for(
int i = 0;
i <
nt;
i++) {
1122 for(
int j = 0;
j <
nt;
j++) {
1123 for(
int i = 0;
i <
k(
j);
i++) {
1175 for(
int i = 0;
i <
nt; ++
i) {
1178 "ND_UQAM::set_M(): M is not a power of 2");
1180 L(
i) =
round_i(std::sqrt(
static_cast<double>(
M(
i))));
1181 it_assert(
L(
i)*
L(
i) ==
M(
i),
"ND_UQAM: constellation M must be square");
1193 std::complex<double>(((
L(
i) - 1) -
j2 * 2.0) / scaling_factor,
1194 ((
L(
i) - 1) -
j1 * 2.0) / scaling_factor);
1210 it_assert(
nt >
nth,
"ND_UQAM::set_constellation_points(): Number of input to change is out of the size");
1212 "ND_UQAM::set_constellation_points(): Number of constellation and bits2symbols does not match");
1214 "ND_UQAM::set_constellation_points(): Number of symbols needs to be even and non-zero");
1220 for(
int m = 0; m <
M(
nth); ++m) {
1256 for(
int i = 0;
i <
nt; ++
i) {
1259 "ND_UPSK::set_M(): M is not a power of 2");
1266 double epsilon =
delta / 10000.0;
1268 for(
int j = 0;
j <
M(
i); ++
j) {
1269 std::complex<double>
symb
1270 = std::complex<double>(std::polar(1.0,
delta *
j));
1272 if(std::abs(std::real(
symb)) < epsilon) {
1275 else if(std::abs(std::imag(
symb)) < epsilon) {
Definitions of Cholesky factorisation functions.
Array< T > mid(int pos, int n) const
Get n elements of the array starting from pos.
int size() const
Returns the number of data elements in the array object.
Array< T > left(int n) const
Get n left elements of the array.
void set_size(int n, bool copy=false)
Resizing an Array<T>.
int length() const
Returns the number of data elements in the array object.
QLLR jaclog(QLLR a, QLLR b) const
Jacobian logarithm.
QLLR to_qllr(double l) const
Convert a "real" LLR value to an LLR type.
Base class for vector (MIMO) channel modulator/demodulators with complex valued components.
void demodulate_soft_bits(const cvec &y, const QLLRvec &LLR_apriori, QLLRvec &LLR_aposteriori, Soft_Demod_Method method=FULL_ENUM_LOGMAP)
Soft MAP demodulation for multidimensional channel, by "brute-force" enumeration of all constellation...
itpp::Array< itpp::Array< itpp::cvec > > hspacings
The spacing between different constellation points multiplied by the different H columns.
void init_soft_demodulator(const itpp::cmat &H, const double &sigma2)
Soft MAP demodulation for multidimensional channel, by "brute-force" enumeration of all constellation...
itpp::Array< itpp::vec > yspacings
The spacing between different constellation points scaled by different y elements.
itpp::cmat H
Complex-valued channel matrix.
Array< cvec > get_symbols() const
Get modulation symbols per dimension.
void modulate_bits(const bvec &bits, cvec &symbols) const
Modulate bits into symbols.
Array< cvec > symbols
Vectors of modulation symbols (along each dimension)
itpp::QLLRvec Qnorms
Norms part depending on both H and y.
double gaussnorm
The normalization factor in the exponent (in front of the square norm) in the Gaussian distribution.
Array< ivec > bits2symbols
Bit pattern in decimal form ordered and the corresponding symbols (one pattern per dimension)
int nt
Number of dimensions.
void demodllrbit2(itpp::QLLR &llr) const
Hardcoded implementation of 3:rd bit demodulation.
itpp::vec hnorms
Norms part dependent on H.
void demodmaxbit1(itpp::QLLR &maxllr) const
Hardcoded implementation of 2:nd bit demodulation.
ivec M
Number of modulation symbols along each dimension.
void update_LLR(const Array< QLLRvec > &logP_apriori, const ivec &s, QLLR scaled_norm, QLLRvec &num, QLLRvec &denom)
Update LLR (for internal use)
itpp::ivec bitcumsum
The cumulative sum of bits in the symbol vector.
ivec k
Number of bits per modulation symbol.
itpp::QLLRvec llrapr
A prioi information.
Soft_Demod_Method
Soft demodulation method.
@ FULL_ENUM_MAXLOG
Max-Log demodulation by "brute-force" enumeration of all points.
@ FULL_ENUM_LOGMAP
Log-MAP demodulation by "brute-force" enumeration of all points.
@ ZF_LOGMAP
Zero-Forcing Log-MAP approximated demodulation.
void demodllrbit1(itpp::QLLR &llr) const
Hardcoded implementation of 2:nd bit demodulation.
void marginalize_bits(itpp::QLLRvec &llr, Soft_Demod_Method method) const
Marginalize (sum) over the bits.
LLR_calc_unit llrcalc
LLR calculation unit.
itpp::Array< itpp::Vec< unsigned > > gray2dec
The Gray to decimal mapping.
int nb
Number of bits in the symbol vector.
QLLRvec probabilities(QLLR l)
Convert LLR to log-probabilities.
void demodmaxbit0(itpp::QLLR &maxllr) const
Hardcoded implementation of 1:st bit demodulation.
Array< bmat > bitmap
Bit mapping table (one table per dimension)
void demodllrbit0(itpp::QLLR &llr) const
Hardcoded implementation of 1:st bit demodulation.
void demodmaxbit2(itpp::QLLR &maxllr) const
Hardcoded implementation of 3:rd bit demodulation.
bool demod_initialized
Flag indicating whether the demodulator has been initialized.
itpp::ivec bpos2cpos
The bit to column mapping.
Base class for N-dimensional vector (MIMO) channel modulators/demodulators with real-valued component...
void demodulate_soft_bits(const vec &y, const QLLRvec &LLR_apriori, QLLRvec &LLR_aposteriori, Soft_Demod_Method method=FULL_ENUM_LOGMAP)
Soft MAP demodulation for multidimensional channel, by "brute-force" enumeration of all constellation...
void yxnormupdate(double &yx, itpp::QLLR &lapr, unsigned &bitstring, unsigned &ind, unsigned bit)
Calculation of the remaining part of the norms that depends both on H and y.
void hxnormupdate(itpp::vec &Hx, unsigned &bitstring, unsigned &ind, unsigned bit)
Calculation of the part of the norms that depends on H.
itpp::Array< itpp::vec > yspacings
The spacing between different constellation points scaled by different y elements.
itpp::mat H
Real channel matrix.
Array< vec > symbols
Vectors of modulation symbols (along each dimension)
void modulate_bits(const bvec &bits, vec &symbols) const
Modulate bits into symbols.
Array< vec > get_symbols() const
Get modulation symbols per dimension.
itpp::Array< itpp::Array< itpp::vec > > hspacings
The spacing between different constellation points multiplied by the different H columns.
void init_soft_demodulator(const itpp::mat &H, const double &sigma2)
Soft MAP demodulation for multidimensional channel, by "brute-force" enumeration of all constellation...
ND_UPAM(int nt=1, int Mary=2)
Constructor.
int sphere_decoding(const vec &y, const mat &H, double rmin, double rmax, double stepup, QLLRvec &detected_bits)
Sphere decoding.
void set_M(int nt=1, int Mary=2)
Set component modulators to M-PAM with Gray mapping.
void set_M(int nt=1, int Mary=4)
Set component modulators to M-QAM with Gray mapping.
ND_UPSK(int nt=1, int Mary=4)
Constructor.
ivec L
the square root of M
void set_constellation_points(const int nth, const cvec &inConstellation, const ivec &in_bit2symbols)
Set the constellation points.
ND_UQAM(int nt=1, int Mary=4)
Constructor.
void set_M(int nt=1, int Mary=4)
Set component modulators to M-QAM with Gray mapping.
Definitions of some specific functions useful in communications.
Definitions of converters between different vector and matrix types.
Elementary mathematical functions - header file.
#define it_error(s)
Abort unconditionally.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
#define it_assert(t, s)
Abort if t is not true.
bool inv(const mat &X, mat &Y)
Inverse of real square matrix.
int pow2i(int x)
Calculate two to the power of x (2^x); x is integer.
vec log2(const vec &x)
log-2 of the elements
int levels2bits(int n)
Calculate the number of bits needed to represent n different values (levels).
Vec< T > cumsum(const Vec< T > &v)
Cumulative sum of all elements in the vector.
T sum(const Vec< T > &v)
Sum of all elements in the vector.
int length(const Vec< T > &v)
Length of vector.
T prod(const Vec< T > &v)
The product of all elements in the vector.
bool chol(const mat &X, mat &F)
Cholesky factorisation of real symmetric and positive definite matrix.
bmat graycode(int m)
Generate Gray code of blocklength m.
int mod(int k, int n)
Calculates the modulus, i.e. the signed reminder after division.
bool is_even(int x)
Return true if x is an even integer.
vec real(const cvec &data)
Real part of complex values.
vec sqr(const cvec &data)
Absolute square of elements.
cvec conj(const cvec &x)
Conjugate of complex value.
Vec< T > reverse(const Vec< T > &in)
Reverse the input vector.
ITPP_EXPORT vec zeros(int size)
A Double vector of zeros.
ITPP_EXPORT ivec ones_i(int size)
A Int vector of ones.
ITPP_EXPORT cvec ones_c(int size)
A float Complex vector of ones.
ITPP_EXPORT vec ones(int size)
A float vector of ones.
ITPP_EXPORT ivec zeros_i(int size)
A Int vector of zeros.
double norm(const cvec &v)
Calculate the 2-norm: norm(v)=sqrt(sum(abs(v).^2))
Definitions of matrix inversion routines.
IT++ compatibility types and functions.
Logarithmic and exponenential functions - header file.
Mat< bin > bmat
bin matrix
Various functions on vectors and matrices - header file.
Miscellaneous statistics functions and classes - header file.
Definition of vector (MIMO) modulator classes.
ITPP_EXPORT int round_i(double x)
Round to nearest integer.
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
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.
const Array< T > concat(const Array< T > &a, const T &e)
Append element e to the end of the Array a.
int gray_code(int x)
Convert to Gray Code.
ITPP_EXPORT bvec dec2bin(int length, int index)
Convert a decimal int index to bvec using length bits in the representation.
const double pi
Constant Pi.
int floor_i(double x)
The nearest smaller integer.