fm

package module
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2023 License: MIT Imports: 8 Imported by: 0

README

hz.tools/fm - fm modulator and demodulator

⚠ Please read Expectations within this Organization before using it.

Go Reference Go Report Card

Documentation

Overview

Package fm contains a modulator and demodulator for FM encoded audio streams.

Index

Constants

This section is empty.

Variables

View Source
var (
	// BroadcastDeviation is the max deviation for FM Broadcast
	// which is 75 KHz (150 KHz bandwidth).
	BroadcastDeviation rf.Hz = rf.KHz * 75

	// NarrowbandDeviation is the max deviation for FM narrowband radio, like
	// Ham radios, 2.5 KHz (5 KHz bandwidth)
	NarrowbandDeviation rf.Hz = rf.KHz * 2.5
)

Functions

func EstimateBeta

func EstimateBeta(desiredBandwidth rf.Hz, audioFrequency float64) float64

EstimateBeta will

Types

type Demodulator

type Demodulator struct {
	// contains filtered or unexported fields
}

Demodulator contains info about

func Demodulate

func Demodulate(reader sdr.Reader, cfg DemodulatorConfig) (*Demodulator, error)

Demodulate will create a new Demodulator, to read FM audio from an IQ stream.

func (Demodulator) Read

func (d Demodulator) Read(audio []float32) (int, error)

Read will (partially?) fill the buffer with audio samples.

func (Demodulator) Reader

func (d Demodulator) Reader() sdr.Reader

Reader will return the underlying reader (TODO: Remove this)

func (Demodulator) SampleRate

func (d Demodulator) SampleRate() uint

SampleRate will return the *audio* sample rate.

type DemodulatorConfig

type DemodulatorConfig struct {
	// Center frequency of the signal in the IQ data.
	CenterFrequency rf.Hz

	// Deviation is the maximum difference between modulated and carrier
	// frequencies. This is half of the total bandwidth.
	Deviation rf.Hz

	// Downsample will define rate to downsample the samples to bring it to
	// a sensible audio sample rate.
	Downsample uint

	// Planner will be used to perform the FFTs used to filter the FM signal.
	Planner fft.Planner
}

DemodulatorConfig will define how the demodulator should decode audio from the iq data.

type Modulator

type Modulator struct {
	// Config
	Config ModulatorConfig
	// contains filtered or unexported fields
}

Modulator is

func NewModulator

func NewModulator(cfg ModulatorConfig) (*Modulator, error)

NewModulator allocates

func (*Modulator) SampleRate

func (m *Modulator) SampleRate() uint

SampleRate implements the sdr.Writer interface.

func (*Modulator) Write

func (m *Modulator) Write(audioSamples []float32) (int, error)

Write accepts audio data as a set of audio samples as the provided Sample Rate, modulate them against the Carrier using Frequency Modulation, and write the IQ data to the resulting sdr.Writer

type ModulatorConfig

type ModulatorConfig struct {
	// AudioSampleRate is the number of audio samples per second.
	AudioSampleRate uint

	// IqBufferLength is the amount of data to allocate to process incoming
	// Audio data.
	IqBufferLength uint

	// IqSamplesPerAudioSample controls how many Iq samples need to be generated
	// for each Audio sample that comes in.
	//
	// If the input AudioSampleRate is 44,100, and the IqSamplesPerAudioSample is
	// 10, the output SampleRate of the sdr.Reader will be 441,000.
	IqSamplesPerAudioSample uint

	// CarrierFrequency controls the frequency of the carrier that will be
	// modulated by incoming data.
	CarrierFrequency rf.Hz

	// Beta controls the deviation from the carrier based on the modulating
	// frequency.
	//
	// This value can get weird. If you want to estimate one, pick some values,
	// plug it into EstimateBeta, and go with it.
	Beta float64

	// Dest is where to send IQ samples to as audio data is written to the
	// Modulator.
	Dest sdr.Writer
}

ModulatorConfig is

type Reader

type Reader interface {
	Read([]float32) (int, error)
}

Reader will allow for the reading of FM demodulated audio samples from an IQ stream.

Directories

Path Synopsis
Package internal contains package local helpers.
Package internal contains package local helpers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL