dorkhub

zigradio

A lightweight software-defined radio framework built with Zig

vsergeev
Zig541 forksMITupdated 1 week ago
visit the demogit clone https://github.com/vsergeev/zigradio.gitvsergeev/zigradio

ZigRadio Tests Status GitHub release License

ZigRadio is a lightweight flow graph signal processing framework for software-defined radio. It provides a suite of source, sink, and processing blocks, with a simple API for defining flow graphs, running flow graphs, and creating blocks. ZigRadio has an API similar to that of LuaRadio and is also MIT licensed.

ZigRadio can be used to rapidly prototype software radios, modulation/demodulation utilities, and signal processing experiments.

Example

Wideband FM Broadcast Radio Receiver
const std = @import("std");

const radio = @import("radio");

pub fn main(init: std.process.Init) !void {
    const frequency: f64 = 91.1e6; // 91.1 MHz

    var source = radio.blocks.RtlSdrSource.init(frequency - 250e3, 960000, .{});
    var if_translator = radio.blocks.FrequencyTranslatorBlock.init(-250e3);
    var if_filter = radio.blocks.LowpassFilterBlock(std.math.Complex(f32), 64).init(200e3, .{});
    var if_downsampler = radio.blocks.DownsamplerBlock(std.math.Complex(f32)).init(4);
    var fm_demod = radio.blocks.FrequencyDiscriminatorBlock.init(75e3);
    var af_filter = radio.blocks.LowpassFilterBlock(f32, 128).init(15e3, .{});
    var af_deemphasis = radio.blocks.FMDeemphasisFilterBlock.init(75e-6);
    var af_downsampler = radio.blocks.DownsamplerBlock(f32).init(5);
    var sink = radio.blocks.PulseAudioSink(1).init();

    var top = radio.Flowgraph.init(init.gpa, init.io, .{ .debug = true });
    defer top.deinit();
    try top.connect(&source.block, &if_translator.block);
    try top.connect(&if_translator.block, &if_filter.block);
    try top.connect(&if_filter.block, &if_downsampler.block);
    try top.connect(&if_downsampler.block, &fm_demod.block);
    try top.connect(&fm_demod.block, &af_filter.block);
    try top.connect(&af_filter.block, &af_deemphasis.block);
    try top.connect(&af_deemphasis.block, &af_downsampler.block);
    try top.connect(&af_downsampler.block, &sink.block);

    try top.start();
    radio.platform.waitForInterrupt();
    _ = try top.stop();
}

Check out some more examples of what you can build with ZigRadio.

Quickstart

ZigRadio requires Zig version 0.16.

$ git clone https://github.com/vsergeev/zigradio.git
$ cd zigradio

Build examples:

$ zig build examples

Try out one of the examples with an RTL-SDR dongle:

$ ./zig-out/bin/example-rtlsdr_wbfm_mono 89.7e6

Building

Fetch the ZigRadio package:

zig fetch --save git+https://github.com/vsergeev/zigradio#master

Add ZigRadio as a dependency to your build.zig:

const radio = b.dependency("radio", .{});
...
exe.root_module.addImport("radio", radio.module("radio"));
exe.linkLibC();

Optimization ReleaseFast is recommended for real-time applications. libc is required for loading dynamic libraries used for acceleration and I/O.

Project Structure

Testing

Run unit tests with:

$ zig build test

Test vectors are generated with Python 3 and NumPy/SciPy:

$ zig build generate

Benchmarking

Run the benchmark suite with:

$ zig build benchmark

License

ZigRadio is MIT licensed. See the included LICENSE file.

more like this

op25

mirror of https://gitea.osmocom.org/op25/op25

Python52

search

search projects, people, and tags