Side info display
Function display_side_info(freq_offset, csi, equalizer, waterfall_flag, CSI_LEN, EQUALIZER_LEN)
display_side_info: The function of display_side_info is to visualize frequency offset, channel state information (CSI), and equalizer data through various plots.
parameters: The parameters of this Function. · freq_offset: A numpy array representing the frequency offset values to be displayed. · csi: A numpy array containing the channel state information data. · equalizer: A numpy array representing the equalizer values. · waterfall_flag: An integer flag indicating whether to display the waterfall plot (1 for yes, 0 for no). · CSI_LEN: An integer representing the length of the CSI data. · EQUALIZER_LEN: An integer representing the length of the equalizer data.
Code Description: The display_side_info function begins by checking if a static variable freq_offset_store exists; if not, it initializes it as a numpy array of zeros with a length of 256. This variable is used to store and manage the frequency offset data over time. The function then updates this store by shifting the existing values and appending the new freq_offset data.
Next, the function creates a figure for plotting the frequency offset, labeling the axes and setting the title. It plots the frequency offset data stored in freq_offset_store and refreshes the figure canvas to display the updated plot.
The function then checks if the equalizer array is empty. If it is, it transposes the csi array for plotting. If the equalizer is not empty, it processes the equalizer data by replacing invalid values (32767 + 32767 * 1j) with zeros and filtering out rows with large values (greater than 2000) in either the real or imaginary parts. The valid equalizer and corresponding CSI data are stored for plotting.
If there are valid equalizer values or if the equalizer array is empty, the function proceeds to create a figure for plotting the CSI data. It generates two subplots: one for the absolute values of the CSI and another for the phase of the CSI, labeling each appropriately and plotting the data.
If the waterfall_flag is set to 1, the function prepares to display a waterfall plot. It rolls the existing csi_mat_for_waterfall array to make room for the new CSI data and updates the first row with the latest CSI values. It then creates a new figure for the waterfall plot, displaying both the amplitude and phase of the CSI data over time.
Finally, if there are valid equalizer values, the function creates a separate figure to visualize the equalizer data using a scatter plot, displaying the real and imaginary components of the equalizer.
Note: It is important to ensure that the input arrays (freq_offset, csi, equalizer) are of appropriate dimensions and types to avoid runtime errors. The function relies on matplotlib for plotting, so the user must have this library installed and properly configured in their environment. Additionally, the function modifies static variables, which may affect subsequent calls to display_side_info.
graph TD
A[Start display_side_info] --> B[Check if freq_offset_store exists]
B -- Yes --> C[Get length of freq_offset]
B -- No --> D[Initialize freq_offset_store with zeros]
D --> C
C --> E[Update freq_offset_store with new freq_offset]
E --> F[Create figure for freq offset]
F --> G[Set labels and title for freq offset]
G --> H[Plot freq_offset_store]
H --> I[Flush events for freq offset figure]
I --> J[Initialize good_row_idx to 0]
J --> K[Check if equalizer is empty]
K -- Yes --> L[Transpose csi for plotting]
K -- No --> M[Process equalizer values]
M --> N[Set equalizer values to zero if condition met]
N --> O[Initialize arrays for plotting]
O --> P[Loop through equalizer rows]
P --> Q[Check if equalizer values are good]
Q -- Yes --> R[Store good equalizer and csi values]
R --> S[Increment good_row_idx]
Q -- No --> P
P --> T[Trim csi_for_plot and equalizer_for_plot]
T --> U[Transpose csi_for_plot and equalizer_for_plot]
U --> V[Check if equalizer is empty or good_row_idx > 0]
V -- Yes --> W[Create figure for CSI]
W --> X[Set labels and title for CSI]
X --> Y[Plot absolute value of csi_for_plot]
Y --> Z[Plot phase of csi_for_plot]
Z --> AA[Flush events for CSI figure]
V -- No --> AB[Check if waterfall_flag is set]
AB -- Yes --> AC[Roll csi_mat_for_waterfall]
AC --> AD[Update csi_mat_for_waterfall with new csi]
AD --> AE[Create figure for waterfall]
AE --> AF[Set titles and labels for waterfall]
AF --> AG[Plot amplitude of csi_mat_for_waterfall]
AG --> AH[Plot phase of csi_mat_for_waterfall]
AH --> AI[Flush events for waterfall figure]
V -- No --> AJ[Check if equalizer has good rows]
AJ -- Yes --> AK[Create figure for equalizer]
AK --> AL[Set labels and title for equalizer]
AL --> AM[Scatter plot equalizer_for_plot]
AM --> AN[Flush events for equalizer figure]
AN --> AO[End display_side_info]
Function parse_side_info(side_info, num_eq, CSI_LEN, EQUALIZER_LEN, HEADER_LEN)
parse_side_info: The function of parse_side_info is to process side information data and extract relevant parameters such as timestamps, frequency offsets, channel state information (CSI), and equalizer values.
parameters: The parameters of this Function.
· side_info: A NumPy array containing the side information data to be processed.
· num_eq: An integer representing the number of equalizers to be used.
· CSI_LEN: An integer indicating the length of the channel state information.
· EQUALIZER_LEN: An integer that specifies the length of each equalizer.
· HEADER_LEN: An integer representing the length of the header in the data.
Code Description: The parse_side_info function begins by calculating the half-length of the CSI (CSI_LEN_HALF) and determining the number of DMA symbols per transmission (num_dma_symbol_per_trans) based on the provided HEADER_LEN, CSI_LEN, and the number of equalizers (num_eq). It then calculates the number of 16-bit integers per transmission (num_int16_per_trans) and the total number of transmissions (num_trans) by reshaping the input side_info array accordingly.
Next, the function extracts timestamps from the reshaped side_info data by combining multiple columns into a single timestamp value using bitwise operations. It also computes the frequency offset using the values from the side_info array, converting them into a frequency representation.
The function initializes two arrays: csi for storing the channel state information and equalizer for storing equalizer values. If num_eq is greater than zero, the equalizer array is created with the appropriate dimensions.
A loop iterates over each transmission, extracting in-phase (I) and quadrature (Q) components from the side_info data. These components are combined into complex numbers, and the function populates the csi and equalizer arrays with the relevant data. The CSI is filled by rearranging the I and Q components, while the equalizer is populated if applicable.
Finally, the function returns four values: the computed timestamps, frequency offsets, the csi array, and the equalizer array.
Note: It is important to ensure that the input side_info array has the correct dimensions and data types to avoid runtime errors. The function assumes that the input data is structured correctly according to the expected format.
Output Example: A possible appearance of the code's return value could be: (timestamp_array, freq_offset_array, csi_array, equalizer_array) where: - timestamp_array: A NumPy array of shape (num_trans,) containing the calculated timestamps. - freq_offset_array: A NumPy array of shape (num_trans,) containing the frequency offsets. - csi_array: A NumPy array of shape (num_trans, CSI_LEN) containing the channel state information. - equalizer_array: A NumPy array of shape (num_trans, num_eq * EQUALIZER_LEN) containing the equalizer values, if num_eq is greater than zero; otherwise, it is an empty array.
graph TD
A[Start] --> B[Calculate CSI_LEN_HALF]
B --> C[Calculate num_dma_symbol_per_trans]
C --> D[Calculate num_int16_per_trans]
D --> E[Calculate num_trans]
E --> F[Reshape side_info]
F --> G[Calculate timestamp]
G --> H[Calculate freq_offset]
H --> I[Initialize csi array]
I --> J[Initialize equalizer array]
J --> K{Check if num_eq > 0}
K -- Yes --> L[Initialize equalizer array with dimensions]
K -- No --> M[Skip equalizer initialization]
L --> N[Loop through num_trans]
M --> N
N --> O[Extract tmp_vec_i and tmp_vec_q]
O --> P[Combine tmp_vec_i and tmp_vec_q]
P --> Q[Assign values to csi]
Q --> R{Check if num_eq > 0}
R -- Yes --> S[Assign values to equalizer]
R -- No --> T[Skip equalizer assignment]
S --> U[End loop]
T --> U
U --> V[Return timestamp, freq_offset, csi, equalizer]
V --> Z[End]