Variable bitrate experiment

This commit is contained in:
Mark Qvist 2015-04-24 10:47:50 +02:00
parent 095a558fcb
commit 8d9da446a4
2 changed files with 44 additions and 7 deletions

View File

@ -331,11 +331,32 @@ void AFSK_adc_isr(Afsk *afsk, int8_t currentSample) {
// to "smooth out" the variations in the samples.
afsk->iirX[0] = afsk->iirX[1];
afsk->iirX[1] = ((int8_t)fifo_pop(&afsk->delayFifo) * currentSample) >> 2;
#if FILTER_CUTOFF == 600
afsk->iirX[1] = ((int8_t)fifo_pop(&afsk->delayFifo) * currentSample) >> 2;
// The above is a simplification of:
// afsk->iirX[1] = ((int8_t)fifo_pop(&afsk->delayFifo) * currentSample) / 3.558147322;
#elif FILTER_CUTOFF == 800
afsk->iirX[1] = ((int8_t)fifo_pop(&afsk->delayFifo) * currentSample) >> 2;
// The above is a simplification of:
// afsk->iirX[1] = ((int8_t)fifo_pop(&afsk->delayFifo) * currentSample) / 2.899043379;
#else
#error Unsupported bitrate!
#endif
afsk->iirY[0] = afsk->iirY[1];
afsk->iirY[1] = afsk->iirX[0] + afsk->iirX[1] + (afsk->iirY[0] >> 1); // Chebyshev filter
#if FILTER_CUTOFF == 600
afsk->iirY[1] = afsk->iirX[0] + afsk->iirX[1] + (afsk->iirY[0] >> 1);
// The above is a simplification of a first-order 600Hz chebyshev filter:
// afsk->iirY[1] = afsk->iirX[0] + afsk->iirX[1] + (afsk->iirY[0] * 0.4379097269);
#elif FILTER_CUTOFF == 800
afsk->iirY[1] = afsk->iirX[0] + afsk->iirX[1] + (afsk->iirY[0] / 3);
// The above is a simplification of a first-order 800Hz chebyshev filter:
// afsk->iirY[1] = afsk->iirX[0] + afsk->iirX[1] + (afsk->iirY[0] * 0.3101172565);
#else
#error Unsupported bitrate!
#endif
// We put the sampled bit in a delay-line:

View File

@ -45,17 +45,33 @@ inline static uint8_t sinSample(uint16_t i) {
#define CONFIG_AFSK_PREAMBLE_LEN 150UL
#define CONFIG_AFSK_TRAILER_LEN 50UL
#define SAMPLERATE 9600
#define BITRATE 1200
#define BITRATE 1600
#if BITRATE == 960
#define FILTER_CUTOFF 600
#define MARK_FREQ 1300
#define SPACE_FREQ 2100
#define PHASE_BITS 8 // How much to increment phase counter each sample
#if BITRATE == 1200
#define FILTER_CUTOFF 600
#define MARK_FREQ 1200
#define SPACE_FREQ 2200
#define PHASE_BITS 8
#elif BITRATE == 1600
#define FILTER_CUTOFF 800
#define MARK_FREQ 1600
#define SPACE_FREQ 2800
#define PHASE_BITS 6
#else
#error Unsupported bitrate!
#endif
#define SAMPLESPERBIT (SAMPLERATE / BITRATE)
#define BIT_STUFF_LEN 5
#define MARK_FREQ 1200
#define SPACE_FREQ 2200
#define PHASE_BITS 8 // How much to increment phase counter each sample
#define PHASE_INC 1 // Nudge by an eigth of a sample each adjustment
#define PHASE_MAX (SAMPLESPERBIT * PHASE_BITS) // Resolution of our phase counter = 64
#define PHASE_THRESHOLD (PHASE_MAX / 2) // Target transition point of our phase window
typedef struct Hdlc
{
uint8_t demodulatedBits;