Skip to main content

Module io

Module io 

Source
Expand description

Reading and writing sampled signals: measured captures and reference sequences.

Three formats cover the usual outputs of oscilloscopes, software-defined radios and numerical tools:

  • SigMF (the Signal Metadata Format of GNU Radio and the SDR community): a JSON file name.sigmf-meta with the data type and the sampling rate, next to the raw samples name.sigmf-data; read_sigmf, write_sigmf;
  • raw interleaved samples with a SigMF data type (cf32_le is the .cfile of GNU Radio, ci16_le the IQ format of most SDRs and many oscilloscopes); read_raw, write_raw;
  • NPY arrays of NumPy (complex, real or integer, one dimension); read_npy, write_npy, write_npy_i64.

read_samples picks the format from the extension. Integer samples are converted to floating point without scaling (the receivers normalise the power).

§Examples

use comnum_spec::io::{read_sigmf, write_sigmf, Datatype};
use comnum_math::C64;
let dir = std::env::temp_dir().join("comnum-doc-io");
let x: Vec<C64> = (0..8).map(|k| C64::new(k as f64, -(k as f64))).collect();
write_sigmf(dir.join("capture"), &x, Datatype::CI16, 64e9, None).unwrap();
let c = read_sigmf(dir.join("capture.sigmf-meta")).unwrap();
assert_eq!(c.samples, x);
assert_eq!((c.sample_rate, c.datatype), (Some(64e9), Datatype::CI16));

Structs§

Annotation
An annotation of a SigMF recording.
Capture
A capture segment of a SigMF recording.
Datatype
A sample format of SigMF: [c|r][f32|f64|i32|i16|i8|u32|u16|u8][_le|_be] (the 8-bit types without endianness).
Npy
An NPY array: its shape and its data in C order.
Samples
The samples of one channel of a recording (read_samples).
SigMF
A SigMF recording.

Enums§

NpyData
The content of an NPY file.
Scalar
The scalar type of the components of a SigMF sample.

Functions§

read_npy
Read an NPY array (little-endian numbers or booleans, C order or one dimension).
read_raw
Read raw interleaved samples.
read_samples
Read samples from a SigMF recording (.sigmf-meta, .sigmf-data, .sigmf), an NPY array (.npy) or a raw file of the given data type: the samples of channel and the sampling rate when the file records it.
read_sigmf
Read a SigMF recording from its .sigmf-meta or .sigmf-data file, their common base name, or a .sigmf archive (the first recording of the archive).
write_npy
Write a one-dimensional complex NPY array (<c16).
write_npy_i64
Write a one-dimensional integer NPY array (<i8), e.g. symbol indices.
write_raw
Write raw interleaved samples (integer types are rounded and saturated).
write_sigmf
Write a SigMF recording base.sigmf-meta and base.sigmf-data.
write_sigmf_annotated
Write a SigMF recording with the centre frequency of its capture (core:frequency) and annotations (see write_sigmf).