-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_ber_curve.py
77 lines (66 loc) · 2.57 KB
/
create_ber_curve.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Copyright (C) 2023 Karl-Ludwig Besser
This program is used in the article:
"Securing Data in Multimode Fibers by Exploiting Mode-Dependent Light
Propagation Effects" (S. Rothe, K.-L. Besser, D. Krause, R. Kuschmierz, N.
Koukourakis, E. Jorswieck, J. Czarske. Research, vol. 6: 0065, Jan. 2023.
DOI:10.34133/research.0065).
License:
This program is licensed under the GPLv3 license. If you in any way use this
code for research that results in publications, please cite our original
article listed above.
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.
Author: Karl-Ludwig Besser, Technische Universität Braunschweig
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from util import save_results, RESULTS_DIR
def main(ber_files, plot=False, export=False):
data = []
for _ber_file in ber_files:
_df = pd.read_csv(_ber_file, sep="\t")
data.append(_df)
data = pd.concat(data, ignore_index=True)
results = {"bob": [],
"eve": [],
}
for k, _data_k in data.groupby("secrate"):
for _name in results:
_data_user = _data_k[_name]
_mean = np.mean(_data_user)
_std = np.std(_data_user, ddof=1)
if not np.isfinite(_std):
_std = 0
_min = _mean-_std
_max = _mean+_std
results[_name].append((k, _mean, _min, _max))
results = {k: np.array(v) for k, v in results.items()}
if export:
for _name, _results in results.items():
outfile = f"ber-statistic-{_name}.dat"
_results = pd.DataFrame(_results)
_results.columns = ["secrate", "mean", "min", "max"]
save_results(RESULTS_DIR, _results, snr=None, filename=outfile)
if plot:
fig, axs = plt.subplots()
for _name, _results in results.items():
_rate, _mean, _min, _max = _results.T
axs.fill_between(_rate, _min, _max, alpha=.5)
axs.plot(_rate, _mean, label=_name)
axs.legend()
axs.set_xlabel("Secrecy Rate")
axs.set_ylabel("BER")
return results
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("ber_files", nargs="+")
parser.add_argument("--plot", action="store_true")
parser.add_argument("--export", action="store_true")
args = vars(parser.parse_args())
main(**args)
plt.show()