def get_filter_mag(name, kalmanRMag, kalmanQMag, windowSizeMag): if name == "raw": return raw.RawFilter() if name == "kalman": return kalman.KalmanFilter(kalmanRMag, kalmanQMag) if name == "movingAverage": return movingAverage.MovingAverageFilter(windowSizeMag)
def get_filter_ble(name, noOfBeacons, kalmanRBLE, kalmanQBLE, windowSizeBLE): if name == "raw": return [raw.RawFilter() for i in range(noOfBeacons)] if name == "kalman": return [ kalman.KalmanFilter(kalmanRBLE, kalmanQBLE) for i in range(noOfBeacons) ] if name == "movingAverage": return [ movingAverage.MovingAverageFilter(windowSizeBLE) for i in range(noOfBeacons) ]
with open(newfile, 'w') as f: f.write(json_data) rssi_list = [x["rssi"] for x in data_list] save_path = os.getcwd() + "/Graphs/rssi_vs_time/" if not(os.path.isdir(save_path)) : os.mkdir(save_path) plt.figure(figsize=(16, 10)) plt.xlabel("Time in seconds", fontsize=20) plt.ylabel("RSSI in dBm", fontsize=20) plt.yticks(np.arange(-85, -59, 5.0), fontsize=20) plt.xticks(np.arange(0, 301, 50), fontsize=20) plt.xlim([0, 301]) plt.ylim([-85, -59]) plt.grid() kalmanFilter = kalman.KalmanFilter(kalmanR, kalmanQ) kalman_list = [] for rssi in rssi_list : kalman_list.append(kalmanFilter.filter(rssi)) movingAverageFilter = movingAverage.MovingAverageFilter(5) moving_list = [] for rssi in rssi_list : moving_list.append(movingAverageFilter.filter(rssi)) plt.plot([x for x in range(1, 301)], rssi_list, "-b") plt.plot([x for x in range(1, 301)], kalman_list, "-r") plt.plot([x for x in range(1, 301)], moving_list, "-g") plt.legend(["Raw","Kalman Filter", "Moving Average"], fontsize=20) filename = os.path.join(save_path, "rssi_vs_time_beacon" + str(beaconNo)) plt.savefig(filename) plt.close()