-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchannel_erasure.py
55 lines (41 loc) · 1.2 KB
/
channel_erasure.py
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
"""
This module contains various channel erasure models
"""
import numpy as np
def bernouli_erasure(success_prob):
"""
It simulates a bernouli erasure channel
Parameters
----------
success_prob : `float`
Probability that the message will be sucessfully delivered
Returns
-------
`bool`
Whether the current packet will be delivered or not
"""
x = np.random.uniform(0,1)
return True if x < success_prob else False
def gilbert_elliot_erasure(previous_status, Pbg, Pgb):
"""
Simulates a Gilbert-Elliot channel as a two state markov chain
Parameters
----------
previous_state : `bool`
Whether the previous message was delivered or not
Pbg : `float`
Probability of state transition from bad to good
Pgb : `float`
Probability of state transition from good to bad
Returns
-------
`bool`
Whether the current packet will be delivered or not
"""
# Check if packet_number-1 was lost
if not previous_status:
x = np.random.uniform(0,1)
return True if x < Pbg else False
else:
x = np.random.uniform(0,1)
return True if x < 1 - Pgb else False