add files via upload
This commit is contained in:
56
LOSS.py
Normal file
56
LOSS.py
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import numpy as np
|
||||||
|
import math
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# --- Configuration ---
|
||||||
|
#folder_path = input("Enter the folder containing the IQ data files: ")
|
||||||
|
if 1 == len(sys.argv):
|
||||||
|
print("No args provided and default folder \"DAT\" not found.")
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
folder_path = sys.argv[1]
|
||||||
|
|
||||||
|
count = -1 # Change this if you want to limit the number of samples per file
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
losses = [0.0,0.0,0.0,0.0,0.0]
|
||||||
|
# --- Processing Loop ---
|
||||||
|
for filename in os.listdir(folder_path):
|
||||||
|
full_path = os.path.join(folder_path, filename)
|
||||||
|
|
||||||
|
# Process only files, not directories
|
||||||
|
if not os.path.isfile(full_path):
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
data = np.fromfile(full_path, dtype=np.complex64, count=count)
|
||||||
|
|
||||||
|
if len(data) == 0:
|
||||||
|
print(f"{filename}: File is empty or unreadable.")
|
||||||
|
continue
|
||||||
|
|
||||||
|
meanVal = np.mean(np.abs(data))
|
||||||
|
|
||||||
|
print(f"{filename} :: loss of {meanVal:.2f} dB")
|
||||||
|
|
||||||
|
losses[i] = meanVal
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"{filename}: Error processing file - {e}")
|
||||||
|
|
||||||
|
meanAll = 0.0
|
||||||
|
|
||||||
|
j = 0
|
||||||
|
for l in losses:
|
||||||
|
meanAll += losses[j]
|
||||||
|
j += 1
|
||||||
|
|
||||||
|
j += 1
|
||||||
|
meanAll /= j
|
||||||
|
|
||||||
|
print(f"Mean path loss: {meanAll:.2f} dB")
|
||||||
|
print(f"total {i} files processed")
|
||||||
41
SINGLELINES.py
Normal file
41
SINGLELINES.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import numpy as np
|
||||||
|
import math
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# --- Configuration ---
|
||||||
|
#folder_path = input("Enter the folder containing the IQ data files: ")
|
||||||
|
if 1 == len(sys.argv):
|
||||||
|
if os.path.isdir("DAT"):
|
||||||
|
folder_path = "DAT"
|
||||||
|
else:
|
||||||
|
print("No args provided and default folder \"DAT\" not found.")
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
folder_path = sys.argv[1]
|
||||||
|
|
||||||
|
count = -1 # Change this if you want to limit the number of samples per file
|
||||||
|
|
||||||
|
# --- Processing Loop ---
|
||||||
|
for filename in os.listdir(folder_path):
|
||||||
|
full_path = os.path.join(folder_path, filename)
|
||||||
|
|
||||||
|
# Process only files, not directories
|
||||||
|
if not os.path.isfile(full_path):
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
data = np.fromfile(full_path, dtype=np.complex64, count=count)
|
||||||
|
|
||||||
|
if len(data) == 0:
|
||||||
|
print(f"{filename}: File is empty or unreadable.")
|
||||||
|
continue
|
||||||
|
|
||||||
|
meanVal = np.mean(np.abs(data))
|
||||||
|
#print(f"\nFile: {filename}")
|
||||||
|
print(f"Instantaneous Power for {filename} = " + str(10 * math.log10(meanVal / 50)))
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"{filename}: Error processing file - {e}")
|
||||||
37
avg-and-stdev.py
Normal file
37
avg-and-stdev.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from statistics import stdev
|
||||||
|
|
||||||
|
e5m = -19.567076092915567 -20.05316841156921 -18.774664683716043 -20.252929968934183 -19.01518926375179
|
||||||
|
e5m /= 5
|
||||||
|
|
||||||
|
e10m = -22.17792627372312 -26.5983685883656 -22.797848894157955-23.014822745152888-21.45208671888342
|
||||||
|
e10m /= 5
|
||||||
|
|
||||||
|
e15m = -25.20854283824081-25.196382621588043-27.146880284259304-23.50194049443653-26.735523841588087
|
||||||
|
e15m /= 5
|
||||||
|
|
||||||
|
e185m = -26.391715760893703-28.1335104958795-29.153177713518723-29.847186387317596-30.558908425543827
|
||||||
|
e185m /= 5
|
||||||
|
|
||||||
|
e235m = -31.755831065931034-31.883960187854985-32.063876077498804-31.643081143951544-32.45807181713604
|
||||||
|
e235m /= 5
|
||||||
|
|
||||||
|
for i in [e5m, e10m, e15m, e185m, e235m]:
|
||||||
|
print(f"avg: {i:.4f}")
|
||||||
|
|
||||||
|
# standard deviation
|
||||||
|
|
||||||
|
e5m = [-19.567076092915567, -20.05316841156921, -18.774664683716043, -20.252929968934183, -19.01518926375179]
|
||||||
|
|
||||||
|
e10m = [-22.17792627372312, -26.5983685883656, -22.797848894157955, -23.014822745152888, -21.45208671888342]
|
||||||
|
|
||||||
|
e15m = [-25.20854283824081, -25.196382621588043, -27.146880284259304, -23.50194049443653, -26.735523841588087]
|
||||||
|
|
||||||
|
e185m = [-26.391715760893703, -28.1335104958795, -29.153177713518723, -29.847186387317596, -30.558908425543827]
|
||||||
|
|
||||||
|
e235m = [-31.755831065931034, -31.883960187854985, -32.063876077498804, -31.643081143951544, -32.45807181713604]
|
||||||
|
|
||||||
|
|
||||||
|
for i in [e5m, e10m, e15m, e185m, e235m]:
|
||||||
|
print(f"stdev: {stdev(i):.4f}")
|
||||||
107
more-data.py
Normal file
107
more-data.py
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import os
|
||||||
|
import math
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from sklearn.linear_model import LinearRegression
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
# sample data: multiple measurements per dist
|
||||||
|
# in meters
|
||||||
|
distances = np.array([5.0, 10.0, 15.0, 18.5, 23.5])
|
||||||
|
|
||||||
|
# measured path loss in db for each dist (rows:distances, columns:measurements)
|
||||||
|
# example: 3 measurements per dist
|
||||||
|
|
||||||
|
#measured_PL = np.array([], [], [], [], [])
|
||||||
|
|
||||||
|
# i got these using scott's get_data script. thanks scott
|
||||||
|
pinst10 = [-22.17792627372312,
|
||||||
|
-26.5983685883656,
|
||||||
|
-22.797848894157955,
|
||||||
|
-23.014822745152888,
|
||||||
|
-21.45208671888342]
|
||||||
|
|
||||||
|
pinst15 = [-25.20854283824081,
|
||||||
|
-25.196382621588043,
|
||||||
|
-27.146880284259304,
|
||||||
|
-23.50194049443653,
|
||||||
|
-26.735523841588087]
|
||||||
|
|
||||||
|
pinst185 = [-26.391715760893703,
|
||||||
|
-28.1335104958795,
|
||||||
|
-29.153177713518723,
|
||||||
|
-29.847186387317596,
|
||||||
|
-30.558908425543827]
|
||||||
|
|
||||||
|
pinst235 = [-31.755831065931034,
|
||||||
|
-31.883960187854985,
|
||||||
|
-32.063876077498804,
|
||||||
|
-31.643081143951544,
|
||||||
|
-32.45807181713604]
|
||||||
|
|
||||||
|
pinst5 = [-19.567076092915567,
|
||||||
|
-20.05316841156921,
|
||||||
|
-18.774664683716043,
|
||||||
|
-20.252929968934183,
|
||||||
|
-19.01518926375179]
|
||||||
|
|
||||||
|
iterate = 0
|
||||||
|
cursor = 0
|
||||||
|
dist_cur = distances[cursor]
|
||||||
|
|
||||||
|
# oh god
|
||||||
|
measured_PL = [pinst5, pinst10, pinst15, pinst185, pinst235]
|
||||||
|
|
||||||
|
# ref dist
|
||||||
|
d0 = 5
|
||||||
|
PL_d0 = np.mean(measured_PL[0])
|
||||||
|
PL_d1 = np.mean(measured_PL[1])
|
||||||
|
PL_d2 = np.mean(measured_PL[2])
|
||||||
|
PL_d3 = np.mean(measured_PL[3])
|
||||||
|
PL_d4 = np.mean(measured_PL[4])
|
||||||
|
|
||||||
|
print(f"Reference distance: {d0}m")
|
||||||
|
print(f"Mean Path-Loss at ref dist: about {PL_d0:.4f}")
|
||||||
|
|
||||||
|
j = 1
|
||||||
|
for i in [PL_d0, PL_d1, PL_d2, PL_d3, PL_d4]:
|
||||||
|
print(f"Computed Path loss #{j}: {i}")
|
||||||
|
j += 1
|
||||||
|
|
||||||
|
# prepare data for linear regression
|
||||||
|
# compute mean PL for each dist
|
||||||
|
mean_PL = np.mean(measured_PL, axis=1)
|
||||||
|
X = 10 * np.log10(distances / d0).reshape(-1, 1)
|
||||||
|
Y = mean_PL - PL_d0 # relative path loss
|
||||||
|
|
||||||
|
# fit linear regression
|
||||||
|
model = LinearRegression()
|
||||||
|
model.fit(X, Y)
|
||||||
|
|
||||||
|
# extract path-loss exponent (slope)
|
||||||
|
n = model.coef_[0]
|
||||||
|
print(f'Estimated path-loss exponent n: {n:.2f}')
|
||||||
|
|
||||||
|
# predicted path loss from model
|
||||||
|
predicted_PL = PL_d0 + model.predict(X)
|
||||||
|
|
||||||
|
# calc shadowing std. deviation using all measurements
|
||||||
|
residuals = measured_PL = predicted_PL[:, np.newaxis] # residuals for all
|
||||||
|
# measurements
|
||||||
|
sigma = np.std(residuals)
|
||||||
|
|
||||||
|
print(f'Shadowing standard deviation: {sigma:.2f} dB')
|
||||||
|
|
||||||
|
# plot
|
||||||
|
plt.figure(figsize=(8,6))
|
||||||
|
plt.scatter(np.repeat(X, measured_PL.shape[1]), measured_PL.flatten(),
|
||||||
|
label='Measured PL')
|
||||||
|
plt.plot(X, predicted_PL, color='red', label='Fitted line')
|
||||||
|
plt.xlabel('10*log10(d/d0)')
|
||||||
|
plt.ylabel('Path Loss (dB)')
|
||||||
|
plt.title('Path Loss Experiment & Shadowing Estimation')
|
||||||
|
plt.legend()
|
||||||
|
plt.grid(True)
|
||||||
|
plt.show()
|
||||||
Reference in New Issue
Block a user