def comm_ue(self, satellite, ue, comm_t):
        """
        Args:
        satellite (list of tuple): {'s1': [1,2,..])
        ue (numpy array): ([r,i,theta], tp)
        comm_t: UPLINK or DOWNLINK

        Return:
        throughput (numpy array): numpy.array([1,2,3,4...])

        .. note::
        TODO: multiple UEs and satellite
        """
        # ss_idx: satellite system idx. s_idx: satellite idx in system
        for ss_idx, s_idx in satellite.iteritems():
            s_pos = self.satellites[ss_idx].satellite_pos(s_idx)
        bw = self.satellites[ss_idx].earth_bw
        f = self.satellites[ss_idx].get_antenna_param(s_idx, 'earth_f')
        if comm_t == UPLINK:
            noise = cal_thermal_noise(bw, 2.73)
            tp = ue.tp
            tr_pos = ue.pos
            rv_pos = s_pos
            gt = 0
            gr = self.satellites[ss_idx].get_antenna_param(s_idx, 'gain')
        else:
            noise = cal_thermal_noise(bw, 290)
            tp = self.satellites[ss_idx].get_antenna_param(s_idx, 'max_tp')
            tr_pos = s_pos
            rv_pos = ue.pos
            gt = self.satellites[ss_idx].get_antenna_param(s_idx, 'gain')
            gr = 0
        rp = cal_recv_power(tr_pos,
                            rv_pos,
                            10**(tp / 10),
                            1,
                            1,
                            dist_func=cal_dist_3d,
                            dist_args=[],
                            pl_func=cal_fiirs,
                            pl_args=[f, gt, gr],
                            fading_func=gen_rician,
                            fading_args=[10, 1],
                            shadowing_func=gen_logNshadowing,
                            shadowing_args=[4])
        throughput = cal_shannon_cap(bw, rp, noise=noise)
        return throughput, rp
Exemple #2
0
def cal_D2D_opt_tp(d2d_ues, cc_ues,
                   pmax_d, pmax_c,
                   g_d2d_bs, g_cc, g_d2d, g_cc_d2d,
                   sinr_d2d, sinr_cc,
                   bw, alpha, freq):
    """
    This function calculates the RRM for D2D UEs (Device-to-Device Communications
Underlaying Cellular Networks)
    Args:
        d2d_ues (numpy array): d2d_ues positions
        g_d2d_cc (): channel gain between d2d and cc ues
        kappa (float): scale param for cc
        bw (float): bandwidth for d2d_ues
        alpha (float): pathloss parameter
        freq (float): frequency

    Returns:
        list of numpy array. The transmit power of D2D UEs and CC UEs.

    ::TODO: only consider one D2D
    """
    noise = cal_thermal_noise(bw, 273)
    # set up reuse array
    idx_avail = []
    p_c = (g_d2d*sinr_cc+g_d2d_bs*sinr_cc*sinr_d2d)*noise / \
          (g_d2d*g_cc-sinr_d2d*sinr_cc*g_cc_d2d*g_d2d_bs)
    p_d2d = (g_cc_d2d*sinr_cc*sinr_d2d+g_cc*sinr_d2d)*noise / \
            (g_d2d*g_cc-sinr_cc*sinr_d2d*g_cc_d2d*g_d2d_bs)
    for i in range(cc_ues.size):
        if (p_d2d > 0 and p_d2d <= pmax_c) and (p_c > 0 and p_c <= pmax_c):
            idx_avail.append(i)

    # calculate optimal transmit power
    # FIXME: one D2D
    def _argmax(tp_pairs):
        f = 0
        idx = 0
        for i, (pc, pd) in enumerate(tp_pairs):
            fc = np.log2(1+pc*g_cc/(pd*g_d2d_bs+noise))+np.log2(1+pd*g_d2d/(pc*g_cc_d2d+noise))
            if fc > f:
                f = fc
                idx = i
        return tp_pairs[idx]

    p1 = (pmax_c*g_cc_d2d[idx_avail]+noise)*sinr_d2d/g_d2d
    p2 = (pmax_c*g_cc[idx_avail]-sinr_cc*noise)/(sinr_cc*g_d2d_bs)
    p3 = (pmax_d*g_d2d-sinr_d2d*noise)/(sinr_d2d*g_cc_d2d[idx_avail])
    p4 = (pmax_d*g_d2d_bs+noise)*sinr_cc/g_cc[idx_avail]
    opt_tp_pairs = []
    for i, j in enumerate(idx_avail):
        if (pmax_c*g_cc[i])/(noise+pmax_d*g_d2d_bs) <= sinr_cc:
            opt_tp_pairs.append(_argmax([(pmax_c, p1[j]), (pmax_c, p2[j])]))
        elif pmax_d*g_d2d/(noise+pmax_c*g_cc_d2d[i]) < sinr_d2d:
            opt_tp_pairs.append(_argmax([(p3[j], pmax_d), (p4[j], pmax_d)]))
        else:
            opt_tp_pairs.append(_argmax([(pmax_c, p1[j]), (pmax_c, pmax_d), (p4[j], pmax_d)]))

    # calculate channel allocation.
    return _argmax(opt_tp_pairs)
Exemple #3
0
def cal_D2D_basic_tp(d2d_ues, g_d2d_bs, kappa, bw, alpha, freq):
    """
    This function calculates the transmit power for D2D UEs (Spectrum Sharing Scheme Between Cellular Users and Ad-hoc Device-to-Device Users)
    Args:
        d2d_ues (numpy array): d2d_ues positions
        g_d2d_cc (): channel gain between d2d and cc ues
        kappa (float): scale param for cc
        bw (float): bandwidth for d2d_ues
        alpha (float): pathloss parameter
        freq (float): frequency

    Returns:
        numpy array. The transmit power of D2D UEs.
    """
    noise = cal_thermal_noise(bw, 273)
    pathloss = cal_umi_nlos(np.abs(d2d_ues), alpha, freq)
    return (kappa - 1) * pathloss * noise / g_d2d_bs
    def intra_comm(self, start, dest, comm_t=INTRA_COMM):
        """
        Args:
        start (dict): {system_key: idx_list (list, None for all)},
        end (dict): {system_key: idx_list (list, None for all)}
        .. note::
        The elements in start and end should be consistent, e.g. all elements in start/end are satellites or earth stations.

        Returns:
        Shannon capacity (numpy array): array of the shannon capacity between all trs and rvs.
        """
        tr_pos = np.array([[0, 0, 0]])
        rv_pos = np.array([[0, 0, 0]])
        f = np.array([])
        gt = np.array([])
        gr = np.array([])
        bw = np.array([])
        tp = np.array([])
        n = 0
        for key, idx in start.iteritems():
            if comm_t == INTRA_COMM:
                s = self.satellites[key]
                tr_pos = np.append(tr_pos, s.satellite_pos(idx), axis=0)
                f = np.append(f, s.get_antenna_param(idx, 'intra_f'))
                bw = np.append(bw, s.intra_bw * np.ones(len(idx)))
                tp = np.append(tp, s.get_antenna_param(idx, 'max_tp'))
                gt = np.append(gt, s.get_antenna_param(idx, 'gain'))
            elif comm_t == DOWNLINK:
                s = self.satellites[key]
                tr_pos = np.append(tr_pos, s.satellite_pos(idx), axis=0)
                f = np.append(f, s.get_antenna_param(idx, 'earth_f'))
                bw = np.append(bw, s.earth_bw * np.ones(len(idx)))
                tp = np.append(tp, s.get_antenna_param(idx, 'max_tp'))
                gt = np.append(gt, s.get_antenna_param(idx, 'gain'))
            else:
                s = self.satellites[key].stations
                tr_pos = np.append(tr_pos, s.stations.station_pos(idx), axis=0)
                f = np.append(f, s.stations.get_antenna_param(idx, 'f'))
                bw = np.append(bw, s.stations.bw * np.ones(len(idx)))
                tp = np.append(tp, s.stations.get_antenna_param(idx, 'max_tp'))
                gt = np.append(gt, s.stations.get_antenna_param(idx, 'gain'))
            n = n + len(idx)
        for key, idx in dest.iteritems():
            if comm_t == INTRA_COMM or UPLINK:
                e = self.satellites[key]
                rv_pos = np.append(rv_pos, e.satellite_pos(idx), axis=0)
                gr = np.append(gr, e.get_antenna_param(idx, 'gain'))
            else:
                e = self.satellites[key].stations
                rv_pos = np.append(rv_pos, e.stations.station_pos(idx), axis=0)
                gr = np.append(gr, e.sations.get_antenna_param(idx, 'gain'))
        tr_pos = tr_pos[1:, :]
        rv_pos = rv_pos[1:, :]
        rp = cal_recv_power(tr_pos,
                            rv_pos,
                            10**(tp / 10),
                            n,
                            1,
                            dist_func=cal_dist_3d,
                            dist_args=[],
                            pl_func=cal_fiirs,
                            pl_args=[f, gt, gr],
                            fading_func=gen_rician,
                            fading_args=[10, 1],
                            shadowing_func=gen_logNshadowing,
                            shadowing_args=[4])
        if comm_t == INTRA_COMM or comm_t == UPLINK:
            noise = cal_thermal_noise(bw * 1e6, 2.73)
        else:
            noise = cal_thermal_noise(bw * 1e6, 290)
        throughput = cal_shannon_cap(bw * 1e6, rp, noise=noise)
        return throughput