Skip to content

Commit

Permalink
Merge pull request #215 from luarvique/master
Browse files Browse the repository at this point in the history
Fixed subsampling in AFSK12, CLIPFSK, EAS, FMSFSK, UFSK12 decoders
  • Loading branch information
EliasOenal authored May 30, 2024
2 parents be6c092 + 835ac32 commit 84b7072
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 50 deletions.
15 changes: 8 additions & 7 deletions demod_afsk12.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*
* Copyright (C) 1996
* Thomas Sailer ([email protected], [email protected])
* Copyright (C) 2024
* Marat Fayzullin ([email protected])
*
* 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
Expand Down Expand Up @@ -79,16 +81,15 @@ static void afsk12_demod(struct demod_state *s, buffer_t buffer, int length)
unsigned char curbit;

if (s->l1.afsk12.subsamp) {
int numfill = SUBSAMP - s->l1.afsk12.subsamp;
if (length < numfill) {
s->l1.afsk12.subsamp += length;
if (length <= (int)s->l1.afsk12.subsamp) {
s->l1.afsk12.subsamp -= length;
return;
}
buffer.fbuffer += numfill;
length -= numfill;
buffer.fbuffer += s->l1.afsk12.subsamp;
length -= s->l1.afsk12.subsamp;
s->l1.afsk12.subsamp = 0;
}
for (; length >= SUBSAMP; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) {
for (; length > 0; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) {
f = fsqr(mac(buffer.fbuffer, corr_mark_i, CORRLEN)) +
fsqr(mac(buffer.fbuffer, corr_mark_q, CORRLEN)) -
fsqr(mac(buffer.fbuffer, corr_space_i, CORRLEN)) -
Expand Down Expand Up @@ -116,7 +117,7 @@ static void afsk12_demod(struct demod_state *s, buffer_t buffer, int length)
hdlc_rxbit(s, curbit);
}
}
s->l1.afsk12.subsamp = length;
s->l1.afsk12.subsamp = -length;
}

/* ---------------------------------------------------------------------- */
Expand Down
15 changes: 7 additions & 8 deletions demod_clipfsk.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* demod_clipfsk.c -- 1200 baud FSK demodulator
*
* Copyright (C) 2007
* Copyright (C) 2007, 2024
*
* 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
Expand Down Expand Up @@ -78,16 +78,15 @@ static void clipfsk_demod(struct demod_state *s, buffer_t buffer, int length)
unsigned char curbit;

if (s->l1.clipfsk.subsamp) {
int numfill = SUBSAMP - s->l1.clipfsk.subsamp;
if (length < numfill) {
s->l1.clipfsk.subsamp += length;
if (length <= (int)s->l1.clipfsk.subsamp) {
s->l1.clipfsk.subsamp -= length;
return;
}
buffer.fbuffer += numfill;
length -= numfill;
buffer.fbuffer += s->l1.clipfsk.subsamp;
length -= s->l1.clipfsk.subsamp;
s->l1.clipfsk.subsamp = 0;
}
for (; length >= SUBSAMP; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) {
for (; length > 0; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) {
f = fsqr(mac(buffer.fbuffer, corr_mark_i, CORRLEN)) +
fsqr(mac(buffer.fbuffer, corr_mark_q, CORRLEN)) -
fsqr(mac(buffer.fbuffer, corr_space_i, CORRLEN)) -
Expand All @@ -112,7 +111,7 @@ static void clipfsk_demod(struct demod_state *s, buffer_t buffer, int length)
clip_rxbit(s, curbit);
}
}
s->l1.clipfsk.subsamp = length;
s->l1.clipfsk.subsamp = -length;
}

/* ---------------------------------------------------------------------- */
Expand Down
36 changes: 17 additions & 19 deletions demod_eas.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*
* Copyright (C) 2000
* A. Maitland Bottoms <[email protected]>
* Copyright (C) 2024
* Marat Fayzullin <[email protected]>
*
* Licensed under same terms and based upon the
* demod_afsk12.c -- 1200 baud AFSK demodulator
Expand Down Expand Up @@ -253,20 +255,19 @@ static void eas_demod(struct demod_state *s, buffer_t buffer, int length)
float f;
unsigned char curbit;
float dll_gain;

if (s->l1.eas.subsamp) {
int numfill = SUBSAMP - s->l1.eas.subsamp;
if (length < numfill) {
s->l1.eas.subsamp += length;
if (length <= (int)s->l1.eas.subsamp) {
s->l1.eas.subsamp -= length;
return;
}
buffer.fbuffer += numfill;
length -= numfill;
buffer.fbuffer += s->l1.eas.subsamp;
length -= s->l1.eas.subsamp;
s->l1.eas.subsamp = 0;
}
// We use a sliding window correlator which advances by SUBSAMP
// each time. One correlator sample is output for each SUBSAMP symbols
for (; length >= SUBSAMP; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) {
for (; length > 0; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) {
f = fsqr(mac(buffer.fbuffer, eascorr_mark_i, CORRLEN)) +
fsqr(mac(buffer.fbuffer, eascorr_mark_q, CORRLEN)) -
fsqr(mac(buffer.fbuffer, eascorr_space_i, CORRLEN)) -
Expand All @@ -286,14 +287,13 @@ static void eas_demod(struct demod_state *s, buffer_t buffer, int length)
{
s->l1.eas.dcd_integrator -= 1;
}

verbprintf(9, "%c", '0'+(s->l1.afsk12.dcd_shreg & 1));



/*
* check if transition occurred on time
*/

if (s->l2.eas.state != EAS_L2_IDLE)
dll_gain = DLL_GAIN_SYNC;
else
Expand All @@ -313,7 +313,6 @@ static void eas_demod(struct demod_state *s, buffer_t buffer, int length)
else
{
// after center; check for increment

if (s->l1.eas.sphase < (0x10000u - SPHASEINC/2))
{
s->l1.eas.sphase += MIN((int)((0x10000u - s->l1.eas.sphase)*
Expand All @@ -325,20 +324,20 @@ static void eas_demod(struct demod_state *s, buffer_t buffer, int length)
}

s->l1.eas.sphase += SPHASEINC;

if (s->l1.eas.sphase >= 0x10000u) {
// end of bit period.
s->l1.eas.sphase = 1; //was &= 0xffffu;
s->l1.eas.lasts >>= 1;

// if at least half of the values in the integrator are 1,
// declare a 1 received
s->l1.afsk12.lasts |= ((s->l1.eas.dcd_integrator >= 0) << 7) & 0x80u;

curbit = (s->l1.eas.lasts >> 7) & 0x1u;
verbprintf(9, " ");
verbprintf(7, "%c", '0'+curbit);

// check for sync sequence
// do not resync when we're reading a message!
if (s->l1.eas.lasts == PREAMBLE
Expand Down Expand Up @@ -369,12 +368,11 @@ static void eas_demod(struct demod_state *s, buffer_t buffer, int length)
s->l1.eas.byte_counter = 0;
}
}



verbprintf(9, "\n");
}
}
s->l1.eas.subsamp = length;
s->l1.eas.subsamp = -length;
}

/* ---------------------------------------------------------------------- */
Expand Down
15 changes: 7 additions & 8 deletions demod_fmsfsk.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* demod_fmsfsk.c -- 1200 baud FMS FSK demodulator
*
* Copyright (C) 2014
* Copyright (C) 2014, 2024
*
* 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
Expand Down Expand Up @@ -78,16 +78,15 @@ static void fmsfsk_demod(struct demod_state *s, buffer_t buffer, int length)
unsigned char curbit;

if (s->l1.fmsfsk.subsamp) {
int numfill = SUBSAMP - s->l1.fmsfsk.subsamp;
if (length < numfill) {
s->l1.fmsfsk.subsamp += length;
if (length <= (int)s->l1.fmsfsk.subsamp) {
s->l1.fmsfsk.subsamp -= length;
return;
}
buffer.fbuffer += numfill;
length -= numfill;
buffer.fbuffer += s->l1.fmsfsk.subsamp;
length -= s->l1.fmsfsk.subsamp;
s->l1.fmsfsk.subsamp = 0;
}
for (; length >= SUBSAMP; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) {
for (; length > 0; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) {
f = fsqr(mac(buffer.fbuffer, corr_1_i, CORRLEN)) +
fsqr(mac(buffer.fbuffer, corr_1_q, CORRLEN)) -
fsqr(mac(buffer.fbuffer, corr_0_i, CORRLEN)) -
Expand All @@ -112,7 +111,7 @@ static void fmsfsk_demod(struct demod_state *s, buffer_t buffer, int length)
fms_rxbit(s, curbit);
}
}
s->l1.fmsfsk.subsamp = length;
s->l1.fmsfsk.subsamp = -length;
}

/* ---------------------------------------------------------------------- */
Expand Down
15 changes: 7 additions & 8 deletions demod_ufsk12.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* demod_ufsk12.c -- 1200 baud FSK demodulator
*
* Copyright (C) 2007
* Copyright (C) 2007, 2024
*
* 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
Expand Down Expand Up @@ -78,16 +78,15 @@ static void ufsk12_demod(struct demod_state *s, buffer_t buffer, int length)
unsigned char curbit;

if (s->l1.ufsk12.subsamp) {
int numfill = SUBSAMP - s->l1.ufsk12.subsamp;
if (length < numfill) {
s->l1.ufsk12.subsamp += length;
if (length <= (int)s->l1.ufsk12.subsamp) {
s->l1.ufsk12.subsamp -= length;
return;
}
buffer.fbuffer += numfill;
length -= numfill;
buffer.fbuffer += s->l1.ufsk12.subsamp;
length -= s->l1.ufsk12.subsamp;
s->l1.ufsk12.subsamp = 0;
}
for (; length >= SUBSAMP; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) {
for (; length > 0; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) {
f = fsqr(mac(buffer.fbuffer, corr_mark_i, CORRLEN)) +
fsqr(mac(buffer.fbuffer, corr_mark_q, CORRLEN)) -
fsqr(mac(buffer.fbuffer, corr_space_i, CORRLEN)) -
Expand All @@ -112,7 +111,7 @@ static void ufsk12_demod(struct demod_state *s, buffer_t buffer, int length)
uart_rxbit(s, curbit);
}
}
s->l1.ufsk12.subsamp = length;
s->l1.ufsk12.subsamp = -length;
}

/* ---------------------------------------------------------------------- */
Expand Down

0 comments on commit 84b7072

Please sign in to comment.