Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Commits
0a8fae3e
Commit
0a8fae3e
authored
Dec 10, 2021
by
Benjamin Becker
Browse files
ricean fading
parent
26fb493b
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/linklayer/mac/wifi/Ieee80211AdHocMac.java
View file @
0a8fae3e
...
...
@@ -611,7 +611,6 @@ public class Ieee80211AdHocMac extends AbstractMacLayer {
.
getMac
(
eventInfo
.
getReceiver
());
if
(
link
.
isConnected
())
{
WifiState
recMacState
=
recMac
.
getWifiState
();
WifiMode
dataMode
=
rateManager
.
getUnicastDataMode
(
recMac
...
...
src/de/tud/kom/p2psim/impl/topology/views/wifi/phy/propagation/loss/LogDistancePropagationLossModelNormalDistribution.java
View file @
0a8fae3e
...
...
@@ -24,6 +24,7 @@ import java.util.HashMap;
import
java.util.Random
;
import
de.tud.kom.p2psim.api.topology.views.wifi.phy.PropagationLossModel
;
import
de.tud.kom.p2psim.impl.topology.placement.RandomPositionDistributionCircle
;
import
de.tudarmstadt.maki.simonstrator.api.Randoms
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
...
...
@@ -65,6 +66,9 @@ public class LogDistancePropagationLossModelNormalDistribution
*/
private
double
referenceDistance
=
1
;
private
Random
random
=
Randoms
.
getRandom
(
LogDistancePropagationLossModelNormalDistribution
.
class
);
/**
* Frequency in Hz<br>
* Default 2,4 GHz
...
...
@@ -79,73 +83,123 @@ public class LogDistancePropagationLossModelNormalDistribution
/**
* The reference Loss
*/
private
double
referenceLoss
=
20
*
Math
.
log10
(
4
*
Math
.
PI
*
referenceDistance
/
lambda
);
private
HashMap
<
Location
,
HashMap
<
Location
,
Double
>>
pathLosses
=
new
HashMap
<>();
private
HashMap
<
Double
,
Double
>
pathLosses0
=
new
HashMap
<>();
long
lastSave
=
-
1
;
private
HashMap
<
Double
,
Double
>
pathLossesWithShadowing
=
new
HashMap
<>();
long
nextSave
=
-
1
;
static
double
avg
=
0
;
static
int
count
=
0
;
static
double
sum
=
0
,
sumh
=
0
;
@Override
public
double
getRxPowerDbm
(
double
txPowerDbm
,
Location
a
,
Location
b
)
{
double
distance
=
a
.
distanceTo
(
b
);
double
distance
=
a
.
distanceTo
(
b
);
if
(
distance
<=
referenceDistance
)
{
return
txPowerDbm
;
}
double
rxc
;
if
(
Time
.
getCurrentTime
()
/
Time
.
SECOND
>
lastSave
)
{
// reset after 100 (nanoseconds)
if
((
Time
.
getCurrentTime
())
>
nextSave
)
{
pathLosses
=
new
HashMap
<>();
las
tSave
=
Time
.
getCurrentTime
()
/
Time
.
SECOND
;
nex
tSave
=
(
Time
.
getCurrentTime
()
/
100L
)
*
100L
+
100L
;
}
HashMap
<
Location
,
Double
>
pathlossesA
;
HashMap
<
Location
,
Double
>
lossAndFadings
;
if
(!
pathLosses
.
containsKey
(
a
))
{
pathlossesA
=
new
HashMap
<>();
pathLosses
.
put
(
a
,
pathlossesA
);
}
else
{
pathlossesA
=
pathLosses
.
get
(
a
);
lossAndFadings
=
new
HashMap
<>();
pathLosses
.
put
(
a
,
lossAndFadings
);
}
else
{
lossAndFadings
=
pathLosses
.
get
(
a
);
}
if
(
pathlossesA
.
containsKey
(
b
))
{
rxc
=
pathlossesA
.
get
(
b
);
if
(
lossAndFadings
.
containsKey
(
b
))
{
rxc
=
lossAndFadings
.
get
(
b
);
}
else
{
double
pathLoss0
;
if
(
pathLosses0
.
containsKey
(
distance
))
{
pathLoss0
=
pathLosses0
.
get
(
distance
);
}
else
{
pathLoss0
=
10
*
exponent
*
Math
.
log10
(
distance
/
referenceDistance
);
pathLosses0
.
put
(
distance
,
pathLoss0
);
// random seed, based on sender/receiver position
long
positionBasedRandomSeed
=
(((((((((((((((
long
)
a
.
getLatitudeOrY
()
%
776531419
)
*
(
long
)
b
.
getLatitudeOrY
()
%
776531419
)
*
(
long
)
a
.
getLongitudeOrX
()
%
776531419
)
*
(
long
)
b
.
getLongitudeOrX
()
%
776531419
)
*
(
long
)
a
.
getLatitudeOrY
()
%
776531419
)
*
(
long
)
b
.
getLatitudeOrY
()
%
776531419
)
*
(
long
)
a
.
getLongitudeOrX
()
%
776531419
)
*
(
long
)
b
.
getLongitudeOrX
()
%
776531419
)
*
(
long
)
a
.
getLatitudeOrY
()
%
776531419
)
*
(
long
)
b
.
getLatitudeOrY
()
%
776531419
)
*
(
long
)
a
.
getLongitudeOrX
()
%
776531419
)
*
(
long
)
b
.
getLongitudeOrX
()
%
776531419
)
*
(
long
)
a
.
getLatitudeOrY
()
%
776531419
)
*
(
long
)
a
.
getLongitudeOrX
()
%
776531419
);
// random seed, based on time
long
timeBasedRandomSeed
=
(((((
nextSave
*
nextSave
%
512927377
)
*
nextSave
%
512927377
)
*
nextSave
%
512927377
)
*
nextSave
%
512927377
)
*
nextSave
%
512927377
);
double
pathLossWithShadowing
;
if
(
pathLossesWithShadowing
.
containsKey
(
distance
))
{
pathLossWithShadowing
=
pathLossesWithShadowing
.
get
(
distance
);
}
else
{
// random which is constant for a pair of nodes; links are
// symmetric
Random
r1
=
new
Random
(
positionBasedRandomSeed
);
Random
r
=
new
Random
(
positionBasedRandomSeed
/
2
+
r1
.
nextLong
()
/
2
);
// SHADOW FADING
double
shadowFading
=
r
.
nextGaussian
()
*
5
;
// LOG-DISTANCE PATH LOSS
double
pathLoss
=
10
*
exponent
*
Math
.
log10
(
distance
/
referenceDistance
);
pathLossWithShadowing
=
pathLoss
+
shadowFading
;
pathLossesWithShadowing
.
put
(
distance
,
pathLossWithShadowing
);
}
double
x
=
Double
.
hashCode
(
Double
.
hashCode
(
a
.
getLatitudeOrY
())
/
4
.
+
Double
.
hashCode
(
b
.
getLatitudeOrY
())
/
4
.
+
Double
.
hashCode
(
a
.
getLongitudeOrX
())
/
4
.
+
Double
.
hashCode
(
b
.
getLongitudeOrX
())
/
4
.);
long
y
=
Time
.
getCurrentTime
()
/
Time
.
SECOND
;
Random
r1
=
new
Random
(
y
);
Random
r
=
new
Random
((
long
)
x
+
r1
.
nextLong
());
double
gaussian
=
r
.
nextGaussian
();
double
sigma
=
6.0
;
// 58:722.0,456.0
// 1:803.0,599.0
// if (a.getLatitudeOrY() == 456.0 && a.getLongitudeOrX() == 722.0) {
// if (b.getLatitudeOrY() == 599.0 && b.getLongitudeOrX() == 803.0) {
// System.out.println(Time.getFormattedTime() + ": " + gaussian);
// }
// }
double
pathLoss
=
pathLoss0
+
gaussian
*
sigma
;
rxc
=
-
this
.
referenceLoss
-
pathLoss
;
pathlossesA
.
put
(
b
,
rxc
);
// random which is constant for a pair of nodes, at a given time;
// links are symmetric
Random
r1
=
new
Random
(
timeBasedRandomSeed
);
Random
r
=
new
Random
((
positionBasedRandomSeed
/
3
+
r1
.
nextLong
()
/
3
+
r1
.
nextLong
()
/
3
));
// RICEAN FADING
// constants: K, mean, sigma
double
K
=
0
;
double
mean
=
Math
.
sqrt
(
K
/
(
2
*
(
K
+
1
)));
double
sigma
=
Math
.
sqrt
(
1
/
(
2
*
(
K
+
1
)));
// gaussian randoms
double
x
=
mean
+
r
.
nextGaussian
()
*
sigma
;
double
y
=
mean
+
r
.
nextGaussian
()
*
sigma
;
// h
double
h
=
Math
.
sqrt
(
x
*
x
+
y
*
y
);
double
riceanFading
=
Math
.
log10
(
h
);
// total loss of the link
rxc
=
-
referenceLoss
-
pathLossWithShadowing
-
riceanFading
;
lossAndFadings
.
put
(
b
,
rxc
);
}
return
txPowerDbm
+
rxc
;
}
/**
* Calculates watt to dBm.
*
* @param w
* The watt, which should be calculated to dBm.
* @return The given watt as dBm.
*/
public
static
double
wToDbm
(
double
w
)
{
double
mw
=
w
*
1000.0
;
return
Math
.
log10
(
mw
)
*
10.0
;
}
public
static
double
dbmToW
(
double
dbm
)
{
double
mw
=
Math
.
pow
(
10.0
,
dbm
/
10.0
);
return
mw
/
1000.0
;
}
@Override
public
void
setFrequency
(
long
frequency
)
{
this
.
frequency
=
frequency
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment