iq-files 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- iq_files-0.1.0/PKG-INFO +59 -0
- iq_files-0.1.0/README.md +32 -0
- iq_files-0.1.0/pyproject.toml +44 -0
- iq_files-0.1.0/setup.cfg +4 -0
- iq_files-0.1.0/src/iq_files/__init__.py +52 -0
- iq_files-0.1.0/src/iq_files/iq_files.py +111 -0
- iq_files-0.1.0/src/iq_files/load_cs12.py +60 -0
- iq_files-0.1.0/src/iq_files/load_csv_iq.py +14 -0
- iq_files-0.1.0/src/iq_files/load_cu8.py +47 -0
- iq_files-0.1.0/src/iq_files/load_grcomplex.py +14 -0
- iq_files-0.1.0/src/iq_files/load_int8.py +17 -0
- iq_files-0.1.0/src/iq_files/load_sc16full.py +17 -0
- iq_files-0.1.0/src/iq_files/load_sc16q11.py +17 -0
- iq_files-0.1.0/src/iq_files/load_wav_iq.py +23 -0
- iq_files-0.1.0/src/iq_files/py.typed +0 -0
- iq_files-0.1.0/src/iq_files/save_cs12.py +9 -0
- iq_files-0.1.0/src/iq_files/save_csv_iq.py +15 -0
- iq_files-0.1.0/src/iq_files/save_cu8.py +10 -0
- iq_files-0.1.0/src/iq_files/save_grcomplex.py +14 -0
- iq_files-0.1.0/src/iq_files/save_int8.py +22 -0
- iq_files-0.1.0/src/iq_files/save_sc16full.py +22 -0
- iq_files-0.1.0/src/iq_files/save_sc16q11.py +25 -0
- iq_files-0.1.0/src/iq_files/save_wav_iq.py +20 -0
- iq_files-0.1.0/src/iq_files.egg-info/PKG-INFO +59 -0
- iq_files-0.1.0/src/iq_files.egg-info/SOURCES.txt +27 -0
- iq_files-0.1.0/src/iq_files.egg-info/dependency_links.txt +1 -0
- iq_files-0.1.0/src/iq_files.egg-info/requires.txt +2 -0
- iq_files-0.1.0/src/iq_files.egg-info/top_level.txt +1 -0
- iq_files-0.1.0/tests/test_python_iq.py +117 -0
iq_files-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: iq-files
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Fast, lightweight I/Q complex signal file reading and writing for SDR in Python (RTL-SDR, HackRF, bladeRF, LimeSDR, GNU Radio, WAV, CSV)
|
|
5
|
+
Author: Terry Joel Casani Valencia
|
|
6
|
+
License-Expression: GPL-3.0-or-later
|
|
7
|
+
Project-URL: Homepage, https://github.com/tcasaniv/iq-files
|
|
8
|
+
Project-URL: Documentation, https://github.com/tcasaniv/iq-files/tree/main/python#readme
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/tcasaniv/iq-files/issues
|
|
10
|
+
Project-URL: Source Code, https://github.com/tcasaniv/iq-files/tree/main/python
|
|
11
|
+
Keywords: sdr,iq,dsp,radio,signal,bladerf,hackrf,rtlsdr,limesdr,gnuradio
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering
|
|
22
|
+
Classifier: Topic :: Communications :: Ham Radio
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
Requires-Dist: numpy>=1.20
|
|
26
|
+
Requires-Dist: scipy>=1.7
|
|
27
|
+
|
|
28
|
+
# iq-files (Python)
|
|
29
|
+
|
|
30
|
+
Biblioteca y scripts modulares para leer y guardar archivos de señales I/Q complejas para Radio Definida por Software (SDR) en Python con NumPy.
|
|
31
|
+
|
|
32
|
+
## Opciones de Uso
|
|
33
|
+
|
|
34
|
+
### 1. Copiar un Script Individual Autocontenido (Sin Instalación)
|
|
35
|
+
Si solo necesitas un formato concreto, puedes copiar el archivo individual que necesites directamente a tu carpeta de trabajo:
|
|
36
|
+
- `load_sc16q11.py` / `save_sc16q11.py`: bladeRF SC16 Q11 (int16 normalizado a $\pm 2048$).
|
|
37
|
+
- `load_grcomplex.py` / `save_grcomplex.py`: GNU Radio float32 complex (`complex64`).
|
|
38
|
+
- `load_sc16full.py` / `save_sc16full.py`: int16 Little-Endian escala completa ($\pm 32768$).
|
|
39
|
+
- `load_int8.py` / `save_int8.py`: HackRF / RTL-SDR signed 8-bit ($\pm 128$).
|
|
40
|
+
- `load_wav_iq.py` / `save_wav_iq.py`: WAV I/Q estéreo de 16 bits PCM.
|
|
41
|
+
- `load_csv_iq.py` / `save_csv_iq.py`: Texto plano CSV con columnas I, Q.
|
|
42
|
+
|
|
43
|
+
### 2. Instalar la Biblioteca Unificada (`pip install iq-files`) o Copiar `iq_files.py`
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import iq_files
|
|
47
|
+
import numpy as np
|
|
48
|
+
|
|
49
|
+
# Generar tono de prueba
|
|
50
|
+
fs = 48000
|
|
51
|
+
t = np.arange(0, 1.0, 1/fs)
|
|
52
|
+
iq = 0.7 * np.exp(1j * 2 * np.pi * 1000 * t).astype(np.complex64)
|
|
53
|
+
|
|
54
|
+
# Guardar en formato bladeRF
|
|
55
|
+
iq_files.write_iq('signal.bin', iq, sample_rate=fs, format='sc16q11')
|
|
56
|
+
|
|
57
|
+
# Leer señal en formato GNU Radio float32
|
|
58
|
+
samples, rate = iq_files.read_iq('signal.iq', format='grcomplex')
|
|
59
|
+
```
|
iq_files-0.1.0/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# iq-files (Python)
|
|
2
|
+
|
|
3
|
+
Biblioteca y scripts modulares para leer y guardar archivos de señales I/Q complejas para Radio Definida por Software (SDR) en Python con NumPy.
|
|
4
|
+
|
|
5
|
+
## Opciones de Uso
|
|
6
|
+
|
|
7
|
+
### 1. Copiar un Script Individual Autocontenido (Sin Instalación)
|
|
8
|
+
Si solo necesitas un formato concreto, puedes copiar el archivo individual que necesites directamente a tu carpeta de trabajo:
|
|
9
|
+
- `load_sc16q11.py` / `save_sc16q11.py`: bladeRF SC16 Q11 (int16 normalizado a $\pm 2048$).
|
|
10
|
+
- `load_grcomplex.py` / `save_grcomplex.py`: GNU Radio float32 complex (`complex64`).
|
|
11
|
+
- `load_sc16full.py` / `save_sc16full.py`: int16 Little-Endian escala completa ($\pm 32768$).
|
|
12
|
+
- `load_int8.py` / `save_int8.py`: HackRF / RTL-SDR signed 8-bit ($\pm 128$).
|
|
13
|
+
- `load_wav_iq.py` / `save_wav_iq.py`: WAV I/Q estéreo de 16 bits PCM.
|
|
14
|
+
- `load_csv_iq.py` / `save_csv_iq.py`: Texto plano CSV con columnas I, Q.
|
|
15
|
+
|
|
16
|
+
### 2. Instalar la Biblioteca Unificada (`pip install iq-files`) o Copiar `iq_files.py`
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
import iq_files
|
|
20
|
+
import numpy as np
|
|
21
|
+
|
|
22
|
+
# Generar tono de prueba
|
|
23
|
+
fs = 48000
|
|
24
|
+
t = np.arange(0, 1.0, 1/fs)
|
|
25
|
+
iq = 0.7 * np.exp(1j * 2 * np.pi * 1000 * t).astype(np.complex64)
|
|
26
|
+
|
|
27
|
+
# Guardar en formato bladeRF
|
|
28
|
+
iq_files.write_iq('signal.bin', iq, sample_rate=fs, format='sc16q11')
|
|
29
|
+
|
|
30
|
+
# Leer señal en formato GNU Radio float32
|
|
31
|
+
samples, rate = iq_files.read_iq('signal.iq', format='grcomplex')
|
|
32
|
+
```
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "iq-files"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Terry Joel Casani Valencia" },
|
|
10
|
+
]
|
|
11
|
+
description = "Fast, lightweight I/Q complex signal file reading and writing for SDR in Python (RTL-SDR, HackRF, bladeRF, LimeSDR, GNU Radio, WAV, CSV)"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = "GPL-3.0-or-later"
|
|
14
|
+
requires-python = ">=3.8"
|
|
15
|
+
dependencies = [
|
|
16
|
+
"numpy>=1.20",
|
|
17
|
+
"scipy>=1.7",
|
|
18
|
+
]
|
|
19
|
+
keywords = ["sdr", "iq", "dsp", "radio", "signal", "bladerf", "hackrf", "rtlsdr", "limesdr", "gnuradio"]
|
|
20
|
+
classifiers = [
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.8",
|
|
23
|
+
"Programming Language :: Python :: 3.9",
|
|
24
|
+
"Programming Language :: Python :: 3.10",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: 3.13",
|
|
28
|
+
"Programming Language :: Python :: 3.14",
|
|
29
|
+
"Operating System :: OS Independent",
|
|
30
|
+
"Topic :: Scientific/Engineering",
|
|
31
|
+
"Topic :: Communications :: Ham Radio",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
"Homepage" = "https://github.com/tcasaniv/iq-files"
|
|
36
|
+
"Documentation" = "https://github.com/tcasaniv/iq-files/tree/main/python#readme"
|
|
37
|
+
"Bug Tracker" = "https://github.com/tcasaniv/iq-files/issues"
|
|
38
|
+
"Source Code" = "https://github.com/tcasaniv/iq-files/tree/main/python"
|
|
39
|
+
|
|
40
|
+
[tool.setuptools.packages.find]
|
|
41
|
+
where = ["src"]
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.package-data]
|
|
44
|
+
"iq_files" = ["py.typed"]
|
iq_files-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""
|
|
2
|
+
iq_files: Paquete modular de lectura y escritura de señales I/Q complejas para Radio Definida por Software (SDR).
|
|
3
|
+
Compatible con bladeRF, HackRF, RTL-SDR, LimeSDR, GNU Radio, WAV y CSV.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from .iq_files import read_iq, write_iq
|
|
7
|
+
from .load_sc16q11 import load_sc16q11
|
|
8
|
+
from .save_sc16q11 import save_sc16q11
|
|
9
|
+
from .load_sc16full import load_sc16full
|
|
10
|
+
from .save_sc16full import save_sc16full
|
|
11
|
+
from .load_grcomplex import load_grcomplex
|
|
12
|
+
from .save_grcomplex import save_grcomplex
|
|
13
|
+
from .load_int8 import load_int8
|
|
14
|
+
from .save_int8 import save_int8
|
|
15
|
+
from .load_cu8 import load_cu8, load_cu8_from_bytes, save_cu8, save_cu8_to_bytes
|
|
16
|
+
from .load_cs12 import load_cs12, load_cs12_from_bytes, save_cs12, save_cs12_to_bytes
|
|
17
|
+
from .load_wav_iq import load_wav_iq
|
|
18
|
+
from .save_wav_iq import save_wav_iq
|
|
19
|
+
from .load_csv_iq import load_csv_iq
|
|
20
|
+
from .save_csv_iq import save_csv_iq
|
|
21
|
+
|
|
22
|
+
__version__ = "0.1.0"
|
|
23
|
+
__author__ = "Terry Joel Casani Valencia"
|
|
24
|
+
__license__ = "GPL-3.0-or-later"
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"__version__",
|
|
28
|
+
"__author__",
|
|
29
|
+
"__license__",
|
|
30
|
+
"read_iq",
|
|
31
|
+
"write_iq",
|
|
32
|
+
"load_sc16q11",
|
|
33
|
+
"save_sc16q11",
|
|
34
|
+
"load_sc16full",
|
|
35
|
+
"save_sc16full",
|
|
36
|
+
"load_grcomplex",
|
|
37
|
+
"save_grcomplex",
|
|
38
|
+
"load_int8",
|
|
39
|
+
"save_int8",
|
|
40
|
+
"load_cu8",
|
|
41
|
+
"load_cu8_from_bytes",
|
|
42
|
+
"save_cu8",
|
|
43
|
+
"save_cu8_to_bytes",
|
|
44
|
+
"load_cs12",
|
|
45
|
+
"load_cs12_from_bytes",
|
|
46
|
+
"save_cs12",
|
|
47
|
+
"save_cs12_to_bytes",
|
|
48
|
+
"load_wav_iq",
|
|
49
|
+
"save_wav_iq",
|
|
50
|
+
"load_csv_iq",
|
|
51
|
+
"save_csv_iq",
|
|
52
|
+
]
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""
|
|
2
|
+
iq_files: Módulo unificado para lectura y guardado de archivos de señales I/Q complejas.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from typing import Tuple, Optional
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
from .load_sc16q11 import load_sc16q11
|
|
10
|
+
from .save_sc16q11 import save_sc16q11
|
|
11
|
+
from .load_sc16full import load_sc16full
|
|
12
|
+
from .save_sc16full import save_sc16full
|
|
13
|
+
from .load_grcomplex import load_grcomplex
|
|
14
|
+
from .save_grcomplex import save_grcomplex
|
|
15
|
+
from .load_int8 import load_int8
|
|
16
|
+
from .save_int8 import save_int8
|
|
17
|
+
from .load_cu8 import load_cu8, save_cu8
|
|
18
|
+
from .load_cs12 import load_cs12, save_cs12
|
|
19
|
+
from .load_wav_iq import load_wav_iq
|
|
20
|
+
from .save_wav_iq import save_wav_iq
|
|
21
|
+
from .load_csv_iq import load_csv_iq
|
|
22
|
+
from .save_csv_iq import save_csv_iq
|
|
23
|
+
except ImportError:
|
|
24
|
+
from load_sc16q11 import load_sc16q11
|
|
25
|
+
from save_sc16q11 import save_sc16q11
|
|
26
|
+
from load_sc16full import load_sc16full
|
|
27
|
+
from save_sc16full import save_sc16full
|
|
28
|
+
from load_grcomplex import load_grcomplex
|
|
29
|
+
from save_grcomplex import save_grcomplex
|
|
30
|
+
from load_int8 import load_int8
|
|
31
|
+
from save_int8 import save_int8
|
|
32
|
+
from load_cu8 import load_cu8, save_cu8
|
|
33
|
+
from load_cs12 import load_cs12, save_cs12
|
|
34
|
+
from load_wav_iq import load_wav_iq
|
|
35
|
+
from save_wav_iq import save_wav_iq
|
|
36
|
+
from load_csv_iq import load_csv_iq
|
|
37
|
+
from save_csv_iq import save_csv_iq
|
|
38
|
+
|
|
39
|
+
__all__ = [
|
|
40
|
+
'read_iq',
|
|
41
|
+
'write_iq',
|
|
42
|
+
'load_sc16q11',
|
|
43
|
+
'save_sc16q11',
|
|
44
|
+
'load_sc16full',
|
|
45
|
+
'save_sc16full',
|
|
46
|
+
'load_grcomplex',
|
|
47
|
+
'save_grcomplex',
|
|
48
|
+
'load_int8',
|
|
49
|
+
'save_int8',
|
|
50
|
+
'load_cu8',
|
|
51
|
+
'save_cu8',
|
|
52
|
+
'load_cs12',
|
|
53
|
+
'save_cs12',
|
|
54
|
+
'load_wav_iq',
|
|
55
|
+
'save_wav_iq',
|
|
56
|
+
'load_csv_iq',
|
|
57
|
+
'save_csv_iq',
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
def read_iq(filename: str, format: str = 'sc16q11') -> Tuple[np.ndarray, int]:
|
|
61
|
+
"""
|
|
62
|
+
Lee un archivo de señal I/Q en el formato especificado.
|
|
63
|
+
Formatos disponibles: 'sc16q11', 'sc16full', 'grcomplex', 'float32', 'int8', 'cu8', 'u8', 'cs12', 'wav_iq', 'csv_iq'.
|
|
64
|
+
Retorna (signal, sample_rate).
|
|
65
|
+
"""
|
|
66
|
+
fmt = format.lower()
|
|
67
|
+
if fmt == 'sc16q11':
|
|
68
|
+
return load_sc16q11(filename), 288000
|
|
69
|
+
elif fmt == 'sc16full':
|
|
70
|
+
return load_sc16full(filename), 288000
|
|
71
|
+
elif fmt in ('grcomplex', 'float32', 'cf32'):
|
|
72
|
+
return load_grcomplex(filename), 1000000
|
|
73
|
+
elif fmt in ('int8', 'cs8', 'sc8'):
|
|
74
|
+
return load_int8(filename), 2000000
|
|
75
|
+
elif fmt in ('cu8', 'u8'):
|
|
76
|
+
return load_cu8(filename), 2048000
|
|
77
|
+
elif fmt in ('cs12', 'sc12'):
|
|
78
|
+
return load_cs12(filename), 2000000
|
|
79
|
+
elif fmt in ('wav_iq', 'wav'):
|
|
80
|
+
return load_wav_iq(filename)
|
|
81
|
+
elif fmt in ('csv_iq', 'csv'):
|
|
82
|
+
return load_csv_iq(filename), 48000
|
|
83
|
+
else:
|
|
84
|
+
raise ValueError(f"Formato desconocido '{format}'. Use: sc16q11, sc16full, grcomplex, int8, cu8, cs12, wav_iq, csv_iq")
|
|
85
|
+
|
|
86
|
+
def write_iq(filename: str, signal: np.ndarray, sample_rate: int = 288000, format: str = 'sc16q11') -> bool:
|
|
87
|
+
"""
|
|
88
|
+
Guarda una señal I/Q en el formato especificado.
|
|
89
|
+
Formatos disponibles: 'sc16q11', 'sc16full', 'grcomplex', 'float32', 'int8', 'cu8', 'u8', 'cs12', 'wav_iq', 'csv_iq'.
|
|
90
|
+
"""
|
|
91
|
+
fmt = format.lower()
|
|
92
|
+
if fmt == 'sc16q11':
|
|
93
|
+
return save_sc16q11(filename, signal)
|
|
94
|
+
elif fmt == 'sc16full':
|
|
95
|
+
return save_sc16full(filename, signal)
|
|
96
|
+
elif fmt in ('grcomplex', 'float32', 'cf32'):
|
|
97
|
+
return save_grcomplex(filename, signal)
|
|
98
|
+
elif fmt in ('int8', 'cs8', 'sc8'):
|
|
99
|
+
return save_int8(filename, signal)
|
|
100
|
+
elif fmt in ('cu8', 'u8'):
|
|
101
|
+
save_cu8(filename, signal)
|
|
102
|
+
return True
|
|
103
|
+
elif fmt in ('cs12', 'sc12'):
|
|
104
|
+
save_cs12(filename, signal)
|
|
105
|
+
return True
|
|
106
|
+
elif fmt in ('wav_iq', 'wav'):
|
|
107
|
+
return save_wav_iq(filename, signal, sample_rate)
|
|
108
|
+
elif fmt in ('csv_iq', 'csv'):
|
|
109
|
+
return save_csv_iq(filename, signal)
|
|
110
|
+
else:
|
|
111
|
+
raise ValueError(f"Formato desconocido '{format}'. Use: sc16q11, sc16full, grcomplex, int8, cu8, cs12, wav_iq, csv_iq")
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""
|
|
2
|
+
load_cs12 / save_cs12: Muestras I/Q RAW Enteros de 12 bits con signo empaquetados (CS12 Packed).
|
|
3
|
+
|
|
4
|
+
¿CUÁNDO USAR ESTE FORMATO?
|
|
5
|
+
--------------------------
|
|
6
|
+
- Hardware típico: Dispositivos LimeSDR (LMS7002M) y bladeRF en modo 12-bit packed.
|
|
7
|
+
- Motivo: Ahorra un 25% de ancho de banda USB empaquetando dos enteros de 12 bits en 3 bytes.
|
|
8
|
+
|
|
9
|
+
ESPECIFICACIONES TÉCNICAS:
|
|
10
|
+
--------------------------
|
|
11
|
+
- Bytes por muestra compleja: 3 bytes por par (I, Q).
|
|
12
|
+
- Rango: [-2048, 2047]. Cero en 0.0.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import numpy as np
|
|
16
|
+
|
|
17
|
+
def load_cs12_from_bytes(raw_bytes: bytes) -> np.ndarray:
|
|
18
|
+
"""Decodifica un buffer de bytes CS12 packed a complex64."""
|
|
19
|
+
num_samples = len(raw_bytes) // 3
|
|
20
|
+
if num_samples == 0:
|
|
21
|
+
return np.array([], dtype=np.complex64)
|
|
22
|
+
|
|
23
|
+
raw = np.frombuffer(raw_bytes[:num_samples * 3], dtype=np.uint8)
|
|
24
|
+
b0 = raw[0::3].astype(np.int32)
|
|
25
|
+
b1 = raw[1::3].astype(np.int32)
|
|
26
|
+
b2 = raw[2::3].astype(np.int32)
|
|
27
|
+
|
|
28
|
+
i_raw = b0 | ((b1 & 0x0F) << 8)
|
|
29
|
+
q_raw = ((b1 >> 4) & 0x0F) | (b2 << 4)
|
|
30
|
+
|
|
31
|
+
# Sign extension de 12 bits a int32
|
|
32
|
+
i_raw = np.where(i_raw >= 2048, i_raw - 4096, i_raw)
|
|
33
|
+
q_raw = np.where(q_raw >= 2048, q_raw - 4096, q_raw)
|
|
34
|
+
|
|
35
|
+
return (i_raw.astype(np.float32) / 2048.0) + 1j * (q_raw.astype(np.float32) / 2048.0)
|
|
36
|
+
|
|
37
|
+
def load_cs12(filepath: str) -> np.ndarray:
|
|
38
|
+
with open(filepath, 'rb') as f:
|
|
39
|
+
return load_cs12_from_bytes(f.read())
|
|
40
|
+
|
|
41
|
+
def save_cs12_to_bytes(iq_samples: np.ndarray) -> bytes:
|
|
42
|
+
i_val = np.clip(np.round(np.real(iq_samples) * 2047.0), -2048, 2047).astype(np.int32)
|
|
43
|
+
q_val = np.clip(np.round(np.imag(iq_samples) * 2047.0), -2048, 2047).astype(np.int32)
|
|
44
|
+
|
|
45
|
+
i_u12 = i_val & 0x0FFF
|
|
46
|
+
q_u12 = q_val & 0x0FFF
|
|
47
|
+
|
|
48
|
+
b0 = (i_u12 & 0x00FF).astype(np.uint8)
|
|
49
|
+
b1 = (((i_u12 >> 8) & 0x0F) | ((q_u12 & 0x0F) << 4)).astype(np.uint8)
|
|
50
|
+
b2 = ((q_u12 >> 4) & 0xFF).astype(np.uint8)
|
|
51
|
+
|
|
52
|
+
interleaved = np.empty(len(iq_samples) * 3, dtype=np.uint8)
|
|
53
|
+
interleaved[0::3] = b0
|
|
54
|
+
interleaved[1::3] = b1
|
|
55
|
+
interleaved[2::3] = b2
|
|
56
|
+
return interleaved.tobytes()
|
|
57
|
+
|
|
58
|
+
def save_cs12(filepath: str, iq_samples: np.ndarray) -> None:
|
|
59
|
+
with open(filepath, 'wb') as f:
|
|
60
|
+
f.write(save_cs12_to_bytes(iq_samples))
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def load_csv_iq(filename: str) -> np.ndarray:
|
|
4
|
+
"""
|
|
5
|
+
Lee un archivo CSV con columnas I, Q como señal compleja.
|
|
6
|
+
"""
|
|
7
|
+
data = np.loadtxt(filename, delimiter=',', comments='#')
|
|
8
|
+
return data[:, 0].astype(np.float32) + 1j * data[:, 1].astype(np.float32)
|
|
9
|
+
|
|
10
|
+
if __name__ == '__main__':
|
|
11
|
+
import sys
|
|
12
|
+
if len(sys.argv) > 1:
|
|
13
|
+
data = load_csv_iq(sys.argv[1])
|
|
14
|
+
print(f"Cargadas {len(data)} muestras complejas.")
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""
|
|
2
|
+
load_cu8 / save_cu8: Muestras I/Q RAW Enteros de 8 bits sin signo (CU8 / uint8).
|
|
3
|
+
|
|
4
|
+
¿CUÁNDO USAR ESTE FORMATO?
|
|
5
|
+
--------------------------
|
|
6
|
+
- Hardware típico: Receptores RTL-SDR (DVB-T Blog V3/V4 basados en el chip RTL2832U).
|
|
7
|
+
- Software emisor: Grabaciones de utilidades como 'rtl_sdr', streams de 'rtl_tcp'.
|
|
8
|
+
- Comando típico de captura:
|
|
9
|
+
rtl_sdr -f 433.92M -s 2048000 -g 30 captura.cu8
|
|
10
|
+
|
|
11
|
+
ESPECIFICACIONES TÉCNICAS:
|
|
12
|
+
--------------------------
|
|
13
|
+
- Tipo primitivo: uint8 (unsigned 8-bit, 0 a 255).
|
|
14
|
+
- Entrelazado: [I0, Q0, I1, Q1, ...].
|
|
15
|
+
- Bytes por muestra compleja: 2 bytes.
|
|
16
|
+
- Punto cero: 127.5.
|
|
17
|
+
- Normalización: val_float = (val_u8 - 127.5) / 127.5
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import numpy as np
|
|
21
|
+
|
|
22
|
+
def load_cu8_from_bytes(raw_bytes: bytes) -> np.ndarray:
|
|
23
|
+
"""Decodifica un buffer de bytes CU8 a un array complejo complex64 normalizado en [-1.0, 1.0]."""
|
|
24
|
+
raw = np.frombuffer(raw_bytes, dtype=np.uint8)
|
|
25
|
+
if len(raw) % 2 != 0:
|
|
26
|
+
raw = raw[:len(raw) - 1]
|
|
27
|
+
raw = (raw.astype(np.float32) - 127.5) / 127.5
|
|
28
|
+
return raw[0::2] + 1j * raw[1::2]
|
|
29
|
+
|
|
30
|
+
def load_cu8(filepath: str) -> np.ndarray:
|
|
31
|
+
"""Lee un archivo RAW CU8 de RTL-SDR y retorna muestras complex64."""
|
|
32
|
+
with open(filepath, 'rb') as f:
|
|
33
|
+
return load_cu8_from_bytes(f.read())
|
|
34
|
+
|
|
35
|
+
def save_cu8_to_bytes(iq_samples: np.ndarray) -> bytes:
|
|
36
|
+
"""Codifica un array complejo a bytes en formato RAW CU8 (uint8 sin signo con cero en 127.5)."""
|
|
37
|
+
i_part = np.clip(np.real(iq_samples) * 127.5 + 127.5, 0, 255).astype(np.uint8)
|
|
38
|
+
q_part = np.clip(np.imag(iq_samples) * 127.5 + 127.5, 0, 255).astype(np.uint8)
|
|
39
|
+
interleaved = np.empty(len(iq_samples) * 2, dtype=np.uint8)
|
|
40
|
+
interleaved[0::2] = i_part
|
|
41
|
+
interleaved[1::2] = q_part
|
|
42
|
+
return interleaved.tobytes()
|
|
43
|
+
|
|
44
|
+
def save_cu8(filepath: str, iq_samples: np.ndarray) -> None:
|
|
45
|
+
"""Guarda muestras complejas en un archivo RAW CU8 compatible con RTL-SDR."""
|
|
46
|
+
with open(filepath, 'wb') as f:
|
|
47
|
+
f.write(save_cu8_to_bytes(iq_samples))
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def load_grcomplex(filename: str) -> np.ndarray:
|
|
4
|
+
"""
|
|
5
|
+
Lee un archivo binario en formato GNU Radio complex float32 (complex64).
|
|
6
|
+
Retorna un array de números complejos numpy.complex64.
|
|
7
|
+
"""
|
|
8
|
+
return np.fromfile(filename, dtype=np.complex64)
|
|
9
|
+
|
|
10
|
+
if __name__ == '__main__':
|
|
11
|
+
import sys
|
|
12
|
+
if len(sys.argv) > 1:
|
|
13
|
+
data = load_grcomplex(sys.argv[1])
|
|
14
|
+
print(f"Cargadas {len(data)} muestras complejas.")
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def load_int8(filename: str) -> np.ndarray:
|
|
4
|
+
"""
|
|
5
|
+
Lee un archivo binario en formato RAW signed 8-bit (HackRF / RTL-SDR).
|
|
6
|
+
Retorna un array de números complejos normalizados a [-1.0, 1.0].
|
|
7
|
+
"""
|
|
8
|
+
raw = np.fromfile(filename, dtype=np.int8)
|
|
9
|
+
i = raw[0::2].astype(np.float32) / 128.0
|
|
10
|
+
q = raw[1::2].astype(np.float32) / 128.0
|
|
11
|
+
return i + 1j * q
|
|
12
|
+
|
|
13
|
+
if __name__ == '__main__':
|
|
14
|
+
import sys
|
|
15
|
+
if len(sys.argv) > 1:
|
|
16
|
+
data = load_int8(sys.argv[1])
|
|
17
|
+
print(f"Cargadas {len(data)} muestras complejas.")
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def load_sc16full(filename: str) -> np.ndarray:
|
|
4
|
+
"""
|
|
5
|
+
Lee un archivo binario en formato RAW SC16 escala completa (int16 estándar).
|
|
6
|
+
Retorna un array de números complejos normalizados a [-1.0, 1.0].
|
|
7
|
+
"""
|
|
8
|
+
raw = np.fromfile(filename, dtype=np.int16)
|
|
9
|
+
i = raw[0::2].astype(np.float32) / 32768.0
|
|
10
|
+
q = raw[1::2].astype(np.float32) / 32768.0
|
|
11
|
+
return i + 1j * q
|
|
12
|
+
|
|
13
|
+
if __name__ == '__main__':
|
|
14
|
+
import sys
|
|
15
|
+
if len(sys.argv) > 1:
|
|
16
|
+
data = load_sc16full(sys.argv[1])
|
|
17
|
+
print(f"Cargadas {len(data)} muestras complejas.")
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def load_sc16q11(filename: str) -> np.ndarray:
|
|
4
|
+
"""
|
|
5
|
+
Lee un archivo binario en formato bladeRF SC16 Q11.
|
|
6
|
+
Retorna un array de números complejos con rango normalizado [-1.0, 1.0].
|
|
7
|
+
"""
|
|
8
|
+
raw = np.fromfile(filename, dtype=np.int16)
|
|
9
|
+
i = raw[0::2].astype(np.float32) / 2048.0
|
|
10
|
+
q = raw[1::2].astype(np.float32) / 2048.0
|
|
11
|
+
return i + 1j * q
|
|
12
|
+
|
|
13
|
+
if __name__ == '__main__':
|
|
14
|
+
import sys
|
|
15
|
+
if len(sys.argv) > 1:
|
|
16
|
+
data = load_sc16q11(sys.argv[1])
|
|
17
|
+
print(f"Cargadas {len(data)} muestras complejas.")
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from scipy.io import wavfile
|
|
3
|
+
|
|
4
|
+
def load_wav_iq(filename: str) -> tuple[np.ndarray, int]:
|
|
5
|
+
"""
|
|
6
|
+
Lee un archivo WAV de 2 canales PCM (16 bits) como señal I/Q.
|
|
7
|
+
Canal 1 = I, Canal 2 = Q.
|
|
8
|
+
Retorna (signal, sample_rate).
|
|
9
|
+
"""
|
|
10
|
+
sample_rate, data = wavfile.read(filename)
|
|
11
|
+
if data.ndim == 1:
|
|
12
|
+
i = data.astype(np.float32) / 32768.0
|
|
13
|
+
q = np.zeros_like(i)
|
|
14
|
+
else:
|
|
15
|
+
i = data[:, 0].astype(np.float32) / 32768.0
|
|
16
|
+
q = data[:, 1].astype(np.float32) / 32768.0
|
|
17
|
+
return (i + 1j * q), int(sample_rate)
|
|
18
|
+
|
|
19
|
+
if __name__ == '__main__':
|
|
20
|
+
import sys
|
|
21
|
+
if len(sys.argv) > 1:
|
|
22
|
+
data, fs = load_wav_iq(sys.argv[1])
|
|
23
|
+
print(f"Cargadas {len(data)} muestras a {fs} Hz.")
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""
|
|
2
|
+
save_cs12: Guarda muestras I/Q en formato CS12 Packed (3 bytes/muestra) para LimeSDR / bladeRF.
|
|
3
|
+
"""
|
|
4
|
+
try:
|
|
5
|
+
from .load_cs12 import save_cs12, save_cs12_to_bytes, load_cs12, load_cs12_from_bytes
|
|
6
|
+
except ImportError:
|
|
7
|
+
from load_cs12 import save_cs12, save_cs12_to_bytes, load_cs12, load_cs12_from_bytes
|
|
8
|
+
|
|
9
|
+
__all__ = ["save_cs12", "save_cs12_to_bytes", "load_cs12", "load_cs12_from_bytes"]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def save_csv_iq(filename: str, signal: np.ndarray) -> bool:
|
|
4
|
+
"""
|
|
5
|
+
Guarda muestras complejas en formato CSV con columnas I, Q.
|
|
6
|
+
"""
|
|
7
|
+
signal = np.asarray(signal, dtype=np.complex64)
|
|
8
|
+
data = np.column_stack([signal.real, signal.imag])
|
|
9
|
+
np.savetxt(filename, data, delimiter=', ', fmt='%.7f', header='I, Q', comments='# ')
|
|
10
|
+
return True
|
|
11
|
+
|
|
12
|
+
if __name__ == '__main__':
|
|
13
|
+
sig = np.array([0.1 + 0.2j, -0.3 + 0.4j], dtype=np.complex64)
|
|
14
|
+
save_csv_iq('test_csv.csv', sig)
|
|
15
|
+
print("Guardado test_csv.csv con éxito.")
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""
|
|
2
|
+
save_cu8: Guarda muestras I/Q RAW Enteros de 8 bits sin signo (CU8 / uint8) para RTL-SDR.
|
|
3
|
+
Reexporta desde load_cu8 para permitir uso standalone copiando únicamente save_cu8.py.
|
|
4
|
+
"""
|
|
5
|
+
try:
|
|
6
|
+
from .load_cu8 import save_cu8, save_cu8_to_bytes, load_cu8, load_cu8_from_bytes
|
|
7
|
+
except ImportError:
|
|
8
|
+
from load_cu8 import save_cu8, save_cu8_to_bytes, load_cu8, load_cu8_from_bytes
|
|
9
|
+
|
|
10
|
+
__all__ = ["save_cu8", "save_cu8_to_bytes", "load_cu8", "load_cu8_from_bytes"]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def save_grcomplex(filename: str, signal: np.ndarray) -> bool:
|
|
4
|
+
"""
|
|
5
|
+
Guarda una señal compleja en formato GNU Radio complex float32 (complex64).
|
|
6
|
+
"""
|
|
7
|
+
signal = np.asarray(signal, dtype=np.complex64)
|
|
8
|
+
signal.tofile(filename)
|
|
9
|
+
return True
|
|
10
|
+
|
|
11
|
+
if __name__ == '__main__':
|
|
12
|
+
sig = np.array([0.5 + 0.5j, -0.7 - 0.2j], dtype=np.complex64)
|
|
13
|
+
save_grcomplex('test_grcomplex.iq', sig)
|
|
14
|
+
print("Guardado test_grcomplex.iq con éxito.")
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def save_int8(filename: str, signal: np.ndarray) -> bool:
|
|
4
|
+
"""
|
|
5
|
+
Guarda una señal compleja normalizada en formato RAW signed 8-bit (HackRF / RTL-SDR).
|
|
6
|
+
Rango de normalización: [-1.0, 1.0] mapeado a enteros [-128, 127].
|
|
7
|
+
"""
|
|
8
|
+
signal = np.asarray(signal, dtype=np.complex64)
|
|
9
|
+
i_scaled = np.clip(np.round(signal.real * 127.0), -128, 127).astype(np.int8)
|
|
10
|
+
q_scaled = np.clip(np.round(signal.imag * 127.0), -128, 127).astype(np.int8)
|
|
11
|
+
|
|
12
|
+
interleaved = np.empty(len(signal) * 2, dtype=np.int8)
|
|
13
|
+
interleaved[0::2] = i_scaled
|
|
14
|
+
interleaved[1::2] = q_scaled
|
|
15
|
+
|
|
16
|
+
interleaved.tofile(filename)
|
|
17
|
+
return True
|
|
18
|
+
|
|
19
|
+
if __name__ == '__main__':
|
|
20
|
+
sig = np.array([0.5 + 0.5j, -0.9 - 0.1j], dtype=np.complex64)
|
|
21
|
+
save_int8('test_int8.raw', sig)
|
|
22
|
+
print("Guardado test_int8.raw con éxito.")
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def save_sc16full(filename: str, signal: np.ndarray) -> bool:
|
|
4
|
+
"""
|
|
5
|
+
Guarda una señal compleja normalizada en formato RAW SC16 escala completa (int16 estándar).
|
|
6
|
+
Rango de normalización: [-1.0, 1.0] mapeado a enteros [-32768, 32767].
|
|
7
|
+
"""
|
|
8
|
+
signal = np.asarray(signal, dtype=np.complex64)
|
|
9
|
+
i_scaled = np.clip(np.round(signal.real * 32767.0), -32768, 32767).astype(np.int16)
|
|
10
|
+
q_scaled = np.clip(np.round(signal.imag * 32767.0), -32768, 32767).astype(np.int16)
|
|
11
|
+
|
|
12
|
+
interleaved = np.empty(len(signal) * 2, dtype=np.int16)
|
|
13
|
+
interleaved[0::2] = i_scaled
|
|
14
|
+
interleaved[1::2] = q_scaled
|
|
15
|
+
|
|
16
|
+
interleaved.tofile(filename)
|
|
17
|
+
return True
|
|
18
|
+
|
|
19
|
+
if __name__ == '__main__':
|
|
20
|
+
sig = np.array([0.707 - 0.707j, -0.5 + 0.5j], dtype=np.complex64)
|
|
21
|
+
save_sc16full('test_sc16full.bin', sig)
|
|
22
|
+
print("Guardado test_sc16full.bin con éxito.")
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def save_sc16q11(filename: str, signal: np.ndarray) -> bool:
|
|
4
|
+
"""
|
|
5
|
+
Guarda una señal compleja normalizada en un archivo binario en formato bladeRF SC16 Q11.
|
|
6
|
+
Valores saturados y mapeados a enteros de 16 bits en el rango [-2048, 2047].
|
|
7
|
+
"""
|
|
8
|
+
signal = np.asarray(signal, dtype=np.complex64)
|
|
9
|
+
i_scaled = np.clip(np.round(signal.real * 2048.0), -2048, 2047).astype(np.int16)
|
|
10
|
+
q_scaled = np.clip(np.round(signal.imag * 2048.0), -2048, 2047).astype(np.int16)
|
|
11
|
+
|
|
12
|
+
interleaved = np.empty(len(signal) * 2, dtype=np.int16)
|
|
13
|
+
interleaved[0::2] = i_scaled
|
|
14
|
+
interleaved[1::2] = q_scaled
|
|
15
|
+
|
|
16
|
+
interleaved.tofile(filename)
|
|
17
|
+
return True
|
|
18
|
+
|
|
19
|
+
if __name__ == '__main__':
|
|
20
|
+
# Ejemplo de prueba
|
|
21
|
+
fs = 48000
|
|
22
|
+
t = np.arange(0, 0.1, 1/fs)
|
|
23
|
+
sig = 0.8 * np.exp(1j * 2 * np.pi * 1000 * t)
|
|
24
|
+
save_sc16q11('test_sc16q11.bin', sig)
|
|
25
|
+
print("Guardado test_sc16q11.bin con éxito.")
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from scipy.io import wavfile
|
|
3
|
+
|
|
4
|
+
def save_wav_iq(filename: str, signal: np.ndarray, sample_rate: int = 48000) -> bool:
|
|
5
|
+
"""
|
|
6
|
+
Guarda una señal compleja normalizada en un archivo WAV de 2 canales PCM (16 bits).
|
|
7
|
+
Canal 1 (L) = I, Canal 2 (R) = Q.
|
|
8
|
+
"""
|
|
9
|
+
signal = np.asarray(signal, dtype=np.complex64)
|
|
10
|
+
i_scaled = np.clip(np.round(signal.real * 32767.0), -32768, 32767).astype(np.int16)
|
|
11
|
+
q_scaled = np.clip(np.round(signal.imag * 32767.0), -32768, 32767).astype(np.int16)
|
|
12
|
+
|
|
13
|
+
data = np.column_stack([i_scaled, q_scaled])
|
|
14
|
+
wavfile.write(filename, sample_rate, data)
|
|
15
|
+
return True
|
|
16
|
+
|
|
17
|
+
if __name__ == '__main__':
|
|
18
|
+
sig = np.array([0.5 + 0.5j, -0.5 - 0.5j], dtype=np.complex64)
|
|
19
|
+
save_wav_iq('test_wav.wav', sig, 48000)
|
|
20
|
+
print("Guardado test_wav.wav con éxito.")
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: iq-files
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Fast, lightweight I/Q complex signal file reading and writing for SDR in Python (RTL-SDR, HackRF, bladeRF, LimeSDR, GNU Radio, WAV, CSV)
|
|
5
|
+
Author: Terry Joel Casani Valencia
|
|
6
|
+
License-Expression: GPL-3.0-or-later
|
|
7
|
+
Project-URL: Homepage, https://github.com/tcasaniv/iq-files
|
|
8
|
+
Project-URL: Documentation, https://github.com/tcasaniv/iq-files/tree/main/python#readme
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/tcasaniv/iq-files/issues
|
|
10
|
+
Project-URL: Source Code, https://github.com/tcasaniv/iq-files/tree/main/python
|
|
11
|
+
Keywords: sdr,iq,dsp,radio,signal,bladerf,hackrf,rtlsdr,limesdr,gnuradio
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering
|
|
22
|
+
Classifier: Topic :: Communications :: Ham Radio
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
Requires-Dist: numpy>=1.20
|
|
26
|
+
Requires-Dist: scipy>=1.7
|
|
27
|
+
|
|
28
|
+
# iq-files (Python)
|
|
29
|
+
|
|
30
|
+
Biblioteca y scripts modulares para leer y guardar archivos de señales I/Q complejas para Radio Definida por Software (SDR) en Python con NumPy.
|
|
31
|
+
|
|
32
|
+
## Opciones de Uso
|
|
33
|
+
|
|
34
|
+
### 1. Copiar un Script Individual Autocontenido (Sin Instalación)
|
|
35
|
+
Si solo necesitas un formato concreto, puedes copiar el archivo individual que necesites directamente a tu carpeta de trabajo:
|
|
36
|
+
- `load_sc16q11.py` / `save_sc16q11.py`: bladeRF SC16 Q11 (int16 normalizado a $\pm 2048$).
|
|
37
|
+
- `load_grcomplex.py` / `save_grcomplex.py`: GNU Radio float32 complex (`complex64`).
|
|
38
|
+
- `load_sc16full.py` / `save_sc16full.py`: int16 Little-Endian escala completa ($\pm 32768$).
|
|
39
|
+
- `load_int8.py` / `save_int8.py`: HackRF / RTL-SDR signed 8-bit ($\pm 128$).
|
|
40
|
+
- `load_wav_iq.py` / `save_wav_iq.py`: WAV I/Q estéreo de 16 bits PCM.
|
|
41
|
+
- `load_csv_iq.py` / `save_csv_iq.py`: Texto plano CSV con columnas I, Q.
|
|
42
|
+
|
|
43
|
+
### 2. Instalar la Biblioteca Unificada (`pip install iq-files`) o Copiar `iq_files.py`
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import iq_files
|
|
47
|
+
import numpy as np
|
|
48
|
+
|
|
49
|
+
# Generar tono de prueba
|
|
50
|
+
fs = 48000
|
|
51
|
+
t = np.arange(0, 1.0, 1/fs)
|
|
52
|
+
iq = 0.7 * np.exp(1j * 2 * np.pi * 1000 * t).astype(np.complex64)
|
|
53
|
+
|
|
54
|
+
# Guardar en formato bladeRF
|
|
55
|
+
iq_files.write_iq('signal.bin', iq, sample_rate=fs, format='sc16q11')
|
|
56
|
+
|
|
57
|
+
# Leer señal en formato GNU Radio float32
|
|
58
|
+
samples, rate = iq_files.read_iq('signal.iq', format='grcomplex')
|
|
59
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/iq_files/__init__.py
|
|
4
|
+
src/iq_files/iq_files.py
|
|
5
|
+
src/iq_files/load_cs12.py
|
|
6
|
+
src/iq_files/load_csv_iq.py
|
|
7
|
+
src/iq_files/load_cu8.py
|
|
8
|
+
src/iq_files/load_grcomplex.py
|
|
9
|
+
src/iq_files/load_int8.py
|
|
10
|
+
src/iq_files/load_sc16full.py
|
|
11
|
+
src/iq_files/load_sc16q11.py
|
|
12
|
+
src/iq_files/load_wav_iq.py
|
|
13
|
+
src/iq_files/py.typed
|
|
14
|
+
src/iq_files/save_cs12.py
|
|
15
|
+
src/iq_files/save_csv_iq.py
|
|
16
|
+
src/iq_files/save_cu8.py
|
|
17
|
+
src/iq_files/save_grcomplex.py
|
|
18
|
+
src/iq_files/save_int8.py
|
|
19
|
+
src/iq_files/save_sc16full.py
|
|
20
|
+
src/iq_files/save_sc16q11.py
|
|
21
|
+
src/iq_files/save_wav_iq.py
|
|
22
|
+
src/iq_files.egg-info/PKG-INFO
|
|
23
|
+
src/iq_files.egg-info/SOURCES.txt
|
|
24
|
+
src/iq_files.egg-info/dependency_links.txt
|
|
25
|
+
src/iq_files.egg-info/requires.txt
|
|
26
|
+
src/iq_files.egg-info/top_level.txt
|
|
27
|
+
tests/test_python_iq.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
iq_files
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import unittest
|
|
3
|
+
import numpy as np
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
# Asegurar importación de src para pruebas contra la estructura del paquete
|
|
7
|
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src')))
|
|
8
|
+
|
|
9
|
+
import iq_files
|
|
10
|
+
from iq_files import (
|
|
11
|
+
read_iq, write_iq,
|
|
12
|
+
load_sc16q11, save_sc16q11,
|
|
13
|
+
load_sc16full, save_sc16full,
|
|
14
|
+
load_grcomplex, save_grcomplex,
|
|
15
|
+
load_int8, save_int8,
|
|
16
|
+
load_cu8, save_cu8,
|
|
17
|
+
load_cs12, save_cs12,
|
|
18
|
+
load_wav_iq, save_wav_iq,
|
|
19
|
+
load_csv_iq, save_csv_iq,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
class TestPythonIqFiles(unittest.TestCase):
|
|
23
|
+
def setUp(self):
|
|
24
|
+
self.test_signal = np.array([0.0, 0.5 - 0.5j, 0.99 - 0.99j, -0.7 + 0.3j], dtype=np.complex64)
|
|
25
|
+
self.tmp_files = []
|
|
26
|
+
|
|
27
|
+
def tearDown(self):
|
|
28
|
+
for f in self.tmp_files:
|
|
29
|
+
if os.path.exists(f):
|
|
30
|
+
try:
|
|
31
|
+
os.remove(f)
|
|
32
|
+
except OSError:
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
def test_version_and_metadata(self):
|
|
36
|
+
self.assertEqual(iq_files.__version__, "0.1.0")
|
|
37
|
+
self.assertIn("read_iq", iq_files.__all__)
|
|
38
|
+
self.assertIn("load_cu8", iq_files.__all__)
|
|
39
|
+
self.assertIn("load_cs12", iq_files.__all__)
|
|
40
|
+
|
|
41
|
+
def test_sc16q11(self):
|
|
42
|
+
fname = "tmp_sc16q11.bin"
|
|
43
|
+
self.tmp_files.append(fname)
|
|
44
|
+
save_sc16q11(fname, self.test_signal)
|
|
45
|
+
loaded = load_sc16q11(fname)
|
|
46
|
+
np.testing.assert_allclose(loaded, self.test_signal, atol=0.002)
|
|
47
|
+
|
|
48
|
+
# Probar API unificada read_iq / write_iq
|
|
49
|
+
write_iq(fname, self.test_signal, format='sc16q11')
|
|
50
|
+
loaded_uni, fs = read_iq(fname, format='sc16q11')
|
|
51
|
+
self.assertEqual(fs, 288000)
|
|
52
|
+
np.testing.assert_allclose(loaded_uni, self.test_signal, atol=0.002)
|
|
53
|
+
|
|
54
|
+
def test_sc16full(self):
|
|
55
|
+
fname = "tmp_sc16full.bin"
|
|
56
|
+
self.tmp_files.append(fname)
|
|
57
|
+
save_sc16full(fname, self.test_signal)
|
|
58
|
+
loaded = load_sc16full(fname)
|
|
59
|
+
np.testing.assert_allclose(loaded, self.test_signal, atol=0.0002)
|
|
60
|
+
|
|
61
|
+
def test_grcomplex(self):
|
|
62
|
+
fname = "tmp_grcomplex.iq"
|
|
63
|
+
self.tmp_files.append(fname)
|
|
64
|
+
save_grcomplex(fname, self.test_signal)
|
|
65
|
+
loaded = load_grcomplex(fname)
|
|
66
|
+
np.testing.assert_allclose(loaded, self.test_signal, atol=1e-6)
|
|
67
|
+
|
|
68
|
+
def test_int8(self):
|
|
69
|
+
fname = "tmp_int8.raw"
|
|
70
|
+
self.tmp_files.append(fname)
|
|
71
|
+
save_int8(fname, self.test_signal)
|
|
72
|
+
loaded = load_int8(fname)
|
|
73
|
+
np.testing.assert_allclose(loaded, self.test_signal, atol=0.02)
|
|
74
|
+
|
|
75
|
+
def test_cu8_rtlsdr(self):
|
|
76
|
+
fname = "tmp_cu8.raw"
|
|
77
|
+
self.tmp_files.append(fname)
|
|
78
|
+
save_cu8(fname, self.test_signal)
|
|
79
|
+
loaded = load_cu8(fname)
|
|
80
|
+
np.testing.assert_allclose(loaded, self.test_signal, atol=0.02)
|
|
81
|
+
|
|
82
|
+
# Probar API unificada
|
|
83
|
+
write_iq(fname, self.test_signal, format='cu8')
|
|
84
|
+
loaded_uni, fs = read_iq(fname, format='cu8')
|
|
85
|
+
self.assertEqual(fs, 2048000)
|
|
86
|
+
np.testing.assert_allclose(loaded_uni, self.test_signal, atol=0.02)
|
|
87
|
+
|
|
88
|
+
def test_cs12_packed(self):
|
|
89
|
+
fname = "tmp_cs12.bin"
|
|
90
|
+
self.tmp_files.append(fname)
|
|
91
|
+
save_cs12(fname, self.test_signal)
|
|
92
|
+
loaded = load_cs12(fname)
|
|
93
|
+
np.testing.assert_allclose(loaded, self.test_signal, atol=0.002)
|
|
94
|
+
|
|
95
|
+
# Probar API unificada
|
|
96
|
+
write_iq(fname, self.test_signal, format='cs12')
|
|
97
|
+
loaded_uni, fs = read_iq(fname, format='cs12')
|
|
98
|
+
self.assertEqual(fs, 2000000)
|
|
99
|
+
np.testing.assert_allclose(loaded_uni, self.test_signal, atol=0.002)
|
|
100
|
+
|
|
101
|
+
def test_wav_iq(self):
|
|
102
|
+
fname = "tmp_wav.wav"
|
|
103
|
+
self.tmp_files.append(fname)
|
|
104
|
+
save_wav_iq(fname, self.test_signal, 48000)
|
|
105
|
+
loaded, fs = load_wav_iq(fname)
|
|
106
|
+
self.assertEqual(fs, 48000)
|
|
107
|
+
np.testing.assert_allclose(loaded, self.test_signal, atol=0.0002)
|
|
108
|
+
|
|
109
|
+
def test_csv_iq(self):
|
|
110
|
+
fname = "tmp_csv.csv"
|
|
111
|
+
self.tmp_files.append(fname)
|
|
112
|
+
save_csv_iq(fname, self.test_signal)
|
|
113
|
+
loaded = load_csv_iq(fname)
|
|
114
|
+
np.testing.assert_allclose(loaded, self.test_signal, atol=0.0002)
|
|
115
|
+
|
|
116
|
+
if __name__ == '__main__':
|
|
117
|
+
unittest.main()
|