87 lines
3.1 KiB
ReStructuredText
87 lines
3.1 KiB
ReStructuredText
.. _txrx:
|
|
|
|
Rx-Tx Example
|
|
=============
|
|
|
|
This section provides an overview of the example code for working with SDRs using the ``Blade`` class from the
|
|
`utils.sdr` module. The example can be used for other radios as well, as ``utils.sdr`` has a common set of interfaces.
|
|
|
|
.. contents::
|
|
:local:
|
|
|
|
Introduction
|
|
------------
|
|
|
|
The following examples demonstrate how to initialize an SDR, record a signal, and transmit a custom waveform.
|
|
These examples assume familiarity with Python and SDR concepts.
|
|
|
|
Example 1: Recording a Signal
|
|
-----------------------------
|
|
|
|
In this example, we initialize the `Blade` SDR, configure it to record a signal for a specified duration, and then
|
|
visualize the recorded data.
|
|
|
|
.. code-block:: python
|
|
|
|
from utils.sdr.blade import Blade
|
|
from utils.data.recording import Recording
|
|
import time
|
|
|
|
my_radio = Blade()
|
|
print(my_radio)
|
|
print(type(my_radio))
|
|
my_radio.init_rx(
|
|
sample_rate=1e6,
|
|
center_frequency=2.44e9,
|
|
gain=50,
|
|
channel=0
|
|
)
|
|
rx_time = 0.01
|
|
start = time.time()
|
|
my_rec = my_radio.record(rx_time=rx_time)
|
|
end = time.time()
|
|
print(f"Total time: {end-start} seconds")
|
|
print(len(my_rec))
|
|
my_rec.view()
|
|
|
|
Example 2: Transmitting a Custom Waveform
|
|
-----------------------------------------
|
|
|
|
This example illustrates how to generate a custom chirp signal and transmit it using the ``Blade`` SDR. The waveform is
|
|
created using the ``numpy`` library and encapsulated in a ``Recording`` object.
|
|
|
|
.. code-block:: python
|
|
|
|
from utils.sdr.blade import Blade
|
|
from utils.data.recording import Recording
|
|
import time
|
|
import numpy as np
|
|
|
|
num_samples = 1_000_000 # Total number of samples
|
|
num_chirps = 10 # Number of upchirps
|
|
sample_rate = 1e6 # Sample rate in Hz (arbitrary choice for normalization)
|
|
chirp_duration = num_samples // num_chirps / sample_rate # Duration of each chirp in seconds
|
|
f_start = 0 # Start frequency of the chirp (normalized)
|
|
f_end = 0.5 * sample_rate # End frequency of the chirp (normalized to Nyquist)
|
|
iq_data = np.tile(np.exp(2j * np.pi * (np.linspace(0, num_samples // num_chirps / sample_rate, num_samples // num_chirps, endpoint=False) * f_start + (f_end - f_start) / (2 * (num_samples // num_chirps / sample_rate)) * np.linspace(0, num_samples // num_chirps / sample_rate, num_samples // num_chirps, endpoint=False)**2)), num_chirps)[:num_samples].astype("complex64")
|
|
|
|
iq_data = Recording(data=iq_data)
|
|
|
|
my_radio = Blade()
|
|
my_radio.init_tx(
|
|
sample_rate=1e6,
|
|
center_frequency=2.44e9,
|
|
gain=50,
|
|
channel=0
|
|
)
|
|
start = time.time()
|
|
my_radio.transmit_recording(recording=iq_data, tx_time=10,)
|
|
end = time.time()
|
|
print(f"Total time: {end-start} seconds")
|
|
|
|
Conclusion
|
|
----------
|
|
|
|
These examples provide a foundation for working with SDRs using the ``Blade`` class. By customizing the parameters,
|
|
you can adapt these scripts to various signal processing and SDR tasks.
|