示例#1
0
 def plot(self, rx_sensitivity, tx_power, freq, h_t=100, h_r=100,
          save=False, show=False):
     """
     Plot received power versus increasing separation range
     :param rx_sensitivity: min received power threshold for reception (W)
     :param tx_power: transmitted power (W)
     :param freq: frequency of transmission (Hz)
     :param h_t: height of transmitter above ground (m)
     :param h_r: height of receiver above ground (m)
     :param save: save the plot (bool)
     :param show: show the plot (bool)
     """
     from matplotlib import pyplot as plt
     tx_pos = [0, 0, h_t]
     CR = self.inverse(rx_sensitivity, tx_power, freq, h_t, h_r)
     xmax = min(2*CR, 100000)
     xs = np.linspace(0, xmax, 10000)
     rx_pos = [util.gps_offset(tx_pos, 0, x) + (h_r,) for x in xs]
     ys = [self.received_power(tx_power, freq, tx_pos, rx_pos_i)
           for rx_pos_i in rx_pos]
     plt.plot(xs, ys, label=self.model_name)
     plt.xlabel("Separation Distance (m)")
     plt.ylabel("Received Power (W)")
     plt.title(self.model_name)
     plt.xlim((0, xmax))
     rx_pos = util.gps_offset(tx_pos, 0, xmax/2) + (h_r,)
     rx_power_at_CR = self.received_power(tx_power, freq, tx_pos, rx_pos)
     plt.ylim((0, 3*rx_power_at_CR))
     plt.legend(loc=3)
     plt.grid()
     if save:
         plt.savefig(self.model_name.replace(" ", ""))
     if show:
         plt.show()
示例#2
0
 def transmit(self):
     if self.transmitter is None:
         return
     data = {"pos": self.pos[:], "vel": self.vel[:]}
     pos_gps = util.gps_offset(self.home_gps, self.pos[0],
                               self.pos[1]) + (self.pos[2], )
     msg = self.transmitter.transmit(self.current_time, self.callsign,
                                     pos_gps, data)
     return msg
示例#3
0
 def receive(self):
     if self.receiver is None:
         return
     pos_gps = util.gps_offset(self.home_gps, self.pos[0],
                               self.pos[1]) + (self.pos[2], )
     msgs = self.receiver.receive(self.current_time, pos_gps)
     for m in msgs:
         if m.sender_id == self.callsign:
             continue
         self.input_traffic(m.sender_id, m.data["pos"], m.data["vel"])
示例#4
0
 def heatmap(self,
             rx_sensitivity,
             tx_power,
             freq,
             h_t=100,
             h_r=100,
             save=False,
             show=False):
     """
     Plot a 2D map of reception probability
     :param rx_sensitivity: min received power threshold for reception (W)
     :param tx_power: transmitted power (W)
     :param freq: frequency of transmission (Hz)
     :param h_t: height of transmitter above ground (m)
     :param h_r: height of receiver above ground (m)
     :param save: save the plot (bool)
     :param show: show the plot (bool)
     """
     from matplotlib import pyplot as plt
     tx_pos = [0, 0, h_t]
     CR = self.communication_range(rx_sensitivity, tx_power, freq, h_t, h_r)
     range_max = min(2 * CR, 100000)
     xs = np.linspace(-range_max, range_max, 100)
     ys = np.linspace(-range_max, range_max, 100)
     heatmap = np.empty((xs.size, ys.size))
     for i in range(len(xs)):
         for j in range(len(ys)):
             rx_pos = util.gps_offset(tx_pos, xs[i], ys[j]) + (h_r, )
             heatmap[i, j] = self.p_reception(tx_power, freq, tx_pos,
                                              rx_pos, rx_sensitivity)
     extent = [xs[0], xs[-1], ys[0], ys[-1]]
     plt.imshow(heatmap, extent=extent)
     cb = plt.colorbar()
     cb.set_label("Probability of Reception")
     plt.title(self.model_name)
     plt.ylabel('y (m)')
     plt.xlabel('x (m)')
     if save:
         plt.savefig("%s_map.png" % self.model_name.replace(" ", ""))
     if show:
         plt.show()