Skip to content

Iq capture

Function display_iq(iq_capture, agc_gain, rssi_half_db)

display_iq: The function of display_iq is to visualize the I/Q data, AGC gain, and RSSI half dB values through graphical plots.

parameters: The parameters of this Function. · iq_capture: A complex array representing the I/Q data to be visualized, where the real part corresponds to I (In-phase) and the imaginary part corresponds to Q (Quadrature). · agc_gain: An array representing the Automatic Gain Control (AGC) gain values, which indicate the gain applied to the signal. · rssi_half_db: An array representing the Received Signal Strength Indicator (RSSI) values in half dB, which provides a measure of the signal strength.

Code Description: The display_iq function is designed to create three distinct plots using Matplotlib to visualize the provided data.

  1. The first plot visualizes the I/Q data. It initializes a figure (fig_iq_capture) and clears any existing content. The x-axis is labeled "sample," and the y-axis is labeled "I/Q." The title of the plot indicates that the blue line represents the I component and the red line represents the Q component. The real part of the iq_capture array is plotted in blue, while the imaginary part is plotted in red. The y-axis limits are set between -32767 and 32767 to accommodate the expected range of I/Q values. The canvas is then refreshed to display the updated plot.

  2. The second plot focuses on the AGC gain. It creates a new figure (fig_agc_gain) and similarly clears any previous content. The x-axis is labeled "sample," and the y-axis is labeled "gain/lock." The title indicates that the blue line shows the AGC gain values while the red line indicates the lock status. The function first creates a copy of the agc_gain array to determine the lock status, setting values greater than 127 to 80 (indicating a locked state) and values less than or equal to 127 to 0 (indicating an unlocked state). Another copy of agc_gain is created to adjust the gain values, where values greater than 127 have 128 subtracted from them. The adjusted gain values are plotted in blue, and the lock status is plotted in red. The y-axis limits are set between 0 and 82, and the canvas is refreshed.

  3. The third plot visualizes the RSSI half dB values. A new figure (fig_rssi_half_db) is created and cleared. The x-axis is labeled "sample," and the y-axis is labeled "dB." The title indicates that the plot represents uncalibrated RSSI half dB values. The rssi_half_db array is plotted, with the y-axis limits set between 100 and 270. The canvas is refreshed to display the plot.

Overall, the display_iq function effectively provides a visual representation of the I/Q data, AGC gain, and RSSI values, allowing users to analyze the signal characteristics over time.

Note: It is important to ensure that the input arrays (iq_capture, agc_gain, rssi_half_db) are of compatible sizes and contain valid numerical data to avoid runtime errors during plotting. Additionally, the function requires Matplotlib and NumPy libraries to be imported and available in the environment.

graph TD
    A[Start display_iq function] --> B[Create figure for IQ capture]
    B --> C[Clear figure]
    C --> D[Set x-label to sample]
    D --> E[Set y-label to I/Q]
    E --> F[Set title for IQ capture]
    F --> G[Plot real part of iq_capture in blue]
    G --> H[Plot imaginary part of iq_capture in red]
    H --> I[Set y-limits for IQ capture]
    I --> J[Flush events for IQ capture figure]

    J --> K[Create agc_gain_lock array]
    K --> L[Set agc_gain_lock values based on agc_gain]
    L --> M[Create agc_gain_value array]
    M --> N[Adjust agc_gain_value based on agc_gain]

    N --> O[Create figure for AGC gain]
    O --> P[Clear figure]
    P --> Q[Set x-label to sample]
    Q --> R[Set y-label to gain/lock]
    R --> S[Set title for AGC gain]
    S --> T[Plot agc_gain_value in blue]
    T --> U[Plot agc_gain_lock in red]
    U --> V[Set y-limits for AGC gain]
    V --> W[Flush events for AGC gain figure]

    W --> X[Create figure for RSSI half dB]
    X --> Y[Clear figure]
    Y --> Z[Set x-label to sample]
    Z --> AA[Set y-label to dB]
    AA --> AB[Set title for RSSI half dB]
    AB --> AC[Plot rssi_half_db]
    AC --> AD[Set y-limits for RSSI half dB]
    AD --> AE[Flush events for RSSI half dB figure]
    AE --> AF[End display_iq function]

Function parse_iq(iq, iq_len)

parse_iq: The function of parse_iq is to process IQ data and extract timestamps, IQ capture values, AGC gain, and RSSI values.

parameters: The parameters of this Function. · parameter1: iq - A NumPy array containing interleaved IQ data in a specific format. · parameter2: iq_len - An integer representing the length of the IQ data in terms of the number of IQ samples per transmission.

Code Description: The parse_iq function begins by calculating the number of DMA symbols per transmission, which is determined by adding 1 to the iq_len parameter. Each DMA symbol consists of 4 integers (64 bits), leading to the calculation of the total number of int16 values per transmission. The function then computes the total number of transmissions by dividing the length of the iq array by the number of int16 values per transmission and rounding the result.

Next, the iq array is reshaped into a 2D array where each row corresponds to a transmission. The function extracts the timestamp by combining the first four columns of the reshaped iq array, using powers of 2 to appropriately shift and combine the values. The IQ capture values are derived from the 5th and 6th columns, which are combined to form complex numbers. Additionally, the AGC gain and RSSI values are extracted from the 7th and 8th columns, respectively.

After extracting these components, the function reshapes the iq_capture, agc_gain, and rssi_half_db arrays to ensure they are one-dimensional and contain the total number of samples across all transmissions. Finally, the function returns the timestamp, iq_capture, agc_gain, and rssi_half_db as separate arrays.

Note: It is important to ensure that the input iq array is of the correct format and length to avoid errors during reshaping and extraction. The iq_len parameter should accurately reflect the expected number of IQ samples per transmission for correct processing.

Output Example: A possible appearance of the code's return value could be: (timestamp: array([1622548800, 1622548801, ...]), iq_capture: array([0.1+0.2j, 0.3+0.4j, ...]), agc_gain: array([10, 12, ...]), rssi_half_db: array([-50, -48, ...]))

graph TD
    A[Start] --> B[Calculate num_dma_symbol_per_trans]
    B --> C[Calculate num_int16_per_trans]
    C --> D[Calculate num_trans]
    D --> E[Reshape iq array]
    E --> F[Calculate timestamp]
    F --> G[Calculate iq_capture]
    G --> H[Calculate agc_gain]
    H --> I[Calculate rssi_half_db]
    I --> J[Reshape iq_capture]
    J --> K[Reshape agc_gain]
    K --> L[Reshape rssi_half_db]
    L --> M[Return timestamp, iq_capture, agc_gain, rssi_half_db]
    M --> N[End]