rtl433  UNKNOWN
RTL-433 utility
baseband.c File Reference

Various functions for baseband sample processing. More...

Functions

static void calc_squares ()
 precalculate lookup table for envelope detection. More...
 
void envelope_detect (uint8_t const *iq_buf, uint16_t *y_buf, uint32_t len)
 This will give a noisy envelope of OOK/ASK signals. More...
 
void envelope_detect_nolut (uint8_t const *iq_buf, uint16_t *y_buf, uint32_t len)
 This will give a noisy envelope of OOK/ASK signals. More...
 
void magnitude_est_cu8 (uint8_t const *iq_buf, uint16_t *y_buf, uint32_t len)
 122/128, 51/128 Magnitude Estimator for CU8 (SIMD has min/max). More...
 
void magnitude_true_cu8 (uint8_t const *iq_buf, uint16_t *y_buf, uint32_t len)
 True Magnitude for CU8 (sqrt can SIMD but float is slow). More...
 
void magnitude_est_cs16 (int16_t const *iq_buf, uint16_t *y_buf, uint32_t len)
 122/128, 51/128 Magnitude Estimator for CS16 (SIMD has min/max). More...
 
void magnitude_true_cs16 (int16_t const *iq_buf, uint16_t *y_buf, uint32_t len)
 True Magnitude for CS16 (sqrt can SIMD but float is slow). More...
 
void baseband_low_pass_filter (uint16_t const *x_buf, int16_t *y_buf, uint32_t len, filter_state_t *state)
 Something that might look like a IIR lowpass filter. More...
 
int16_t atan2_int16 (int16_t y, int16_t x)
 Integer implementation of atan2() with int16_t normalized output. More...
 
void baseband_demod_FM (uint8_t const *x_buf, int16_t *y_buf, unsigned long num_samples, demodfm_state_t *state)
 FM demodulator. More...
 
int32_t atan2_int32 (int32_t y, int32_t x)
 for evaluation. More...
 
void baseband_demod_FM_cs16 (int16_t const *x_buf, int16_t *y_buf, unsigned long num_samples, demodfm_state_t *state)
 for evaluation. More...
 
void baseband_init (void)
 Initialize tables and constants. More...
 

Variables

static uint16_t scaled_squares [256]
 

Detailed Description

Various functions for baseband sample processing.

Copyright (C) 2012 by Benjamin Larsson benja.nosp@m.min@.nosp@m.south.nosp@m.pole.nosp@m..se Copyright (C) 2015 Tommy Vestermark

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

Function Documentation

◆ atan2_int16()

int16_t atan2_int16 ( int16_t  y,
int16_t  x 
)

Integer implementation of atan2() with int16_t normalized output.

Returns arc tangent of y/x across all quadrants in radians. Error max 0.07 radians. Reference: http://dspguru.com/dsp/tricks/fixed-point-atan2-with-self-normalization

Parameters
yNumerator (imaginary value of complex vector)
xDenominator (real value of complex vector)
Returns
angle in radians (Pi equals INT16_MAX)

Referenced by baseband_demod_FM().

◆ atan2_int32()

int32_t atan2_int32 ( int32_t  y,
int32_t  x 
)

for evaluation.

Referenced by baseband_demod_FM_cs16().

◆ baseband_demod_FM()

void baseband_demod_FM ( uint8_t const *  x_buf,
int16_t y_buf,
unsigned long  num_samples,
demodfm_state_t state 
)

FM demodulator.

Function is stateful

Parameters
x_bufinput samples (I/Q samples in interleaved uint8)
[out]y_bufoutput from FM demodulator
lennumber of samples to process
[in,out]stateState to store between chunk processing

[b,a] = butter(1, 0.1) -> 3x tau (95%) ~10 samples

[b,a] = butter(1, 0.2) -> 3x tau (95%) ~5 samples

References atan2_int16(), demodfm_state::bi, demodfm_state::br, demodfm_state::xlp, and demodfm_state::ylp.

Referenced by sdr_callback().

◆ baseband_demod_FM_cs16()

void baseband_demod_FM_cs16 ( int16_t const *  x_buf,
int16_t y_buf,
unsigned long  num_samples,
demodfm_state_t state 
)

for evaluation.

For evaluation.

[b,a] = butter(1, 0.1) -> 3x tau (95%) ~10 samples

[b,a] = butter(1, 0.2) -> 3x tau (95%) ~5 samples

References atan2_int32(), demodfm_state::bi, demodfm_state::br, demodfm_state::xlp, and demodfm_state::ylp.

Referenced by sdr_callback().

◆ baseband_init()

void baseband_init ( void  )

Initialize tables and constants.

Should be called once at startup.

References calc_squares().

Referenced by main().

◆ baseband_low_pass_filter()

void baseband_low_pass_filter ( uint16_t const *  x_buf,
int16_t y_buf,
uint32_t  len,
filter_state_t state 
)

Something that might look like a IIR lowpass filter.

Lowpass filter.

[b,a] = butter(1, Wc) # low pass filter with cutoff pi*Wc radians Q1.15*Q15.0 = Q16.15 Q16.15>>1 = Q15.14 Q15.14 + Q15.14 + Q15.14 could possibly overflow to 17.14 but the b coeffs are small so it wont happen Q15.14>>14 = Q15.0 /

[b,a] = butter(1, 0.01) -> 3x tau (95%) ~100 samples

[b,a] = butter(1, 0.05) -> 3x tau (95%) ~20 samples

References filter_state::x, and filter_state::y.

Referenced by sdr_callback().

◆ calc_squares()

static void calc_squares ( )
static

precalculate lookup table for envelope detection.

References scaled_squares.

Referenced by baseband_init().

◆ envelope_detect()

void envelope_detect ( uint8_t const *  iq_buf,
uint16_t y_buf,
uint32_t  len 
)

This will give a noisy envelope of OOK/ASK signals.

Subtract the bias (-128) and get an envelope estimation The output will be written in the input buffer

Returns
pointer to the input buffer

References scaled_squares.

Referenced by sdr_callback().

◆ envelope_detect_nolut()

void envelope_detect_nolut ( uint8_t const *  iq_buf,
uint16_t y_buf,
uint32_t  len 
)

This will give a noisy envelope of OOK/ASK signals.

Subtracts the bias (-128) and calculates the norm (scaled by 16384). Using a LUT is slower for O1 and above.

◆ magnitude_est_cs16()

void magnitude_est_cs16 ( int16_t const *  iq_buf,
uint16_t y_buf,
uint32_t  len 
)

122/128, 51/128 Magnitude Estimator for CS16 (SIMD has min/max).

Referenced by sdr_callback().

◆ magnitude_est_cu8()

void magnitude_est_cu8 ( uint8_t const *  iq_buf,
uint16_t y_buf,
uint32_t  len 
)

122/128, 51/128 Magnitude Estimator for CU8 (SIMD has min/max).

Note that magnitude emphasizes quiet signals / deemphasizes loud signals.

◆ magnitude_true_cs16()

void magnitude_true_cs16 ( int16_t const *  iq_buf,
uint16_t y_buf,
uint32_t  len 
)

True Magnitude for CS16 (sqrt can SIMD but float is slow).

◆ magnitude_true_cu8()

void magnitude_true_cu8 ( uint8_t const *  iq_buf,
uint16_t y_buf,
uint32_t  len 
)

True Magnitude for CU8 (sqrt can SIMD but float is slow).

Variable Documentation

◆ scaled_squares

uint16_t scaled_squares[256]
static

Referenced by calc_squares(), and envelope_detect().