TinyModem
Header-only software audio modem library
Loading...
Searching...
No Matches
tinymodem::OFDMDecoder Class Reference

OFDM demodulator: the PCM audio data is written to the decoder and the decoded frames are written to the output. The input can be 8, 16 or 32 bit signed samples with any number of channels (only OFDMConfig::channel is evaluated). More...

#include <OFDMDecoder.h>

Inheritance diagram for tinymodem::OFDMDecoder:
Collaboration diagram for tinymodem::OFDMDecoder:

Public Member Functions

 OFDMDecoder ()=default
 OFDMDecoder (Print &out)
OFDMConfig defaultConfig ()
 Provides a default configuration: ofdm32.
void setAudioInfo (audio_tools::AudioInfo info) override
 Defines the format of the input audio data.
audio_tools::AudioInfo audioInfo () override
bool begin (OFDMConfig config)
 Starts the processing with the indicated configuration.
bool begin () override
void end () override
 Processes the remaining samples.
void flush () override
 Processes the remaining samples (e.g. at the end of the input).
size_t write (const uint8_t *data, size_t len) override
 Provide PCM data to the decoder.
bool isCarrier () override
 true while a frame is received
bool isFinished () override
 true if the decoding was stopped (rx_one)
size_t frameCount ()
 Number of received frames.
OFDMConfig & config ()
 The configuration which was provided in begin().
 operator bool () override
Public Member Functions inherited from tinymodem::ModemDecoder
void setStatusOutput (Print &out)
 Defines the output for the ### CARRIER / ### NOCARRIER messages.
void setQuiet (bool quiet)
 Suppresses the status messages.
const char * mime () override

Protected Types

enum class  State { SEARCH , FRAME }

Protected Member Functions

void resetState ()
float noise ()
 uniform random value in the range -0.5 to 0.5
float sample (uint32_t idx)
void addSample (float x, bool add_noise)
void recalculate (uint32_t t)
void compact ()
 Drops the samples which are not needed any more.
void search (uint32_t d)
void dft ()
 DFT of the window at the carrier frequencies.
void processSymbol ()
void referenceSymbol ()
void dataSymbol ()
void checkHeader ()
void dataBits (int dibit)
void endFrame (bool complete)
Protected Member Functions inherited from tinymodem::ModemDecoder
void status (const char *fmt,...)

Static Protected Member Functions

static bool isReached (uint32_t a, uint32_t b)
 true if the global index a is at or after b (with wrap around)
static float wrap (float angle)
static void fit (const float *angle, const float *weight, int n, float &common, float &slope)
 Weighted linear fit: angle = common + slope * carrier.
static int phaseToGray (int phase)
 0 -> 00, 90 -> 01, 180 -> 11, 270 -> 10 degrees

Protected Attributes

OFDMConfig cfg
bool is_active = false
bool is_finished = false
PcmInput input
OFDMTable table
uint32_t noise_seed = 1
size_t frames = 0
int fft_size = 0
int prefix_size = 0
int symbol_size = 0
int half = 0
int first_bin = 0
int ncarriers = 0
audio_tools::Vector< float > buffer
size_t nvalid = 0
uint32_t base = 0
uint32_t now = 0
uint32_t filled = 0
float corr = 0
float power = 0
bool in_plateau = false
uint32_t plateau_start = 0
audio_tools::Vector< float > plateau
audio_tools::Vector< float > smoothed
int plateau_len = 0
State state = State::SEARCH
uint32_t window = 0
int symbol = 0
audio_tools::Vector< float > z_re
audio_tools::Vector< float > z_im
audio_tools::Vector< float > prev_re
audio_tools::Vector< float > prev_im
float pred_common = 0
float pred_slope = 0
float slope_adjust = 0
float drift = 0
float reference_power = 0
float header_soft [32]
int header_symbol = 0
int frame_len = -1
int ndata = 0
uint8_t current = 0
int current_dibits = 0
float error_total = 0
int error_count = 0
Protected Attributes inherited from tinymodem::ModemDecoder
Print * p_status = nullptr
bool is_quiet = false

Static Protected Attributes

static constexpr float TRACKING_GAIN = 0.5f
static constexpr float MIN_POWER = 1e-6f

Detailed Description

OFDM demodulator: the PCM audio data is written to the decoder and the decoded frames are written to the output. The input can be 8, 16 or 32 bit signed samples with any number of channels (only OFDMConfig::channel is evaluated).

The start of a frame is found with the Schmidl & Cox method: the sync symbol consists of two identical halves, which are detected with a sliding autocorrelation. The reference symbol provides the initial phase of all carriers and an estimate of the frequency offset and timing drift, which are tracked during the frame. The carriers are analyzed with a DFT.

Member Enumeration Documentation

◆ State

enum class tinymodem::OFDMDecoder::State
strongprotected
Enumerator
SEARCH 
FRAME 

Constructor & Destructor Documentation

◆ OFDMDecoder() [1/2]

tinymodem::OFDMDecoder::OFDMDecoder ( )
default

◆ OFDMDecoder() [2/2]

tinymodem::OFDMDecoder::OFDMDecoder ( Print & out)
inline

Member Function Documentation

◆ addSample()

void tinymodem::OFDMDecoder::addSample ( float x,
bool add_noise )
inlineprotected

◆ audioInfo()

audio_tools::AudioInfo tinymodem::OFDMDecoder::audioInfo ( )
inlineoverride

◆ begin() [1/2]

bool tinymodem::OFDMDecoder::begin ( )
inlineoverride

◆ begin() [2/2]

bool tinymodem::OFDMDecoder::begin ( OFDMConfig config)
inline

Starts the processing with the indicated configuration.

◆ checkHeader()

void tinymodem::OFDMDecoder::checkHeader ( )
inlineprotected

◆ compact()

void tinymodem::OFDMDecoder::compact ( )
inlineprotected

Drops the samples which are not needed any more.

◆ config()

OFDMConfig & tinymodem::OFDMDecoder::config ( )
inline

The configuration which was provided in begin().

◆ dataBits()

void tinymodem::OFDMDecoder::dataBits ( int dibit)
inlineprotected

◆ dataSymbol()

void tinymodem::OFDMDecoder::dataSymbol ( )
inlineprotected

◆ defaultConfig()

OFDMConfig tinymodem::OFDMDecoder::defaultConfig ( )
inline

Provides a default configuration: ofdm32.

◆ dft()

void tinymodem::OFDMDecoder::dft ( )
inlineprotected

DFT of the window at the carrier frequencies.

◆ end()

void tinymodem::OFDMDecoder::end ( )
inlineoverride

Processes the remaining samples.

◆ endFrame()

void tinymodem::OFDMDecoder::endFrame ( bool complete)
inlineprotected

◆ fit()

void tinymodem::OFDMDecoder::fit ( const float * angle,
const float * weight,
int n,
float & common,
float & slope )
inlinestaticprotected

Weighted linear fit: angle = common + slope * carrier.

◆ flush()

void tinymodem::OFDMDecoder::flush ( )
inlineoverridevirtual

Processes the remaining samples (e.g. at the end of the input).

Implements tinymodem::ModemDecoder.

◆ frameCount()

size_t tinymodem::OFDMDecoder::frameCount ( )
inline

Number of received frames.

◆ isCarrier()

bool tinymodem::OFDMDecoder::isCarrier ( )
inlineoverridevirtual

true while a frame is received

Implements tinymodem::ModemDecoder.

◆ isFinished()

bool tinymodem::OFDMDecoder::isFinished ( )
inlineoverridevirtual

true if the decoding was stopped (rx_one)

Implements tinymodem::ModemDecoder.

◆ isReached()

bool tinymodem::OFDMDecoder::isReached ( uint32_t a,
uint32_t b )
inlinestaticprotected

true if the global index a is at or after b (with wrap around)

◆ noise()

float tinymodem::OFDMDecoder::noise ( )
inlineprotected

uniform random value in the range -0.5 to 0.5

◆ operator bool()

tinymodem::OFDMDecoder::operator bool ( )
inlineoverride

◆ phaseToGray()

int tinymodem::OFDMDecoder::phaseToGray ( int phase)
inlinestaticprotected

0 -> 00, 90 -> 01, 180 -> 11, 270 -> 10 degrees

◆ processSymbol()

void tinymodem::OFDMDecoder::processSymbol ( )
inlineprotected

◆ recalculate()

void tinymodem::OFDMDecoder::recalculate ( uint32_t t)
inlineprotected

◆ referenceSymbol()

void tinymodem::OFDMDecoder::referenceSymbol ( )
inlineprotected

Initial estimate of the frequency offset and the timing drift from the known phases of the even carriers in the sync and reference symbols

◆ resetState()

void tinymodem::OFDMDecoder::resetState ( )
inlineprotected

◆ sample()

float tinymodem::OFDMDecoder::sample ( uint32_t idx)
inlineprotected

◆ search()

void tinymodem::OFDMDecoder::search ( uint32_t d)
inlineprotected

The sync symbol results in a plateau of the normalized correlation (length = cyclic prefix): we use the middle of the plateau

◆ setAudioInfo()

void tinymodem::OFDMDecoder::setAudioInfo ( audio_tools::AudioInfo info)
inlineoverride

Defines the format of the input audio data.

◆ wrap()

float tinymodem::OFDMDecoder::wrap ( float angle)
inlinestaticprotected

◆ write()

size_t tinymodem::OFDMDecoder::write ( const uint8_t * data,
size_t len )
inlineoverride

Provide PCM data to the decoder.

Member Data Documentation

◆ base

uint32_t tinymodem::OFDMDecoder::base = 0
protected

◆ buffer

audio_tools::Vector<float> tinymodem::OFDMDecoder::buffer
protected

◆ cfg

OFDMConfig tinymodem::OFDMDecoder::cfg
protected

◆ corr

float tinymodem::OFDMDecoder::corr = 0
protected

◆ current

uint8_t tinymodem::OFDMDecoder::current = 0
protected

◆ current_dibits

int tinymodem::OFDMDecoder::current_dibits = 0
protected

◆ drift

float tinymodem::OFDMDecoder::drift = 0
protected

◆ error_count

int tinymodem::OFDMDecoder::error_count = 0
protected

◆ error_total

float tinymodem::OFDMDecoder::error_total = 0
protected

◆ fft_size

int tinymodem::OFDMDecoder::fft_size = 0
protected

◆ filled

uint32_t tinymodem::OFDMDecoder::filled = 0
protected

◆ first_bin

int tinymodem::OFDMDecoder::first_bin = 0
protected

◆ frame_len

int tinymodem::OFDMDecoder::frame_len = -1
protected

◆ frames

size_t tinymodem::OFDMDecoder::frames = 0
protected

◆ half

int tinymodem::OFDMDecoder::half = 0
protected

◆ header_soft

float tinymodem::OFDMDecoder::header_soft[32]
protected

◆ header_symbol

int tinymodem::OFDMDecoder::header_symbol = 0
protected

◆ in_plateau

bool tinymodem::OFDMDecoder::in_plateau = false
protected

◆ input

PcmInput tinymodem::OFDMDecoder::input
protected

◆ is_active

bool tinymodem::OFDMDecoder::is_active = false
protected

◆ is_finished

bool tinymodem::OFDMDecoder::is_finished = false
protected

◆ MIN_POWER

float tinymodem::OFDMDecoder::MIN_POWER = 1e-6f
staticconstexprprotected

◆ ncarriers

int tinymodem::OFDMDecoder::ncarriers = 0
protected

◆ ndata

int tinymodem::OFDMDecoder::ndata = 0
protected

◆ noise_seed

uint32_t tinymodem::OFDMDecoder::noise_seed = 1
protected

◆ now

uint32_t tinymodem::OFDMDecoder::now = 0
protected

◆ nvalid

size_t tinymodem::OFDMDecoder::nvalid = 0
protected

◆ plateau

audio_tools::Vector<float> tinymodem::OFDMDecoder::plateau
protected

◆ plateau_len

int tinymodem::OFDMDecoder::plateau_len = 0
protected

◆ plateau_start

uint32_t tinymodem::OFDMDecoder::plateau_start = 0
protected

◆ power

float tinymodem::OFDMDecoder::power = 0
protected

◆ pred_common

float tinymodem::OFDMDecoder::pred_common = 0
protected

◆ pred_slope

float tinymodem::OFDMDecoder::pred_slope = 0
protected

◆ prefix_size

int tinymodem::OFDMDecoder::prefix_size = 0
protected

◆ prev_im

audio_tools::Vector<float> tinymodem::OFDMDecoder::prev_im
protected

◆ prev_re

audio_tools::Vector<float> tinymodem::OFDMDecoder::prev_re
protected

◆ reference_power

float tinymodem::OFDMDecoder::reference_power = 0
protected

◆ slope_adjust

float tinymodem::OFDMDecoder::slope_adjust = 0
protected

◆ smoothed

audio_tools::Vector<float> tinymodem::OFDMDecoder::smoothed
protected

◆ state

State tinymodem::OFDMDecoder::state = State::SEARCH
protected

◆ symbol

int tinymodem::OFDMDecoder::symbol = 0
protected

◆ symbol_size

int tinymodem::OFDMDecoder::symbol_size = 0
protected

◆ table

OFDMTable tinymodem::OFDMDecoder::table
protected

◆ TRACKING_GAIN

float tinymodem::OFDMDecoder::TRACKING_GAIN = 0.5f
staticconstexprprotected

◆ window

uint32_t tinymodem::OFDMDecoder::window = 0
protected

◆ z_im

audio_tools::Vector<float> tinymodem::OFDMDecoder::z_im
protected

◆ z_re

audio_tools::Vector<float> tinymodem::OFDMDecoder::z_re
protected

The documentation for this class was generated from the following file: