import math


def calculate_distance_km_given_pl_abg_nlos(acceptable_PL_ABG_NLOS, radio_frequency, alpha, beta, gamma, sigma):
    """
    Calculate distance given Free-space path loss (FSPL)
    Formula:
    PL_ABG_NLOS (in dB) = 10 * alpha * log(d) + beta + 10 * gamma * log(f) + sigma

    distance in meters formula
    d = 10 ** (1/(10 * alpha) * (PL_ABG_NLOS - beta - 10 * gamma * log(f) - sigma))
    Distance from path loss in db, radio frequency, alpha, beta, gamma, sigma

    :param acceptable_PL_ABG_NLOS:
    :param radio_frequency:
    :param alpha: alpha
    :param beta: beta (in dB)
    :param gamma: gamma
    :param sigma: sigma (in dB)
    :return:
    """
    return round((10 ** (1 / (10 * alpha) * (acceptable_PL_ABG_NLOS - beta - sigma -
                                             (10 * gamma * math.log10(radio_frequency / 1000000000)))))/1000, 2)