-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Travis F. Collins <[email protected]>
- Loading branch information
Showing
9 changed files
with
1,199 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .e36233a import E36233A | ||
from .n9040b import N9040B | ||
from .dwta import utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .utils import data_to_iq_datafile | ||
|
||
supported_devices = ["Pluto", "ad9081", "ad9084"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Keysight DWTA data capture module.""" | ||
|
||
import adi | ||
|
||
from .utils import data_to_iq_datafile | ||
from ..dwta import supported_devices | ||
|
||
|
||
def capture_iq_datafile( | ||
filename: str, device_name: str, samples: int, uri: str, **kwargs | ||
) -> None: | ||
"""Capture IQ data to a file. | ||
Args: | ||
filename: The filename to write to. | ||
device_name: The device name. | ||
samples: The number of samples to capture. | ||
uri: The URI of the device. | ||
*args: Additional arguments. | ||
**kwargs: Additional keyword arguments. | ||
""" | ||
# Checks | ||
assert ( | ||
device_name in supported_devices | ||
), f"Device not supported: {device_name}.\n Supported devices: {supported_devices}" | ||
assert samples > 0, "Number of samples must be greater than 0" | ||
if "ip:" not in uri and "usb:" not in uri: | ||
raise ValueError(f"URI must start with 'ip:' or 'usb:'. Got: {uri}") | ||
|
||
# Create device | ||
device = getattr(adi, device_name)(uri) | ||
|
||
# Assume kwargs are attributes to set | ||
for key, value in kwargs.items(): | ||
print(f"Setting {key} to {value}") | ||
if not hasattr(device, key): | ||
raise AttributeError(f"Device does not have attribute: {key}") | ||
setattr(device, key, value) | ||
|
||
# Capture data | ||
device.rx_buffer_size = samples | ||
data = device.rx() | ||
|
||
# Write data to file | ||
data_to_iq_datafile(device, data, filename, device_check=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""""Utilities for the Keysight DWTA.""" | ||
|
||
from typing import List, Union | ||
import numpy as np | ||
|
||
import adi | ||
|
||
|
||
def data_to_iq_datafile( | ||
device, data: np.ndarray, filename: str, device_check: bool = True | ||
) -> None: | ||
"""Write data to a file in IQ data format. | ||
Args: | ||
device: Device object from pyadi-iio library. | ||
data: The data to write. | ||
filename: The filename to write to. | ||
device_check: Check if specific class is supported. Default is True. | ||
""" | ||
# Checks | ||
assert data.dtype == np.complex128, "Data must be complex" | ||
assert device._complex_data, "Device does not support complex data" | ||
if device_check: | ||
supported_devices = ["Pluto", "ad9081"] | ||
assert any( | ||
dev in device.__class__.__name__ for dev in supported_devices | ||
), f"Device not supported. Supported devices: {supported_devices}" | ||
|
||
# Get sample rate and carrier frequencies | ||
if hasattr(device, "sample_rate"): | ||
sample_rate = device.sample_rate | ||
elif hasattr(device, "rx_sample_rate"): | ||
sample_rate = device.rx_sample_rate | ||
else: | ||
raise AttributeError("Device does not have sample rate attribute") | ||
|
||
if type(device) in [adi.Pluto]: | ||
center_frequency = int(device.rx_lo) # FIXME | ||
else: | ||
raise NotImplementedError("Center frequency not implemented for this device") | ||
|
||
assert device._complex_data, "Device does not support complex data" | ||
|
||
with open(filename, "w") as f: | ||
f.write(f"SampleRate={sample_rate}\n") | ||
f.write(f"CenterFrequency={center_frequency}\n") | ||
for d in data: | ||
f.write(f"{d.real},{d.imag}\n") | ||
|
||
print(f"Data written to {filename}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.