RTL-SDR IQ sample reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

OCaml 90.6%
Dune 2.5%
Other 6.9%
19 1 0

Clone this repository

https://tangled.org/gazagnaire.org/ocaml-rtlsdr https://tangled.org/did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-rtlsdr
git@git.recoil.org:gazagnaire.org/ocaml-rtlsdr git@git.recoil.org:did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-rtlsdr

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

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 memory
  • read, read_all -- Read complex samples from a source
  • close, sample_count -- Source lifecycle
  • metadata, with_metadata -- Attach/query center frequency, sample rate, gain
  • generate_tone -- Synthetic complex sinusoid
  • generate_bpsk -- Synthetic BPSK-modulated IQ signal

Licence#

ISC License. See LICENSE.md for details.