bit_goal = np.ceil(1/cfg.give_up_value) * cfg.certainty
max_tries = int(np.ceil(bit_goal / (cfg.bits_per_slot * cfg.slot_per_frame)))

branches = np.arange(1, cfg.branches+1, 1)

shape = (len(branches), len(snr_todo))
# nan or "not a number" values are ignored when plotting
probs = np.full(shape, np.nan)
snrs = np.full(shape, np.nan)

for j, branch in enumerate(branches):
    branch_probs = []
    branch_snrs = []
    for i, gamma in enumerate(snr_todo):
        # create channel with the curretn branch and snr
        ch = channel.RayleighAWGNChannel(N=branch, snr=gamma)
        errors = 0
        numberOfBits = 0

        for k in range(max_tries):
            fram = make_frame_array()
            for slot in fram:
                signal = gfsk.modulate(slot)
                recieved, h = ch.run(signal)
                hat_recieved, _ = diversity_technique.selection_from_power(
                    recieved)
                hat_slot = gfsk.demodulate(hat_recieved)
                err, n = common.count_symbol_errors(slot, hat_slot)
                errors += err
                numberOfBits += n
            ch.frame_sent()
import ad_path
from antenna_diversity import channel
import numpy as np
import matplotlib.pyplot as plt
import math
ad_path.nop()


def calculate_db(input):
    return 10 * math.log10(input)


branches = 3
sampler = channel.RayleighAWGNChannel(branches, 10)

# Run a thausant of dect frames
runs = 100
frame_number = np.arange(runs)
res = np.empty((runs, branches))
resDb = np.empty((runs, branches))

signal = np.ones(1)
for i in frame_number:
    _, result = sampler.run(signal)
    res[i] = result
    for j, br in enumerate(result):
        resDb[i][j] = calculate_db(br)
    sampler.frame_sent()


fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 6))
def make_frame_array():
    frameArray = np.empty(shape=(slot_per_frame, bits_per_slot))
    for i in range(slot_per_frame):
        frameArray[i] = np.random.randint(2, size=bits_per_slot)
    return frameArray


snr = np.arange(10, 17.5, 2.5)

branches = np.arange(1, 6, 1)
prob = np.empty(shape=(len(branches), len(snr)))
base_tries = 5000

errors = 0
numberOfTries = 0
ch = channel.RayleighAWGNChannel(N=2, snr=10)

tries = 1000
ind_1_arr = np.empty(shape=(tries))
ind_2_arr = np.empty(shape=(tries))

for ty in range(tries):
    fram = make_frame_array()
    for slot in fram:
        signal = gfsk.modulate(slot)
        recieved, h = ch.run(signal)
        hat_real_recieved, ind1 = real_selection(recieved)
        hat_recieved, ind2 = diversity_technique.selection_from_power(recieved)
        ind_1_arr[ty] = ind1
        ind_2_arr[ty] = ind2
        hat_slot = gfsk.demodulate(hat_recieved)
Beispiel #4
0
import time

import ad_path
from antenna_diversity import modulation, encoding, channel, \
    diversity_technique
from antenna_diversity.protocols import dect

ad_path.nop()


M = 2
enc = encoding.SymbolEncoder(M)
mod = modulation.PSK(M)

# Nice shorthand /s
chnl = channel.RayleighAWGNChannel(2, 10)


def run_sim() -> bool:
    # Create random dect packet
    payload = os.urandom(40)
    data = dect.Full(payload).to_bytes()

    # Run through simulation chain
    symbols = enc.encode_msb(data)
    moded = mod.modulate(symbols)
    recv, h = chnl.run(moded)
    combined, _ = diversity_technique.selection_from_power(recv)

    symbols_hat = mod.demodulate(combined)
    data_hat = enc.decode_msb(symbols_hat)