OLD | NEW |
(Empty) | |
| 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2010 TELEMATICS LAB, DEE - Politecnico di Bari |
| 4 * |
| 5 * This program is free software; you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 2 as |
| 7 * published by the Free Software Foundation; |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software |
| 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 * |
| 18 * Author: Giuseppe Piro <g.piro@poliba.it> |
| 19 */ |
| 20 |
| 21 |
| 22 #include "amc-module.h" |
| 23 #include <ns3/log.h> |
| 24 #include <math.h> |
| 25 |
| 26 NS_LOG_COMPONENT_DEFINE ("AmcModule"); |
| 27 |
| 28 namespace ns3 { |
| 29 |
| 30 |
| 31 NS_OBJECT_ENSURE_REGISTERED (AmcModule); |
| 32 |
| 33 |
| 34 |
| 35 int CQIIndex[15] = { |
| 36 1, 2, 3, 4, 5, 6, // QAM |
| 37 7, 8, 9, // 4-QAM |
| 38 10, 11, 12, 13, 14, 15 // 16QAM |
| 39 }; |
| 40 |
| 41 |
| 42 double SpectralEfficiencyForCQIIndex[15] = { |
| 43 0.15, 0.23, 0.38, 0.6, 0.88, 1.18, |
| 44 1.48, 1.91, 2.41, |
| 45 2.73, 3.32, 3.9, 4.52, 5.12, 5.55 |
| 46 }; |
| 47 |
| 48 int MCSIndex[32] = { |
| 49 0, // RESERVED |
| 50 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, // QAM |
| 51 12, 13, 14, 15, 16, 17, 18, // 4-QAM |
| 52 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, // 16-QAM |
| 53 30, // QAM, RESERVED |
| 54 31 // RESERVED |
| 55 }; |
| 56 |
| 57 int ModulationSchemeForMCSIndex[32] = { |
| 58 0, // Not defined |
| 59 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 60 4, 4, 4, 4, 4, 4, 4, |
| 61 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |
| 62 2, |
| 63 0 // Not defined |
| 64 }; |
| 65 |
| 66 double SpectralEfficiencyForMCSIndex[32] = { |
| 67 0, |
| 68 0.15, 0.19, 0.23, 0.31, 0.38, 0.49, 0.6, 0.74, 0.88, 1.03, 1.18, |
| 69 1.33, 1.48, 1.7, 1.91, 2.16, 2.41, 2.57, |
| 70 2.73, 3.03, 3.32, 3.61, 3.9, 4.21, 4.52, 4.82, 5.12, 5.33, 5.55, |
| 71 2.4, |
| 72 0 |
| 73 }; |
| 74 |
| 75 int TransportBlockSize[32] = { |
| 76 0, |
| 77 18, 23, 28, 37, 45, 59, 72, 89, 105, 123, 141, |
| 78 159, 177, 203, 230, 259, 289, 288, |
| 79 308, 328, 363, 399, 433, 468, 506, 543, 578, 614, 640, |
| 80 667, |
| 81 0 |
| 82 }; |
| 83 |
| 84 |
| 85 AmcModule::AmcModule () |
| 86 { |
| 87 Initialize (); |
| 88 } |
| 89 |
| 90 |
| 91 TypeId |
| 92 AmcModule::GetTypeId (void) |
| 93 { |
| 94 static TypeId tid = TypeId ("ns3::AmcModule") |
| 95 .SetParent<Object> () |
| 96 .AddConstructor<AmcModule> () |
| 97 ; |
| 98 return tid; |
| 99 } |
| 100 |
| 101 |
| 102 AmcModule::~AmcModule () |
| 103 { |
| 104 |
| 105 } |
| 106 |
| 107 void |
| 108 AmcModule::Initialize () |
| 109 { |
| 110 NS_LOG_FUNCTION (this); |
| 111 } |
| 112 |
| 113 |
| 114 int |
| 115 AmcModule::GetCqiFromFromSpectralEfficiency (double s) |
| 116 { |
| 117 NS_LOG_FUNCTION (this); |
| 118 int cqi = 1; // == CQIIndex[0] |
| 119 while (SpectralEfficiencyForCQIIndex[cqi] < s && cqi <= 14) |
| 120 { |
| 121 cqi++; |
| 122 } |
| 123 NS_LOG_FUNCTION (this << s << cqi); |
| 124 return cqi; |
| 125 } |
| 126 |
| 127 |
| 128 int |
| 129 AmcModule::GetMCSFromCQI (int cqi) |
| 130 { |
| 131 NS_LOG_FUNCTION (this); |
| 132 double spectralEfficiency = SpectralEfficiencyForCQIIndex[cqi - 1]; |
| 133 int mcs = 1; |
| 134 while (SpectralEfficiencyForMCSIndex[mcs] < spectralEfficiency && mcs < 30) |
| 135 { |
| 136 mcs++; |
| 137 } |
| 138 NS_LOG_FUNCTION (this << cqi << mcs); |
| 139 return mcs; |
| 140 } |
| 141 |
| 142 |
| 143 int |
| 144 AmcModule::GetTBSizeFromMCS (int mcs) |
| 145 { |
| 146 NS_LOG_FUNCTION (this); |
| 147 NS_LOG_FUNCTION (this << mcs << TransportBlockSize[mcs]); |
| 148 return TransportBlockSize[mcs]; |
| 149 } |
| 150 |
| 151 |
| 152 double |
| 153 AmcModule::GetSpectralEfficiencyFromCQI (int cqi) |
| 154 { |
| 155 NS_LOG_FUNCTION (this); |
| 156 NS_LOG_FUNCTION (this << cqi << SpectralEfficiencyForCQIIndex[cqi - 1]); |
| 157 return SpectralEfficiencyForCQIIndex[cqi - 1]; |
| 158 } |
| 159 |
| 160 |
| 161 std::vector<int> |
| 162 AmcModule::CreateCqiFeedbacks (std::vector<double> sinr) |
| 163 { |
| 164 NS_LOG_FUNCTION (this); |
| 165 |
| 166 std::vector<int> cqi; |
| 167 std::vector<double>::iterator it; |
| 168 |
| 169 for (it = sinr.begin (); it != sinr.end (); it++) |
| 170 { |
| 171 double sinr_ = (*it); |
| 172 |
| 173 /* |
| 174 * Compute the spectral efficiency from the SINR |
| 175 * SINR |
| 176 * spectralEfficiency = log2 (1 + -------------------- ) |
| 177 * -ln(5*BER)/1.5 |
| 178 * NB: SINR must be expressed in natural unit: |
| 179 * (SINR)dB => 10 ^ (SINR/10) |
| 180 */ |
| 181 |
| 182 double s = log2 ( 1 + ( |
| 183 pow (10, sinr_ / 10 ) / |
| 184 ( (-log (5.0 * 0.00005 )) / 1.5) )); |
| 185 |
| 186 int cqi_ = GetCqiFromFromSpectralEfficiency (s); |
| 187 |
| 188 NS_LOG_FUNCTION (this << "channel_id = " << cqi.size () |
| 189 << "sinr = " << sinr_ |
| 190 << "spectral efficiency =" << s |
| 191 << " ---- CQI = " << cqi_ ); |
| 192 |
| 193 cqi.push_back (cqi_); |
| 194 } |
| 195 |
| 196 return cqi; |
| 197 } |
| 198 |
| 199 } // namespace ns3 |
OLD | NEW |