Skip to content

Commit ef5bf76

Browse files
committed
Fix interleaver lengths.
1 parent 48dbff4 commit ef5bf76

File tree

4 files changed

+99
-24
lines changed

4 files changed

+99
-24
lines changed

src/H_128_384_23.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#define H_128_384_23_MAX_COL_WEIGHT 5
1515
#define H_128_384_23_DEC_TYPE 0
1616
#define H_128_384_23_MAX_ITER 100
17-
#define H_128_384_23_COPRIME 347
17+
#define H_128_384_23_COPRIME 383
1818

1919
extern const uint16_t H_128_384_23_H_rows[];
2020
extern const uint16_t H_128_384_23_H_cols[];

src/H_256_768_22.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#define H_256_768_22_MAX_COL_WEIGHT 4
1515
#define H_256_768_22_DEC_TYPE 0
1616
#define H_256_768_22_MAX_ITER 100
17-
#define H_256_768_22_COPRIME 347
17+
#define H_256_768_22_COPRIME 761
1818

1919
extern const uint16_t H_256_768_22_H_rows[];
2020
extern const uint16_t H_256_768_22_H_cols[];

src/horus_api.c

+81-4
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,8 @@ struct horus *horus_open_advanced (int mode, int Rs, int tx_tone_spacing) {
170170
}
171171

172172
if (mode == HORUS_MODE_BINARY_V2_256BIT) {
173-
// Parameter setup for the Legacy Horus Binary Mode (22 byte frames, Golay encoding)
174173

175-
hstates->mFSK = 4;
174+
hstates->mFSK = 2;
176175
hstates->max_packet_len = HORUS_BINARY_V2_256BIT_NUM_CODED_BITS ;
177176

178177
// If baud rate not provided, use default
@@ -200,9 +199,9 @@ struct horus *horus_open_advanced (int mode, int Rs, int tx_tone_spacing) {
200199
}
201200

202201
if (mode == HORUS_MODE_BINARY_V2_128BIT) {
203-
// Parameter setup for the Legacy Horus Binary Mode (22 byte frames, Golay encoding)
202+
// Parameter setup for the New v2 Horus Binary mode.
204203

205-
hstates->mFSK = 4;
204+
hstates->mFSK = 2; // Lock to 2FSK until we have decent LLRs for 4FSK.
206205
hstates->max_packet_len = HORUS_BINARY_V2_128BIT_NUM_CODED_BITS ;
207206

208207
// If baud rate not provided, use default
@@ -556,6 +555,81 @@ int extract_horus_binary_v2_128(struct horus *hstates, char hex_out[], int uw_lo
556555

557556
}
558557

558+
int extract_horus_binary_v2_256(struct horus *hstates, char hex_out[], int uw_loc) {
559+
const int nfield = 8; /* 8 bit binary */
560+
int st = uw_loc; /* first bit of first char */
561+
int en = uw_loc + hstates->max_packet_len; /* last bit of max length packet */
562+
563+
int j, b, nout;
564+
uint8_t rxpacket[hstates->max_packet_len];
565+
uint8_t rxbyte, *pout;
566+
567+
/* convert bits to a packet of bytes */
568+
569+
pout = rxpacket; nout = 0;
570+
571+
for (b=st; b<en; b+=nfield) {
572+
573+
/* assemble bytes MSB to LSB */
574+
575+
rxbyte = 0;
576+
for(j=0; j<nfield; j++) {
577+
assert(hstates->rx_bits[b+j] <= 1);
578+
rxbyte <<= 1;
579+
rxbyte |= hstates->rx_bits[b+j];
580+
}
581+
582+
/* build up output array */
583+
584+
*pout++ = rxbyte;
585+
nout++;
586+
}
587+
588+
if (hstates->verbose) {
589+
fprintf(stderr, " extract_horus_binary_v2_256 nout: %d\n Received Packet before decoding:\n ", nout);
590+
for (b=0; b<nout; b++) {
591+
fprintf(stderr, "%02X", rxpacket[b]);
592+
}
593+
fprintf(stderr, "\n");
594+
}
595+
596+
uint8_t payload_bytes[HORUS_BINARY_V2_256BIT_NUM_UNCODED_PAYLOAD_BYTES];
597+
float *softbits = hstates->soft_bits + uw_loc + sizeof(uw_horus_binary_v2);
598+
horus_ldpc_decode( payload_bytes, softbits , HORUS_MODE_BINARY_V2_256BIT);
599+
600+
uint16_t crc_tx, crc_rx;
601+
crc_rx = horus_l2_gen_crc16(payload_bytes, HORUS_BINARY_V2_256BIT_NUM_UNCODED_PAYLOAD_BYTES-2);
602+
crc_tx = (uint16_t)payload_bytes[HORUS_BINARY_V2_256BIT_NUM_UNCODED_PAYLOAD_BYTES-2] +
603+
((uint16_t)payload_bytes[HORUS_BINARY_V2_256BIT_NUM_UNCODED_PAYLOAD_BYTES-1]<<8);
604+
605+
if (hstates->verbose) {
606+
fprintf(stderr, " extract_horus_binary_v2_256 crc_tx: %04X crc_rx: %04X\n", crc_tx, crc_rx);
607+
}
608+
609+
/* convert to ASCII string of hex characters */
610+
611+
hex_out[0] = 0;
612+
char hex[3];
613+
for (b=0; b<HORUS_BINARY_V2_256BIT_NUM_UNCODED_PAYLOAD_BYTES; b++) {
614+
sprintf(hex, "%02X", payload_bytes[b]);
615+
strcat(hex_out, hex);
616+
}
617+
618+
if (hstates->verbose) {
619+
fprintf(stderr, " nout: %d Decoded Payload bytes:\n %s\n", nout, hex_out);
620+
}
621+
622+
/* With noise input to FSK demod we can get occasinal UW matches,
623+
so a good idea to only pass on any packets that pass CRC */
624+
625+
hstates->crc_ok = (crc_tx == crc_rx);
626+
if ( hstates->crc_ok) {
627+
hstates->total_payload_bits = HORUS_BINARY_V2_256BIT_NUM_UNCODED_PAYLOAD_BYTES;
628+
}
629+
630+
return hstates->crc_ok;
631+
632+
}
559633

560634
int horus_rx(struct horus *hstates, char ascii_out[], short demod_in[], int quadrature) {
561635
int i, j, uw_loc, packet_detected;
@@ -627,6 +701,9 @@ int horus_rx(struct horus *hstates, char ascii_out[], short demod_in[], int quad
627701
if (hstates->mode == HORUS_MODE_BINARY_V2_128BIT){
628702
packet_detected = extract_horus_binary_v2_128(hstates, ascii_out, uw_loc);
629703
}
704+
if (hstates->mode == HORUS_MODE_BINARY_V2_256BIT){
705+
packet_detected = extract_horus_binary_v2_256(hstates, ascii_out, uw_loc);
706+
}
630707
}
631708
return packet_detected;
632709
}

src/horus_l2.c

+16-18
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
4040
4/ Streaming test bits to stdout, for 'live' testing with fsk_mod and horus_demod:
4141
42-
$ gcc horus_l2.c golay23.c -o horus_l2 -Wall -DGEN_TX_BITSTREAM -DSCRAMBLER -DINTERLEAVER
42+
$ ggcc horus_l2.c golay23.c H_128_384_23.c H_256_768_22.c mpdecode_core.c phi0.c -o horus_l2 -Wall -DGEN_TX_BITSTREAM -DSCRAMBLER -DINTERLEAVER
4343
$ cp horus_l2 ../build/src/
4444
$ cd ../build/src/
45-
$ ./horus_l2 100 | ./fsk_mod 4 48000 100 750 250 - - | ./horus_demod -m binary - -
45+
$ ./horus_l2 100 0 | ./fsk_mod 4 48000 100 750 250 - - | ./horus_demod -m binary - -
4646
4747
5/ Unit testing interleaver:
4848
@@ -485,7 +485,8 @@ uint16_t primes[] = {
485485
127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
486486
179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
487487
233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
488-
283, 293, 307, 311, 313, 317, 331, 337, 347
488+
283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
489+
379, 383, 389, 757, 761, 769, 773
489490
};
490491

491492
void interleave(unsigned char *inout, int nbytes, int dir)
@@ -507,6 +508,8 @@ void interleave(unsigned char *inout, int nbytes, int dir)
507508
i++;
508509
b = primes[i-1];
509510

511+
fprintf(stderr,"nbits: %d coprime: %d\n", nbits, b);
512+
510513
for(n=0; n<nbits; n++) {
511514

512515
/*
@@ -984,7 +987,7 @@ int main(int argc,char *argv[]) {
984987
input_payload.Counter = 2;
985988
input_payload.Checksum = horus_l2_gen_crc16((unsigned char*)&input_payload, nbytes-2);
986989

987-
int ldpc_tx_bytes = ldpc_encode_packet(tx, (unsigned char*)&input_payload, 2);
990+
int ldpc_tx_bytes = ldpc_encode_packet(tx, (unsigned char*)&input_payload, 1);
988991

989992
int b;
990993
uint8_t tx_bit;
@@ -1216,27 +1219,21 @@ void horus_ldpc_decode(uint8_t *payload, float *sd, int mode) {
12161219
payload_bytes = H_128_384_23_DATA_BYTES;
12171220
}
12181221

1222+
double sd_double[bits_per_packet];
12191223
float llr[bits_per_packet];
12201224
float temp[bits_per_packet];
12211225
uint8_t outbits[bits_per_packet];
12221226

1223-
int b, i, parityCC;
1227+
int b, i, parityCC;
12241228
struct LDPC ldpc;
12251229

1226-
/* normalise bitstream to log-like */
1227-
sum = 0.0;
1228-
for ( i = 0; i < bits_per_packet; i++ )
1229-
sum += fabs(sd[i]);
1230-
mean = sum / bits_per_packet;
1230+
// cast incoming SDs to doubles for sd_to_llr
1231+
// For some reason I need to flip the sign ?!?!
1232+
for ( i = 0; i < bits_per_packet; i++ )
1233+
sd_double[i] = (double)sd[i]*-1.0;
12311234

1232-
sumsq = 0.0;
1233-
for ( i = 0; i < bits_per_packet; i++ ) {
1234-
x = fabs(sd[i]) / mean - 1.0;
1235-
sumsq += x * x;
1236-
}
1237-
estEsN0 = 2.0 * bits_per_packet / (sumsq + 1.0e-3) / mean;
1238-
for ( i = 0; i < bits_per_packet; i++ )
1239-
llr[i] = estEsN0 * sd[i];
1235+
1236+
sd_to_llr(llr, sd_double, bits_per_packet);
12401237

12411238
/* reverse whitening and re-order bits */
12421239
soft_unscramble(llr, temp, bits_per_packet);
@@ -1272,6 +1269,7 @@ void horus_ldpc_decode(uint8_t *payload, float *sd, int mode) {
12721269
}
12731270

12741271
i = run_ldpc_decoder(&ldpc, outbits, llr, &parityCC);
1272+
fprintf(stderr,"iterations: %d\n", i);
12751273

12761274
/* convert MSB bits to a packet of bytes */
12771275
for (b = 0; b < payload_bytes; b++) {

0 commit comments

Comments
 (0)