37 #include <itpp/itexports.h>
92 virtual int get_k()
const {
return k; }
95 virtual int get_M()
const {
return M; }
120 virtual void modulate(
const ivec& symbolnumbers,
Vec<T>& output)
const;
225 double N0, vec& soft_bits,
281 setup_done(false), k(0), M(0), bitmap(
""), bits2symbols(
""), symbols(
""),
287 set(symbols, bits2symbols);
294 "Modulator<T>::set(): Number of symbols and bits2symbols does not match");
296 "Modulator<T>::set(): Number of symbols needs to be even and non-zero");
297 it_assert((
max(in_bits2symbols) == in_bits2symbols.size() - 1)
298 && (
min(in_bits2symbols) == 0),
"Modulator<T>::set(): Improper bits2symbol vector");
299 symbols = in_symbols;
300 bits2symbols = in_bits2symbols;
301 M = bits2symbols.
size();
303 bitmap.set_size(M, k);
304 for (
int m = 0; m < M; m++) {
305 bitmap.set_row(bits2symbols(m),
dec2bin(k, m));
307 calculate_softbit_matrices();
315 it_assert_debug(setup_done,
"Modulator<T>::modulate(): Modulator not ready.");
316 output.
set_size(symbolnumbers.length());
317 for (
int i = 0; i < symbolnumbers.length(); i++)
318 output(i) = symbols(symbolnumbers(i));
324 Vec<T> output(symbolnumbers.length());
325 modulate(symbolnumbers, output);
333 it_assert_debug(setup_done,
"Modulator<T>::demodulate(): Modulator not ready.");
334 double dist, mindist;
336 output.set_size(signal.
size());
338 for (
int i = 0; i < signal.
size(); i++) {
339 mindist =
std::abs(symbols(0) - signal(i));
341 for (
int j = 1; j < M; j++) {
342 dist =
std::abs(symbols(j) - signal(i));
343 if (dist < mindist) {
355 ivec output(signal.
length());
356 demodulate(signal, output);
364 it_assert_debug(setup_done,
"Modulator<T>::modulate_bits(): Modulator not ready.");
367 if (bits.length() % k) {
368 it_warning(
"Modulator<T>::modulate_bits(): The number of input bits is not a multiple of k (number of bits per symbol). Remainder bits are not modulated.");
370 int no_symbols = bits.length() / k;
372 for (
int i = 0; i < no_symbols; i++) {
373 output(i) = symbols(bits2symbols(
bin2dec(bits.mid(i * k, k))));
381 modulate_bits(bits, output);
388 it_assert_debug(setup_done,
"Modulator<T>::demodulate_bist(): Modulator not ready.");
389 double dist, mindist;
391 bits.set_size(k*signal.
size());
393 for (
int i = 0; i < signal.
size(); i++) {
394 mindist =
std::abs(symbols(0) - signal(i));
396 for (
int j = 1; j < M; j++) {
397 dist =
std::abs(symbols(j) - signal(i));
398 if (dist < mindist) {
403 bits.replace_mid(i*k, bitmap.get_row(closest));
411 demodulate_bits(signal, bits);
421 it_assert_debug(setup_done,
"Modulator<T>::demodulate_soft_bits(): Modulator not ready.");
422 double P0, P1, d0min, d1min, temp;
425 soft_bits.set_size(k * rx_symbols.
size());
428 for (
int l = 0; l < rx_symbols.
size(); l++) {
429 for (
int j = 0; j < M; j++) {
430 metric(j) =
std::exp(-
sqr(rx_symbols(l) - symbols(j)) / N0);
432 for (
int i = 0; i < k; i++) {
434 for (
int j = 0; j < (M >> 1); j++) {
435 P0 += metric(S0(i, j));
436 P1 += metric(S1(i, j));
443 for (
int l = 0; l < rx_symbols.
size(); l++) {
444 for (
int j = 0; j < M; j++) {
445 metric(j) =
sqr(rx_symbols(l) - symbols(j));
447 for (
int i = 0; i < k; i++) {
449 for (
int j = 0; j < (M >> 1); j++) {
450 temp = metric(S0(i, j));
451 if (temp < d0min) { d0min = temp; }
452 temp = metric(S1(i, j));
453 if (temp < d1min) { d1min = temp; }
455 soft_bits(l*k + i) = (-d0min + d1min) / N0;
467 demodulate_soft_bits(rx_symbols, N0, output, method);
473 const Vec<T> &channel,
double N0,
477 it_assert_debug(setup_done,
"Modulator_2D::demodulate_soft_bits(): Modulator not ready.");
478 double P0, P1, d0min, d1min, temp;
481 soft_bits.set_size(k * rx_symbols.
size());
484 for (
int l = 0; l < rx_symbols.
size(); l++) {
485 for (
int j = 0; j < M; j++) {
486 metric(j) =
std::exp(-
sqr(rx_symbols(l) - channel(l) * symbols(j))
489 for (
int i = 0; i < k; i++) {
491 for (
int j = 0; j < (M >> 1); j++) {
492 P0 += metric(S0(i, j));
493 P1 += metric(S1(i, j));
500 for (
int l = 0; l < rx_symbols.
size(); l++) {
501 for (
int j = 0; j < M; j++) {
502 metric(j) =
sqr(rx_symbols(l) - channel(l) * symbols(j));
504 for (
int i = 0; i < k; i++) {
506 for (
int j = 0; j < (M >> 1); j++) {
507 temp = metric(S0(i, j));
508 if (temp < d0min) { d0min = temp; }
509 temp = metric(S1(i, j));
510 if (temp < d1min) { d1min = temp; }
512 soft_bits(l*k + i) = (-d0min + d1min) / N0;
525 demodulate_soft_bits(rx_symbols, channel, N0, output, method);
535 S0.set_size(k, M >> 1,
false);
536 S1.set_size(k, M >> 1,
false);
538 for (
int i = 0; i < k; i++) {
541 for (
int j = 0; j < M; j++) {
542 if (bitmap(j, i) ==
bin(0)) {
599 void demodulate_bits(
const cvec& signal, bvec& bits)
const;
601 bvec demodulate_bits(
const cvec& signal)
const;
648 void demodulate_bits(
const cvec& signal, bvec& bits)
const;
650 bvec demodulate_bits(
const cvec& signal)
const;
706 virtual void demodulate_soft_bits(
const cvec& rx_symbols,
double N0,
710 vec demodulate_soft_bits(
const cvec& rx_symbols,
double N0,
736 virtual void demodulate_soft_bits(
const cvec& rx_symbols,
737 const cvec& channel,
double N0,
741 vec demodulate_soft_bits(
const cvec& rx_symbols,
const cvec& channel,
784 void modulate_bits(
const bvec& bits, cvec& output)
const;
786 cvec modulate_bits(
const bvec& bits)
const;
788 void demodulate_bits(
const cvec& signal, bvec& output)
const;
790 bvec demodulate_bits(
const cvec& signal)
const;
811 virtual void demodulate_soft_bits(
const cvec& rx_symbols,
double N0,
815 vec demodulate_soft_bits(
const cvec& rx_symbols,
double N0,
838 virtual void demodulate_soft_bits(
const cvec& rx_symbols,
839 const cvec& channel,
double N0,
843 vec demodulate_soft_bits(
const cvec& rx_symbols,
const cvec& channel,
885 void modulate_bits(
const bvec& bits, vec& output)
const;
887 vec modulate_bits(
const bvec& bits)
const;
889 void demodulate_bits(
const vec& signal, bvec& output)
const;
891 bvec demodulate_bits(
const vec& signal)
const;
910 virtual void demodulate_soft_bits(
const vec& rx_symbols,
double N0,
914 vec demodulate_soft_bits(
const vec& rx_symbols,
double N0,
936 virtual void demodulate_soft_bits(
const vec& rx_symbols,
937 const vec& channel,
double N0,
941 vec demodulate_soft_bits(
const vec& rx_symbols,
const vec& channel,
981 void demodulate_bits(
const cvec& signal, bvec& output)
const;
983 bvec demodulate_bits(
const cvec& signal)
const;
1024 virtual void demodulate_soft_bits(
const cvec& rx_symbols,
double N0,
1028 virtual vec demodulate_soft_bits(
const cvec& rx_symbols,
double N0,
1069 virtual void demodulate_soft_bits(
const cvec& rx_symbols,
1070 const cvec& channel,
double N0,
1074 virtual vec demodulate_soft_bits(
const cvec& rx_symbols,
1075 const cvec& channel,
double N0,
1117 void demodulate_bits(
const vec& signal, bvec& output)
const;
1119 bvec demodulate_bits(
const vec& signal)
const;
1128 #endif // #ifndef MODULATOR_H