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 #include <cmath> |
| 22 #include <ns3/log.h> |
| 23 #include "multipath-loss-model.h" |
| 24 #include <ns3/simulator.h> |
| 25 #include <stdint.h> |
| 26 #include "stdlib.h" |
| 27 #include "lte-phy.h" |
| 28 #include <ns3/mobility-model.h> |
| 29 |
| 30 #include "JakesTraces/multipath_v0_M6.h" |
| 31 #include "JakesTraces/multipath_v0_M8.h" |
| 32 #include "JakesTraces/multipath_v0_M10.h" |
| 33 #include "JakesTraces/multipath_v0_M12.h" |
| 34 |
| 35 #include "JakesTraces/multipath_v3_M6.h" |
| 36 #include "JakesTraces/multipath_v3_M8.h" |
| 37 #include "JakesTraces/multipath_v3_M10.h" |
| 38 #include "JakesTraces/multipath_v3_M12.h" |
| 39 |
| 40 #include "JakesTraces/multipath_v30_M6.h" |
| 41 #include "JakesTraces/multipath_v30_M8.h" |
| 42 #include "JakesTraces/multipath_v30_M10.h" |
| 43 #include "JakesTraces/multipath_v30_M12.h" |
| 44 |
| 45 #include "JakesTraces/multipath_v120_M6.h" |
| 46 #include "JakesTraces/multipath_v120_M8.h" |
| 47 #include "JakesTraces/multipath_v120_M10.h" |
| 48 #include "JakesTraces/multipath_v120_M12.h" |
| 49 |
| 50 |
| 51 NS_LOG_COMPONENT_DEFINE ("MultipathLossModel"); |
| 52 |
| 53 namespace ns3 { |
| 54 |
| 55 |
| 56 NS_OBJECT_ENSURE_REGISTERED (MultipathLossModel); |
| 57 |
| 58 MultipathLossModel::MultipathLossModel () |
| 59 { |
| 60 NS_LOG_FUNCTION (this); |
| 61 SetSamplingPeriod (0.5); // default value |
| 62 m_multipath = new MultipathForFrequencyDomain (); |
| 63 m_nbOfPaths = new UniformVariable (1, 4); |
| 64 m_startJakes = new UniformVariable (1, 2000); |
| 65 m_phy = 0; |
| 66 } |
| 67 |
| 68 |
| 69 TypeId |
| 70 MultipathLossModel::GetTypeId (void) |
| 71 { |
| 72 static TypeId tid = TypeId ("ns3::MultipathLossModel") |
| 73 .SetParent<LossModel> () |
| 74 .AddConstructor<MultipathLossModel> () |
| 75 ; |
| 76 return tid; |
| 77 } |
| 78 |
| 79 |
| 80 MultipathLossModel::~MultipathLossModel () |
| 81 { |
| 82 m_multipath = 0; |
| 83 m_nbOfPaths = 0; |
| 84 m_startJakes = 0; |
| 85 } |
| 86 |
| 87 |
| 88 void |
| 89 MultipathLossModel::SetPhy (Ptr<LtePhy> phy) |
| 90 { |
| 91 NS_LOG_FUNCTION (this); |
| 92 m_phy = phy; |
| 93 |
| 94 SetValue (); |
| 95 } |
| 96 |
| 97 |
| 98 Ptr<LtePhy> |
| 99 MultipathLossModel::GetPhy (void) |
| 100 { |
| 101 NS_LOG_FUNCTION (this); |
| 102 return m_phy; |
| 103 } |
| 104 |
| 105 |
| 106 void |
| 107 MultipathLossModel::SetValue (void) |
| 108 { |
| 109 NS_LOG_FUNCTION (this); |
| 110 |
| 111 m_multipath->clear (); |
| 112 |
| 113 int downlinkSubChannels = GetPhy ()->GetDownlinkSubChannels ().size (); |
| 114 |
| 115 Ptr<MobilityModel> mobility = GetPhy ()->GetDownlinkSpectrumPhy ()->GetMobilit
y ()->GetObject<MobilityModel> (); |
| 116 Vector speedVector = mobility->GetVelocity (); |
| 117 |
| 118 double speed = sqrt (pow (speedVector.x,2) + pow (speedVector.y,2)); |
| 119 |
| 120 NS_LOG_FUNCTION (this << mobility << speedVector << speed); |
| 121 |
| 122 if (speed < 3.) |
| 123 { |
| 124 speed = 0; |
| 125 } |
| 126 else if (speed < 30.) |
| 127 { |
| 128 speed = 3.; |
| 129 } |
| 130 else if (speed < 120.) |
| 131 { |
| 132 speed = 30.; |
| 133 } |
| 134 else |
| 135 { |
| 136 speed = 30; |
| 137 } |
| 138 |
| 139 NS_LOG_FUNCTION (this << mobility << speedVector << speed); |
| 140 |
| 141 |
| 142 /* |
| 143 * Jackes Model. |
| 144 * Jakes popularised a model for Rayleigh fading based on summing sinusoids |
| 145 * William C. Jakes, Editor (February 1, 1975). |
| 146 * Microwave Mobile Communications. |
| 147 * New York: John Wiley & Sons Inc. ISBN 0-471-43720-4 |
| 148 */ |
| 149 |
| 150 // number of path = M |
| 151 // x = 1 -> M=6, x = 2 -> M=8, x = 3 -> M=10, x = 4 -> M=12 |
| 152 int x = m_nbOfPaths->GetValue (); |
| 153 |
| 154 for (int i = 0; i < downlinkSubChannels; i++) |
| 155 { |
| 156 // StartJakes allow us to select a window of 0.5ms into the Jakes realizat
ion lasting 3s. |
| 157 int startJakes = m_startJakes->GetValue (); |
| 158 |
| 159 MultipathForTimeDomain multipathForTimeDomain; |
| 160 |
| 161 if (x == 1) |
| 162 { |
| 163 // SELECTED 6 MULTIPLE PATH FOR JAKES MODEL |
| 164 if (speed == 0) |
| 165 { |
| 166 for (int j = 0; j < 500; j++) |
| 167 { |
| 168 multipathForTimeDomain.push_back (multipath_M6_v_0 [j + startJ
akes]); |
| 169 } |
| 170 } |
| 171 if (speed == 3) |
| 172 { |
| 173 for (int j = 0; j < 500; j++) |
| 174 { |
| 175 multipathForTimeDomain.push_back (multipath_M6_v_3 [j + startJ
akes]); |
| 176 } |
| 177 } |
| 178 if (speed == 30) |
| 179 { |
| 180 for (int j = 0; j < 500; j++) |
| 181 { |
| 182 multipathForTimeDomain.push_back (multipath_M6_v_30 [j + start
Jakes]); |
| 183 } |
| 184 } |
| 185 if (speed == 120) |
| 186 { |
| 187 for (int j = 0; j < 500; j++) |
| 188 { |
| 189 multipathForTimeDomain.push_back (multipath_M6_v_120 [j + star
tJakes]); |
| 190 } |
| 191 } |
| 192 } |
| 193 |
| 194 else if (x == 2) |
| 195 { |
| 196 // SELECTED 6 MULTIPLE PATH FOR JAKES MODEL |
| 197 if (speed == 0) |
| 198 { |
| 199 for (int j = 0; j < 500; j++) |
| 200 { |
| 201 multipathForTimeDomain.push_back (multipath_M8_v_0 [j + startJ
akes]); |
| 202 } |
| 203 } |
| 204 if (speed == 3) |
| 205 { |
| 206 for (int j = 0; j < 500; j++) |
| 207 { |
| 208 multipathForTimeDomain.push_back (multipath_M8_v_3 [j + startJ
akes]); |
| 209 } |
| 210 } |
| 211 if (speed == 30) |
| 212 { |
| 213 for (int j = 0; j < 500; j++) |
| 214 { |
| 215 multipathForTimeDomain.push_back (multipath_M8_v_30 [j + start
Jakes]); |
| 216 } |
| 217 } |
| 218 if (speed == 120) |
| 219 { |
| 220 for (int j = 0; j < 500; j++) |
| 221 { |
| 222 multipathForTimeDomain.push_back (multipath_M8_v_120 [j + star
tJakes]); |
| 223 } |
| 224 } |
| 225 } |
| 226 |
| 227 else if (x == 3) |
| 228 { |
| 229 // SELECTED 6 MULTIPLE PATH FOR JAKES MODEL |
| 230 if (speed == 0) |
| 231 { |
| 232 for (int j = 0; j < 500; j++) |
| 233 { |
| 234 multipathForTimeDomain.push_back (multipath_M10_v_0 [j + start
Jakes]); |
| 235 } |
| 236 } |
| 237 if (speed == 3) |
| 238 { |
| 239 for (int j = 0; j < 500; j++) |
| 240 { |
| 241 multipathForTimeDomain.push_back (multipath_M10_v_3 [j + start
Jakes]); |
| 242 } |
| 243 } |
| 244 if (speed == 30) |
| 245 { |
| 246 for (int j = 0; j < 500; j++) |
| 247 { |
| 248 multipathForTimeDomain.push_back (multipath_M10_v_30 [j + star
tJakes]); |
| 249 } |
| 250 } |
| 251 if (speed == 120) |
| 252 { |
| 253 for (int j = 0; j < 500; j++) |
| 254 { |
| 255 multipathForTimeDomain.push_back (multipath_M10_v_120 [j + sta
rtJakes]); |
| 256 } |
| 257 } |
| 258 } |
| 259 |
| 260 else if (x == 4) |
| 261 { |
| 262 // SELECTED 6 MULTIPLE PATH FOR JAKES MODEL |
| 263 if (speed == 0) |
| 264 { |
| 265 for (int j = 0; j < 500; j++) |
| 266 { |
| 267 multipathForTimeDomain.push_back (multipath_M12_v_0 [j + start
Jakes]); |
| 268 } |
| 269 } |
| 270 if (speed == 3) |
| 271 { |
| 272 for (int j = 0; j < 500; j++) |
| 273 { |
| 274 multipathForTimeDomain.push_back (multipath_M12_v_3 [j + start
Jakes]); |
| 275 } |
| 276 } |
| 277 if (speed == 30) |
| 278 { |
| 279 for (int j = 0; j < 500; j++) |
| 280 { |
| 281 multipathForTimeDomain.push_back (multipath_M12_v_30 [j + star
tJakes]); |
| 282 } |
| 283 } |
| 284 if (speed == 120) |
| 285 { |
| 286 for (int j = 0; j < 500; j++) |
| 287 { |
| 288 multipathForTimeDomain.push_back (multipath_M12_v_120 [j + sta
rtJakes]); |
| 289 } |
| 290 } |
| 291 } |
| 292 else |
| 293 { |
| 294 std::cout << " ERROR: Jaks's Model, incorrect M value" << std::endl; |
| 295 } |
| 296 |
| 297 |
| 298 m_multipath->push_back (multipathForTimeDomain); |
| 299 } |
| 300 |
| 301 SetLastUpdate (); |
| 302 } |
| 303 |
| 304 double |
| 305 MultipathLossModel::GetValue (int subChannel) |
| 306 { |
| 307 NS_LOG_FUNCTION (this); |
| 308 if (NeedForUpdate ()) |
| 309 { |
| 310 SetValue (); |
| 311 SetLastUpdate (); |
| 312 } |
| 313 |
| 314 int now_ms = Simulator::Now ().GetSeconds () * 1000; |
| 315 int lastUpdate_ms = GetLastUpdate ().GetSeconds () * 1000; |
| 316 int index = now_ms - lastUpdate_ms; |
| 317 |
| 318 NS_LOG_FUNCTION (this << subChannel << now_ms |
| 319 << lastUpdate_ms << index << m_multipath->at (subChannel
).at (index)); |
| 320 |
| 321 return m_multipath->at (subChannel).at (index); |
| 322 } |
| 323 |
| 324 |
| 325 |
| 326 } // namespace ns3 |
OLD | NEW |