bladeRF-cli: added sc16q11 packed mimo rx example
This commit is contained in:
parent
3ae66b49a1
commit
c407de2c9f
5 changed files with 150 additions and 0 deletions
25
host/examples/bladeRF-cli/sc16q11-packed-mimo/README.md
Normal file
25
host/examples/bladeRF-cli/sc16q11-packed-mimo/README.md
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# BladeRF CLI RX MIMO Packed
|
||||
|
||||
This example demonstrates how to configure and use the BladeRF CLI to aquire an RX stream of packed 16-bit samples.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before running this example, ensure the Python environment is initialized and install the dependencies:
|
||||
|
||||
```bash
|
||||
python3 -m venv env
|
||||
source env/bin/activate
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Running the Example
|
||||
|
||||
To run the example, execute the following command:
|
||||
|
||||
```bash
|
||||
./run.sh
|
||||
```
|
||||
|
||||
This will execute the bladeRF-cli script that ingests samples from an internal 12b counter and writes them to a CSV file.
|
||||
|
||||
The Python script `validate.py` will then read the CSV file and plot the samples for visual inspection.
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
contourpy==1.3.0
|
||||
cycler==0.12.1
|
||||
fonttools==4.54.1
|
||||
kiwisolver==1.4.7
|
||||
matplotlib==3.9.2
|
||||
numpy==2.1.1
|
||||
packaging==24.1
|
||||
pandas==2.2.3
|
||||
pillow==10.4.0
|
||||
pyparsing==3.1.4
|
||||
python-dateutil==2.9.0.post0
|
||||
pytz==2024.2
|
||||
six==1.16.0
|
||||
tzdata==2024.2
|
||||
3
host/examples/bladeRF-cli/sc16q11-packed-mimo/run.sh
Executable file
3
host/examples/bladeRF-cli/sc16q11-packed-mimo/run.sh
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
set -e
|
||||
bladeRF-cli -s rx.txt
|
||||
python3 validate.py /tmp/data.csv
|
||||
8
host/examples/bladeRF-cli/sc16q11-packed-mimo/rx.txt
Normal file
8
host/examples/bladeRF-cli/sc16q11-packed-mimo/rx.txt
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
set bitmode packed
|
||||
set rx_mux 12BIT_COUNTER
|
||||
# set frequency 915M
|
||||
set samplerate 61.44M
|
||||
rx config file=/tmp/data.csv format=csv n=40k channel=1,2
|
||||
# rx config file=/tmp/data.csv format=csv n=200k
|
||||
rx start
|
||||
rx wait
|
||||
100
host/examples/bladeRF-cli/sc16q11-packed-mimo/validate.py
Normal file
100
host/examples/bladeRF-cli/sc16q11-packed-mimo/validate.py
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
import matplotlib.pyplot as plt
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import sys
|
||||
import ast
|
||||
|
||||
def import_data(file_path):
|
||||
try:
|
||||
# Read the CSV file without header
|
||||
df = pd.read_csv(file_path, header=None)
|
||||
|
||||
# Function to safely convert string representations of tuples to actual tuples
|
||||
def safe_eval(x):
|
||||
try:
|
||||
return ast.literal_eval(x)
|
||||
except:
|
||||
return x
|
||||
|
||||
# Apply safe_eval to all elements
|
||||
df = df.apply(lambda col: col.map(safe_eval))
|
||||
|
||||
# Rename columns based on the number of columns
|
||||
if df.shape[1] == 2:
|
||||
df.columns = ['I', 'Q']
|
||||
elif df.shape[1] == 4:
|
||||
df.columns = ['I1', 'Q1', 'I2', 'Q2']
|
||||
else:
|
||||
raise ValueError("CSV file must contain either two columns (single channel) or four columns (dual channel)")
|
||||
|
||||
# Extract numeric values from tuples if necessary
|
||||
for col in df.columns:
|
||||
if df[col].dtype == 'object':
|
||||
df[col] = df[col].apply(lambda x: x[0] if isinstance(x, (tuple, list)) else x)
|
||||
|
||||
# Convert to numeric, coercing errors to NaN
|
||||
df = df.apply(pd.to_numeric, errors='coerce')
|
||||
|
||||
# Drop any rows with NaN values
|
||||
df = df.dropna()
|
||||
|
||||
# Check if all columns are numeric
|
||||
for col in df.columns:
|
||||
if not pd.api.types.is_numeric_dtype(df[col]):
|
||||
raise ValueError(f"{col} samples must be numeric")
|
||||
|
||||
return df
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"Error: File '{file_path}' not found")
|
||||
sys.exit(1)
|
||||
except pd.errors.EmptyDataError:
|
||||
print(f"Error: File '{file_path}' is empty")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"Error: {str(e)}")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: python validate.py <path_to_csv_file>")
|
||||
sys.exit(1)
|
||||
|
||||
file_path = sys.argv[1]
|
||||
df = import_data(file_path)
|
||||
|
||||
# Determine if it's single or dual channel
|
||||
is_dual_channel = 'I2' in df.columns
|
||||
|
||||
plt.figure(figsize=(12, 8))
|
||||
|
||||
if is_dual_channel:
|
||||
# Plot Channel 1
|
||||
plt.subplot(2, 1, 1)
|
||||
plt.plot(df.index, df['I1'], label='I (Ch1)', alpha=0.7)
|
||||
plt.plot(df.index, df['Q1'], label='Q (Ch1)', alpha=0.7)
|
||||
plt.ylabel('Amplitude (Ch1)')
|
||||
plt.title('I/Q Components Over Time - Channel 1')
|
||||
plt.legend(loc='upper right')
|
||||
plt.grid(True, alpha=0.3)
|
||||
|
||||
# Plot Channel 2
|
||||
plt.subplot(2, 1, 2)
|
||||
plt.plot(df.index, df['I2'], label='I (Ch2)', alpha=0.7)
|
||||
plt.plot(df.index, df['Q2'], label='Q (Ch2)', alpha=0.7)
|
||||
plt.xlabel('Sample Index')
|
||||
plt.ylabel('Amplitude (Ch2)')
|
||||
plt.title('I/Q Components Over Time - Channel 2')
|
||||
plt.legend(loc='upper right')
|
||||
plt.grid(True, alpha=0.3)
|
||||
else:
|
||||
# Plot Single Channel
|
||||
plt.plot(df.index, df['I'], label='I', alpha=0.7)
|
||||
plt.plot(df.index, df['Q'], label='Q', alpha=0.7)
|
||||
plt.xlabel('Sample Index')
|
||||
plt.ylabel('Amplitude')
|
||||
plt.title('I/Q Components Over Time - Single Channel')
|
||||
plt.legend(loc='upper right')
|
||||
plt.grid(True, alpha=0.3)
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
Loading…
Add table
Add a link
Reference in a new issue