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 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
/*!
* \file
* \brief 1D and 2D modulators test program
* \author Tony Ottosson and Adam Piatyszek
*
* -------------------------------------------------------------------------
*
* IT++ - C++ library of mathematical, signal processing, speech processing,
* and communications classes and functions
*
* Copyright (C) 1995-2008 (see AUTHORS file for a list of contributors)
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* -------------------------------------------------------------------------
*/
#include <itpp/itcomm.h>
using namespace itpp;
using namespace std;
int main()
{
RNG_reset(12345);
cout << "===========================================================" << endl;
cout << " Test of Modulators " << endl;
cout << "===========================================================" << endl;
const int no_symbols = 5;
const double N0 = 0.1;
{
cout << endl << "Modulator_1D (configured as BPSK)" << endl;
Modulator_1D mod("1.0 -1.0", "0 1");
int bps = round_i(mod.bits_per_symbol());
bvec tx_bits = randb(no_symbols * bps);
ivec tx_sym_numbers = randi(no_symbols, 0, pow2i(bps) - 1);
vec noise = sqrt(N0) * randn(no_symbols);
vec tx_symbols = mod.modulate_bits(tx_bits);
vec rx_symbols = tx_symbols + noise;
bvec decbits = mod.demodulate_bits(rx_symbols);
cout << "* modulating bits:" << endl;
cout << " tx_bits = " << tx_bits << endl;
cout << " tx_symbols = " << tx_symbols << endl;
cout << " rx_symbols = " << rx_symbols << endl;
cout << " decbits = " << decbits << endl;
tx_symbols = mod.modulate(tx_sym_numbers);
rx_symbols = tx_symbols + noise;
ivec dec_sym_numbers = mod.demodulate(rx_symbols);
cout << "* modulating symbol numbers:" << endl;
cout << " tx_sym_numbers = " << tx_sym_numbers << endl;
cout << " tx_symbols = " << tx_symbols << endl;
cout << " rx_symbols = " << rx_symbols << endl;
cout << " dec_sym_numbers = " << dec_sym_numbers << endl;
cout << endl << "BPSK (real signal)" << endl;
BPSK bpsk;
bpsk.modulate_bits(tx_bits, tx_symbols);
rx_symbols = tx_symbols + noise;
bpsk.demodulate_bits(rx_symbols, decbits);
cout << "* modulating bits:" << endl;
cout << " tx_bits = " << tx_bits << endl;
cout << " tx_symbols = " << tx_symbols << endl;
cout << " rx_symbols = " << rx_symbols << endl;
cout << " decbits = " << decbits << endl;
cout << endl << "BPSK (complex signal)" << endl;
BPSK_c bpsk_c;
cvec tx_csymbols = bpsk_c.modulate_bits(tx_bits);
cvec rx_csymbols = tx_csymbols + to_cvec(noise, -noise);
decbits = bpsk_c.demodulate_bits(rx_csymbols);
vec softbits_approx = bpsk_c.demodulate_soft_bits(rx_csymbols, N0, APPROX);
vec softbits = bpsk_c.demodulate_soft_bits(rx_csymbols, N0, LOGMAP);
cout << "* modulating bits:" << endl;
cout << " tx_bits = " << tx_bits << endl;
cout << " tx_csymbols = " << tx_csymbols << endl;
cout << " rx_csymbols = " << rx_csymbols << endl;
cout << " decbits = " << decbits << endl;
cout << " softbits = " << softbits << endl;
cout << " softbits_approx = " << softbits_approx << endl << endl;
}
cout << "===========================================================" << endl;
{
cout << endl << "Modulator_1D (configured as 4-PAM)" << endl;
Modulator_1D mod("-3.0 -1.0 1.0 3.0", "0 1 3 2");
int bps = round_i(mod.bits_per_symbol());
bvec tx_bits = randb(no_symbols * bps);
ivec tx_sym_numbers = randi(no_symbols, 0, pow2i(bps) - 1);
vec noise = sqrt(N0) * randn(no_symbols);
vec tx_symbols = mod.modulate_bits(tx_bits);
vec rx_symbols = tx_symbols + noise;
bvec decbits = mod.demodulate_bits(rx_symbols);
cout << "* modulating bits:" << endl;
cout << " tx_bits = " << tx_bits << endl;
cout << " tx_symbols = " << tx_symbols << endl;
cout << " rx_symbols = " << rx_symbols << endl;
cout << " decbits = " << decbits << endl;
tx_symbols = mod.modulate(tx_sym_numbers);
rx_symbols = tx_symbols + noise;
ivec dec_sym_numbers = mod.demodulate(rx_symbols);
cout << "* modulating symbol numbers:" << endl;
cout << " tx_sym_numbers = " << tx_sym_numbers << endl;
cout << " tx_symbols = " << tx_symbols << endl;
cout << " rx_symbols = " << rx_symbols << endl;
cout << " dec_sym_numbers = " << dec_sym_numbers << endl;
cout << endl << "4-PAM (real signal)" << endl;
PAM pam(4);
pam.modulate_bits(tx_bits, tx_symbols);
rx_symbols = tx_symbols + noise;
pam.demodulate_bits(rx_symbols, decbits);
cout << "* modulating bits:" << endl;
cout << " tx_bits = " << tx_bits << endl;
cout << " tx_symbols = " << tx_symbols << endl;
cout << " rx_symbols = " << rx_symbols << endl;
cout << " decbits = " << decbits << endl;
cout << endl << "4-PAM (complex signal)" << endl;
PAM_c pam_c(4);
cvec tx_csymbols = pam_c.modulate_bits(tx_bits);
cvec rx_csymbols = tx_csymbols + to_cvec(noise, -noise);
decbits = pam_c.demodulate_bits(rx_csymbols);
vec softbits_approx = pam_c.demodulate_soft_bits(rx_csymbols, N0, APPROX);
vec softbits = pam_c.demodulate_soft_bits(rx_csymbols, N0, LOGMAP);
cout << "* modulating bits:" << endl;
cout << " tx_bits = " << tx_bits << endl;
cout << " tx_csymbols = " << tx_csymbols << endl;
cout << " rx_csymbols = " << rx_csymbols << endl;
cout << " decbits = " << decbits << endl;
cout << " softbits = " << softbits << endl;
cout << " softbits_approx = " << softbits_approx << endl << endl;
}
cout << "===========================================================" << endl;
{
cout << endl << "Modulator_2D (configured as 256-QAM)" << endl;
QAM qam(256);
Modulator_2D mod(qam.get_symbols(), qam.get_bits2symbols());
int bps = round_i(mod.bits_per_symbol());
bvec tx_bits = randb(no_symbols * bps);
ivec tx_sym_numbers = randi(no_symbols, 0, pow2i(bps) - 1);
cvec noise = sqrt(N0) * randn_c(no_symbols);
cvec tx_symbols = mod.modulate(tx_sym_numbers);
cvec rx_symbols = tx_symbols + noise;
ivec dec_sym_numbers = mod.demodulate(rx_symbols);
cout << "* modulating symbol numbers:" << endl;
cout << " tx_sym_numbers = " << tx_sym_numbers << endl;
cout << " tx_symbols = " << tx_symbols << endl;
cout << " rx_symbols = " << rx_symbols << endl;
cout << " dec_sym_numbers = " << dec_sym_numbers << endl;
tx_symbols = mod.modulate_bits(tx_bits);
rx_symbols = tx_symbols + noise;
bvec decbits = mod.demodulate_bits(rx_symbols);
vec softbits_approx = mod.demodulate_soft_bits(rx_symbols, N0, APPROX);
vec softbits = mod.demodulate_soft_bits(rx_symbols, N0, LOGMAP);
cout << "* modulating bits:" << endl;
cout << " tx_bits = " << tx_bits << endl;
cout << " tx_symbols = " << tx_symbols << endl;
cout << " rx_symbols = " << rx_symbols << endl;
cout << " decbits = " << decbits << endl;
cout << " softbits = " << softbits << endl;
cout << " softbits_approx = " << softbits_approx << endl;
cout << endl << "256-QAM" << endl;
tx_symbols = qam.modulate(tx_sym_numbers);
rx_symbols = tx_symbols + noise;
dec_sym_numbers = qam.demodulate(rx_symbols);
cout << "* modulating symbol numbers:" << endl;
cout << " tx_sym_numbers = " << tx_sym_numbers << endl;
cout << " tx_symbols = " << tx_symbols << endl;
cout << " rx_symbols = " << rx_symbols << endl;
cout << " dec_sym_numbers = " << dec_sym_numbers << endl;
tx_symbols = qam.modulate_bits(tx_bits);
rx_symbols = tx_symbols + noise;
decbits = qam.demodulate_bits(rx_symbols);
softbits_approx = qam.demodulate_soft_bits(rx_symbols, N0, APPROX);
softbits = qam.demodulate_soft_bits(rx_symbols, N0, LOGMAP);
cout << "* modulating bits:" << endl;
cout << " tx_bits = " << tx_bits << endl;
cout << " tx_symbols = " << tx_symbols << endl;
cout << " rx_symbols = " << rx_symbols << endl;
cout << " decbits = " << decbits << endl;
cout << " softbits = " << softbits << endl;
cout << " softbits_approx = " << softbits_approx << endl << endl;
}
cout << "===========================================================" << endl;
{
cout << endl << "8-PSK" << endl;
PSK psk(8);
int bps = round_i(psk.bits_per_symbol());
bvec tx_bits = randb(no_symbols * bps);
ivec tx_sym_numbers = randi(no_symbols, 0, pow2i(bps) - 1);
cvec noise = sqrt(N0) * randn_c(no_symbols);
cvec tx_symbols = psk.modulate(tx_sym_numbers);
cvec rx_symbols = tx_symbols + noise;
ivec dec_sym_numbers = psk.demodulate(rx_symbols);
cout << "* modulating symbol numbers:" << endl;
cout << " tx_sym_numbers = " << tx_sym_numbers << endl;
cout << " tx_symbols = " << tx_symbols << endl;
cout << " rx_symbols = " << rx_symbols << endl;
cout << " dec_sym_numbers = " << dec_sym_numbers << endl;
tx_symbols = psk.modulate_bits(tx_bits);
rx_symbols = tx_symbols + noise;
bvec decbits = psk.demodulate_bits(rx_symbols);
vec softbits_approx = psk.demodulate_soft_bits(rx_symbols, N0, APPROX);
vec softbits = psk.demodulate_soft_bits(rx_symbols, N0, LOGMAP);
cout << "* modulating bits:" << endl;
cout << " tx_bits = " << tx_bits << endl;
cout << " tx_symbols = " << tx_symbols << endl;
cout << " rx_symbols = " << rx_symbols << endl;
cout << " decbits = " << decbits << endl;
cout << " softbits = " << softbits << endl;
cout << " softbits_approx = " << softbits_approx << endl << endl;
}
cout << "===========================================================" << endl;
{
cout << endl << "16-QAM" << endl;
QAM qam(16);
int bps = round_i(qam.bits_per_symbol());
bvec tx_bits = randb(no_symbols * bps);
ivec tx_sym_numbers = randi(no_symbols, 0, pow2i(bps) - 1);
cvec noise = sqrt(N0) * randn_c(no_symbols);
cvec tx_symbols = qam.modulate(tx_sym_numbers);
cvec rx_symbols = tx_symbols + noise;
ivec dec_sym_numbers = qam.demodulate(rx_symbols);
cout << "* modulating symbol numbers:" << endl;
cout << " tx_sym_numbers = " << tx_sym_numbers << endl;
cout << " tx_symbols = " << tx_symbols << endl;
cout << " rx_symbols = " << rx_symbols << endl;
cout << " dec_sym_numbers = " << dec_sym_numbers << endl;
tx_symbols = qam.modulate_bits(tx_bits);
rx_symbols = tx_symbols + noise;
bvec decbits = qam.demodulate_bits(rx_symbols);
vec softbits_approx = qam.demodulate_soft_bits(rx_symbols, N0, APPROX);
vec softbits = qam.demodulate_soft_bits(rx_symbols, N0, LOGMAP);
cout << "* modulating bits:" << endl;
cout << " tx_bits = " << tx_bits << endl;
cout << " tx_symbols = " << tx_symbols << endl;
cout << " rx_symbols = " << rx_symbols << endl;
cout << " decbits = " << decbits << endl;
cout << " softbits = " << softbits << endl;
cout << " softbits_approx = " << softbits_approx << endl << endl;
}
}
|