examples: (fixes #1146) Fix three-gpp-v2v-channel-example and plotting script
Pass tx params copy to ComputeSnr, to prevent pathloss to be incorrectly accumulated over time
This commit is contained in:
@@ -151,13 +151,10 @@ PrintGnuplottableBuildingListToFile(std::string filename)
|
||||
NS_LOG_ERROR("Can't open file " << filename);
|
||||
return;
|
||||
}
|
||||
uint32_t index = 0;
|
||||
for (auto it = BuildingList::Begin(); it != BuildingList::End(); ++it)
|
||||
{
|
||||
++index;
|
||||
Box box = (*it)->GetBoundaries();
|
||||
outFile << "set object " << index << " rect from " << box.xMin << "," << box.yMin << " to "
|
||||
<< box.xMax << "," << box.yMax << std::endl;
|
||||
outFile << box.xMin << " " << box.yMin << " " << box.xMax << " " << box.yMax << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,7 +356,7 @@ main(int argc, char* argv[])
|
||||
|
||||
for (int i = 0; i < simTime / timeRes; i++)
|
||||
{
|
||||
ComputeSnrParams params{txMob, rxMob, txParams, noiseFigure, txAntenna, rxAntenna};
|
||||
ComputeSnrParams params{txMob, rxMob, txParams->Copy(), noiseFigure, txAntenna, rxAntenna};
|
||||
Simulator::Schedule(timeRes * i, &ComputeSnr, params);
|
||||
}
|
||||
|
||||
|
||||
86
examples/channel-models/three-gpp-v2v-channel-example.py
Normal file
86
examples/channel-models/three-gpp-v2v-channel-example.py
Normal file
@@ -0,0 +1,86 @@
|
||||
#!/bin/python3
|
||||
|
||||
# Copyright (c) 2020, University of Padova, Dep. of Information Engineering, SIGNET lab
|
||||
# Copyright (c) 2025, Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
import matplotlib.animation as animation
|
||||
import matplotlib.patches as patches
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
#
|
||||
# Plot the traces generated by three-gpp-v2v-channel-example
|
||||
#
|
||||
import pandas as pd
|
||||
|
||||
# Load the data
|
||||
df = pd.read_csv("example-output.txt", sep=r"\s+", comment="#")
|
||||
df = df.iloc[::10, :]
|
||||
|
||||
# Column indices (adjust if needed)
|
||||
TIME = 0
|
||||
TX_X = 1
|
||||
TX_Y = 2
|
||||
RX_X = 3
|
||||
RX_Y = 4
|
||||
SNR = 6
|
||||
|
||||
# Create the figure and subplots
|
||||
fig, (ax_map, ax_snr) = plt.subplots(1, 2, figsize=(12, 6))
|
||||
|
||||
# Map plot config
|
||||
ax_map.set_xlim(-25, 600)
|
||||
ax_map.set_ylim(-25, 1000)
|
||||
ax_map.set_xlabel("X [m]")
|
||||
ax_map.set_ylabel("Y [m]")
|
||||
ax_map.set_aspect("equal")
|
||||
tx_circle = patches.Circle((0, 0), 5, color="blue", alpha=0.35)
|
||||
rx_circle = patches.Circle((0, 0), 5, color="red", alpha=0.35)
|
||||
ax_map.add_patch(tx_circle)
|
||||
ax_map.add_patch(rx_circle)
|
||||
|
||||
# SNR plot config
|
||||
ax_snr.set_xlim(0, 40)
|
||||
ax_snr.set_ylim(-20, 100)
|
||||
ax_snr.set_xlabel("Time [s]")
|
||||
ax_snr.set_ylabel("SNR [dB]")
|
||||
ax_snr.grid(True)
|
||||
(snr_line,) = ax_snr.plot([], [], "k-")
|
||||
|
||||
buildings = pd.read_csv("buildings.txt", sep=r"\s+", comment="#", header=None)
|
||||
building_patches = []
|
||||
for idx, row in buildings.iterrows():
|
||||
x0, y0, x1, y1 = row
|
||||
width = x1 - x0
|
||||
height = y1 - y0
|
||||
rect = patches.Rectangle((x0, y0), width, height, color="gray", alpha=0.5)
|
||||
ax_map.add_patch(rect)
|
||||
building_patches.append(rect)
|
||||
|
||||
|
||||
# Animation update function
|
||||
def update(frame):
|
||||
row = df.iloc[frame]
|
||||
tx_circle.set_center((row.iloc[TX_X], row.iloc[TX_Y]))
|
||||
rx_circle.set_center((row.iloc[RX_X], row.iloc[RX_Y]))
|
||||
snr_line.set_data(df.iloc[: frame + 1, TIME], df.iloc[: frame + 1, SNR])
|
||||
ax_map.set_title(f"Time = {row.iloc[TIME]:.1f} s")
|
||||
return tx_circle, rx_circle, snr_line
|
||||
|
||||
|
||||
# Run animation
|
||||
ani = animation.FuncAnimation(fig, update, frames=len(df), interval=0.001, blit=False)
|
||||
|
||||
# Save animation
|
||||
ani.save("map.gif", writer="pillow")
|
||||
|
||||
# Save final SNR plot separately
|
||||
plt.figure()
|
||||
plt.plot(df.iloc[:, TIME], df.iloc[:, SNR], "k-")
|
||||
plt.xlabel("Time [s]")
|
||||
plt.ylabel("SNR [dB]")
|
||||
plt.grid(True)
|
||||
plt.xlim(0, 40)
|
||||
plt.ylim(-20, 100)
|
||||
plt.savefig("snr.png")
|
||||
@@ -1,57 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright (c) 2020, University of Padova, Dep. of Information Engineering, SIGNET lab
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
#
|
||||
# Plot the traces generated by three-gpp-vehicular-channel-condition-model-example
|
||||
#
|
||||
|
||||
cat >aa <<EOL
|
||||
set terminal gif animate delay 100
|
||||
set output 'map.gif'
|
||||
set view map
|
||||
set style fill transparent solid 0.5
|
||||
unset key
|
||||
set style fill transparent solid 0.35 noborder
|
||||
set style circle radius 5
|
||||
|
||||
do for [i=0:299] {
|
||||
set multiplot layout 1,2
|
||||
set zrange [i-1:i]
|
||||
set xrange [-25:600]
|
||||
set yrange [-25:1000]
|
||||
set xlabel 'X [m]'
|
||||
set ylabel 'Y [m]'
|
||||
set xtics
|
||||
set ytics
|
||||
load 'buildings.txt'
|
||||
splot 'example-output.txt' u 2:3:1 with circles lc rgb "blue", 'example-output.txt' u 4:5:1 with circles lc rgb "red"
|
||||
set object 101 rect from -25,-25 to 1400,1000 fc rgb "white"
|
||||
set xrange [i-0.001:i+0.001]
|
||||
set yrange [i-0.001:i+0.001]
|
||||
unset xlabel
|
||||
unset ylabel
|
||||
unset xtics
|
||||
unset ytics
|
||||
plot 'example-output.txt' using 1:1:1 with labels offset -10, 0, 'example-output.txt' using 1:1:6 with labels offset 10, 0
|
||||
unset object 101
|
||||
unset multiplot
|
||||
}
|
||||
|
||||
reset
|
||||
set terminal png
|
||||
set output 'snr.png'
|
||||
set xlabel 'Time [s]'
|
||||
set ylabel 'SNR [dB]'
|
||||
set xtics
|
||||
set ytics
|
||||
set grid
|
||||
set xrange [0:40]
|
||||
set yrange [-20:100]
|
||||
plot 'example-output.txt' u 1:7 w l
|
||||
EOL
|
||||
gnuplot aa
|
||||
rm aa
|
||||
# rm out.txt
|
||||
Reference in New Issue
Block a user