rtlsdr#
RTL-SDR IQ sample reader for OCaml.
Overview#
Reads interleaved unsigned 8-bit IQ samples from files produced by rtl_sdr
and similar tools, converting them to complex float pairs suitable for
processing with the dsp and demod packages. Also provides synthetic
signal generation for testing demodulation pipelines without hardware.
Installation#
Install with opam:
$ opam install rtlsdr
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install rtlsdr
Usage#
(* Read IQ samples from a raw capture file. *)
let read_capture path =
let src = Rtlsdr.of_file path in
Fmt.pr "%d samples available@." (Rtlsdr.sample_count src);
let samples = Rtlsdr.read src 4096 in
Rtlsdr.close src;
samples
(* Attach recording metadata. *)
let with_meta path =
Rtlsdr.of_file path
|> Rtlsdr.with_metadata
{ center_freq = 137.5e6; sample_rate = 2.4e6; gain = 40.0 }
(* Generate a synthetic BPSK signal for testing. *)
let bits = Bytes.of_string "\x01\x00\x01\x01\x00"
let iq =
Rtlsdr.generate_bpsk ~sample_rate:48000.0 ~symbol_rate:1200.0 ~bits
~carrier_freq:1800.0
API Overview#
of_file,of_bytes-- Create an IQ source from file or memoryread,read_all-- Read complex samples from a sourceclose,sample_count-- Source lifecyclemetadata,with_metadata-- Attach/query center frequency, sample rate, gaingenerate_tone-- Synthetic complex sinusoidgenerate_bpsk-- Synthetic BPSK-modulated IQ signal
Licence#
ISC License. See LICENSE.md for details.