[Python] I need assistance with Sionna-rt [closed]

Discussão em 'Python' iniciado por Stack, Junho 5, 2025.

  1. Stack

    Stack Membro Participativo

    I generated a human body model through "Blender". Now I hope to simulate the reflection path of radio signals on the human body through sionna, but I can't achieve it. May I ask what the reason is?

    Here is my code and computational results in the image

    # %%
    import numpy as np
    import drjit as dr
    import mitsuba as mi
    import matplotlib as mpl
    # import tensorflow as tf

    from sionna.rt import LambertianPattern, DirectivePattern, BackscatteringPattern,\
    load_scene, Camera, Transmitter, Receiver, PlanarArray,\
    PathSolver, RadioMapSolver, cpx_abs, cpx_convert

    no_preview = True # Toggle to False to use the preview widget

    from sionna.rt import load_scene, PlanarArray, Transmitter, Receiver, Camera, watt_to_dbm,\
    PathSolver, RadioMapSolver, subcarrier_frequencies

    import matplotlib.pyplot as plt

    # %% [markdown]
    # 导入

    # %%
    scene = load_scene("/data2/yty/Blender Scene/Human_test/Human_test.xml")

    # %%
    if not no_preview:
    scene.preview();

    # %%
    # Only availabe if a preview is open
    if not no_preview:
    scene.render(camera="preview", num_samples=512);

    if not no_preview:
    scene.render_to_file(camera="preview",
    filename="scene.png",
    resolution=[650,500]);

    # %%
    # Create new camera with different configuration
    my_cam = Camera(position=[-100,150,250], look_at=[0,0,0])

    # Render scene with new camera*
    scene.render(camera=my_cam, resolution=[650, 500], num_samples=512); # Increase num_samples to increase image quality

    # %%
    scene.objects
    # floor = scene.get("floor")
    # print("Position (x,y,z) [m]: ", floor.position)
    # print("Orientation (alpha, beta, gamma) [rad]: ", floor.orientation)
    # print("Scaling: ", floor.scaling)

    # %%
    # test_scene——tx:[15,90,5];rx:[20,20,20]
    # Human/skeleton——tx:[20,20,5];rx:[20,-20,5]


    # Configure antenna array for all transmitters
    scene.tx_array = PlanarArray(num_rows=1,
    num_cols=1,
    vertical_spacing=0.5,
    horizontal_spacing=0.5,
    pattern="tr38901",
    polarization="V")

    # Configure antenna array for all receivers
    scene.rx_array = PlanarArray(num_rows=1,
    num_cols=1,
    vertical_spacing=0.5,
    horizontal_spacing=0.5,
    pattern="dipole",
    polarization="cross")

    # Create transmitter
    tx = Transmitter(name="tx",
    position=[20,20,5],
    display_radius=2)

    # Add transmitter instance to scene
    scene.add(tx)

    # Create a receiver
    rx = Receiver(name="rx",
    position=[20,-20,5],
    display_radius=2)

    # Add receiver instance to scene
    scene.add(rx)

    tx.look_at(rx) # Transmitter points towards receiver


    # Compute radio map
    rm_solver = RadioMapSolver()
    rm = rm_solver(scene,
    max_depth=5, # Maximum number of ray scene interactions
    samples_per_tx=10**7 , # If you increase: less noise, but more memory required
    cell_size=(5, 5), # Resolution of the radio map
    center=[0, 0, 0], # Center of the radio map
    size=[400, 400], # Total size of the radio map
    orientation=[0, 0, 0]) # Orientation of the radio map, e.g., could be also vertical

    # %%
    # Visualize path gain
    rm.show(metric="path_gain");

    # Visualize received signal strength (RSS)
    rm.show(metric="rss");

    # Visulaize SINR
    rm.show(metric="sinr");

    # %%
    tx.power_dbm = 24
    rm = rm_solver(scene,
    max_depth=5,
    samples_per_tx=10**7,
    cell_size=(5, 5),
    center=[0, 0, 0],
    size=[400, 400],
    orientation=[0, 0, 0])
    rm.show(metric="rss");

    # %%
    print(f"Bandwidth: ", scene.bandwidth.numpy(), "[Hz]")
    print(f"Temperature: ", scene.temperature.numpy(), "[K]")
    print(f"Thermal noise power: ", watt_to_dbm(scene.thermal_noise_power).numpy(), "[dBm]")

    # %%
    # Instantiate a path solver
    # The same path solver can be used with multiple scenes
    p_solver = PathSolver()

    # Compute propagation paths
    paths = p_solver(scene=scene,
    max_depth=5,
    los=True,
    specular_reflection=True,
    diffuse_reflection=False,
    refraction=False,
    synthetic_array=False,
    seed=41)

    # %%
    # if no_preview:
    # scene.render(camera=my_cam, paths=paths, clip_at=20);
    # else:
    # scene.preview(paths=paths, clip_at=20);

    scene.preview(paths=paths, clip_at=20);

    # %%
    a, tau = paths.cir(normalize_delays=True, out_type="numpy")

    # Shape: [num_rx, num_rx_ant, num_tx, num_tx_ant, num_paths, num_time_steps]
    print("Shape of a: ", a.shape)

    # Shape: [num_rx, num_rx_ant, num_tx, num_tx_ant, num_paths]
    print("Shape of tau: ", tau.shape)

    # %%
    t = tau[0,0,0,0,:]/1e-9 # Scale to ns
    a_abs = np.abs(a)[0,0,0,0,:,0]
    a_max = np.max(a_abs)

    # And plot the CIR
    plt.figure()
    plt.title("Channel impulse response")
    plt.stem(t, a_abs)
    plt.xlabel(r"$\tau$ [ns]")
    plt.ylabel(r"$|a|$");

    # %%
    # OFDM system parameters
    num_subcarriers = 1024
    subcarrier_spacing=30e3

    # Compute frequencies of subcarriers relative to the carrier frequency
    frequencies = subcarrier_frequencies(num_subcarriers, subcarrier_spacing)

    # Compute channel frequency response
    h_freq = paths.cfr(frequencies=frequencies,
    normalize=True, # Normalize energy
    normalize_delays=True,
    out_type="numpy")

    # Shape: [num_rx, num_rx_ant, num_tx, num_tx_ant, num_time_steps, num_subcarriers]
    print("Shape of h_freq: ", h_freq.shape)

    # Plot absolute value
    plt.figure()
    plt.plot(np.abs(h_freq)[0,0,0,0,0,:]);
    plt.xlabel("Subcarrier index");
    plt.ylabel(r"|$h_\text{freq}$|");
    plt.title("Channel frequency response");

    # %%
    taps = paths.taps(bandwidth=100e6, # Bandwidth to which the channel is low-pass filtered
    l_min=-6, # Smallest time lag
    l_max=100, # Largest time lag
    sampling_frequency=None, # Sampling at Nyquist rate, i.e., 1/bandwidth
    normalize=True, # Normalize energy
    normalize_delays=True,
    out_type="numpy")
    print("Shape of taps: ", taps.shape)

    plt.figure()
    plt.stem(np.arange(-6, 101), np.abs(taps)[0,0,0,0,0]);
    plt.xlabel(r"Tap index $\ell$");
    plt.ylabel(r"|$h[\ell]|$");
    plt.title("Discrete channel taps");

    # %%
    scene.get("tx").velocity = [10, 0, 0]

    # Recompute propagation paths
    paths_mob = p_solver(scene=scene,
    max_depth=5,
    los=True,
    specular_reflection=True,
    diffuse_reflection=False,
    refraction=True,
    synthetic_array=True,
    seed=41)

    # Compute CIR with time-evolution
    num_time_steps=100
    sampling_frequency = 1e4
    a_mob, _ = paths_mob.cir(sampling_frequency=sampling_frequency,
    num_time_steps=num_time_steps,
    out_type="numpy")

    # Inspect time-evolution of a single path coefficient
    plt.figure()
    plt.plot(np.arange(num_time_steps)/sampling_frequency*1000,
    a_mob[0,0,0,0,0].real);
    plt.xlabel("Time [ms]");
    plt.ylabel(r"$\Re\{a_0(t) \}$");
    plt.title("Time-evolution of a path coefficient");

    # %%
    rm_solver = RadioMapSolver()

    rm = rm_solver(scene=scene,
    max_depth=5,
    cell_size=[1,1],
    samples_per_tx=10**6)

    if no_preview:
    scene.render(camera=my_cam, radio_map=rm);
    else:
    scene.preview(radio_map=rm);

    # scene.preview(radio_map=rm);


    enter image description here

    Continue reading...

Compartilhe esta Página