1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Signal Hound Spike API - SA series (USB-SA44B) Problem reading power at specific...

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    I'm conducting a test of RF modules using the SA series API for Python, but I’m encountering some unexpected results and have some doubts about the configuration. To better understand the issue, I’ll first describe my setup: I have an RFID module connected to a 40dB attenuator, which is then connected to a USB-SA44B spectrum analyzer, with the analyzer connected to a PC. The API I’m using is the one provided by Signal Hound, which includes sa_api.py and sa_api.dll, located in \signal_hound_sdk\device_apis\sa_series\examples\python.

    Here is the code:

    # -*- coding: utf-8 -*-

    from sadevice.sa_api import *
    import time
    import matplotlib.pyplot as plt
    import numpy as np

    # Frequency configuration for the 3 channels with a ±200Hz margin
    frequencies = [(916300e3, 400), (917500e3, 400), (918700e3, 400)]#,


    def configure_device(handle, center_freq, span):
    # Set center frequency and span
    sa_config_center_span(handle, center_freq, span)
    sa_config_level(handle, -30.0)
    sa_config_sweep_coupling(handle, 10e3, 10e3, 0)
    sa_config_acquisition(handle, SA_MIN_MAX, SA_LOG_SCALE)
    sa_initiate(handle, SA_SWEEPING, 0)


    def get_power_for_frequency(handle, center_freq, span):
    query = sa_query_sweep_info(handle)
    sweep_length = query["sweep_length"]
    start_freq = query["start_freq"]
    bin_size = query["bin_size"]


    sweep_max = sa_get_sweep_32f(handle)["max"]
    freqs = [start_freq + i * bin_size for i in range(sweep_length)]

    power_values = [(freq, power) for freq, power in zip(freqs, sweep_max)
    if center_freq - span / 2 <= freq <= center_freq + span / 2] #

    return power_values


    def print_debug_info(data, elapsed_time):
    print(f"\n=== Debug Info at {elapsed_time:.1f} seconds ===")
    for freq in data:
    times = data[freq]["times"]
    powers = data[freq]["powers"]
    print(f"Frequency: {freq}")
    print(f"Times: {times}")
    print(f"Powers: {powers}\n")
    print(len(powers))


    def collect_and_plot_data():
    # Open device
    handle = sa_open_device()["handle"]

    data = {f"{freq[0] / 1e6:.3f} MHz": {"times": [], "powers": []} for freq in frequencies}
    last_debug_time = 0

    # Collect data for 1 minute
    start_time = time.time()
    while time.time() - start_time < 30:
    elapsed_time = time.time() - start_time
    for center_freq, span in frequencies:
    configure_device(handle, center_freq, span)
    power_values = get_power_for_frequency(handle, center_freq, span)


    for _, power in power_values:
    data[f"{center_freq / 1e6:.3f} MHz"]["times"].append(elapsed_time)
    data[f"{center_freq / 1e6:.3f} MHz"]["powers"].append(power)

    # Debugging output every 10 seconds
    '''
    if int(elapsed_time) % 10 == 0 and elapsed_time > last_debug_time:
    print_debug_info(data, elapsed_time)
    last_debug_time = elapsed_time # Update the last debug time
    '''
    # Close the device
    sa_close_device(handle)

    # Plot the data
    plt.figure(figsize=(10, 6))

    for freq in data:
    if data[freq]["times"]:
    plt.plot(data[freq]["times"], data[freq]["powers"], label=freq, marker='o', linestyle='-')

    p = data[freq]["powers"]
    print((data[freq]["powers"]))
    print(np.max(p))

    plt.title("Power vs Time for Different Frequencies")
    plt.xlabel("Time (s)")
    plt.ylabel("Power (dBm)")
    plt.legend(title="Frequency")
    plt.grid(True)
    plt.show()

    if __name__ == "__main__":
    collect_and_plot_data()`


    I performed a simple 30-second test, reading across 3 channels (with only 1 carrier on) at 2 different power outputs, but the results were not as expected.

    Power set Spike UI python
    31.5 dBm -8.72 dBm -27.67 dBm
    20 dBm -20.28 dBm -75.17 dBm

    Since I have a 40dB attenuator the spike results are close to the output power, but the python values are not even 11.5 dBm separated.

    31.5 dBm plot:

    31.5_dbm

    20 dBm plot:

    20 dBm

    Continue reading...

Compartilhe esta Página