forked from paulh002/sdrberry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
liquid.internal.h
1817 lines (1549 loc) · 73 KB
/
liquid.internal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2007 - 2020 Joseph Gaeddert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
//
// liquid.internal.h
//
// Internal header file for liquid DSP for SDR
//
// This file includes function declarations which are intended
// for internal use
//
#ifndef __LIQUID_INTERNAL_H__
#define __LIQUID_INTERNAL_H__
// Configuration file
#include "config.h"
#include <stdarg.h>
#include <complex.h>
#include "liquid.h"
#if defined HAVE_FEC_H && defined HAVE_LIBFEC
# define LIBFEC_ENABLED 1
#endif
// report error
int liquid_error_fl(int _code, const char * _file, int _line, const char * _format, ...);
// report error specifically for invalid object configuration
void * liquid_error_config_fl(const char * _file, int _line, const char * _format, ...);
// macro to get file name and line number for source of error
#define liquid_error(code, format, ...) \
liquid_error_fl(code, __FILE__, __LINE__, format, ##__VA_ARGS__);
// macro to get file name and line number for source of error (invalid object)
#define liquid_error_config(format, ...) \
liquid_error_config_fl(__FILE__, __LINE__, format, ##__VA_ARGS__);
//
// Debugging macros
//
#define DEBUG_PRINTF_FLOAT(F,STR,I,V) \
fprintf(F,"%s(%4u) = %12.4e;\n",STR,I+1,V)
#define DEBUG_PRINTF_CFLOAT(F,STR,I,V) \
fprintf(F,"%s(%4u) = %12.4e +j*%12.4e;\n",STR,I+1,crealf(V),cimagf(V))
#define PRINTVAL_FLOAT(X,F) printf(#F,crealf(X));
#define PRINTVAL_CFLOAT(X,F) printf(#F "+j*" #F, crealf(X), cimagf(X));
//
// MODULE : agc
//
//
// MODULE : audio
//
//
// MODULE : buffer
//
//
// MODULE : dotprod
//
//
// MODULE : fec (forward error-correction)
//
// checksum / cyclic redundancy check (crc)
#define CRC8_POLY 0x07
#define CRC16_POLY 0x8005
#define CRC24_POLY 0x5D6DCB
#define CRC32_POLY 0x04C11DB7
unsigned int checksum_generate_key(unsigned char * _msg, unsigned int _msg_len);
unsigned int crc8_generate_key(unsigned char * _msg, unsigned int _msg_len);
unsigned int crc16_generate_key(unsigned char * _msg, unsigned int _msg_len);
unsigned int crc24_generate_key(unsigned char * _msg, unsigned int _msg_len);
unsigned int crc32_generate_key(unsigned char * _msg, unsigned int _msg_len);
// fec : basic object
struct fec_s {
// common
fec_scheme scheme;
//unsigned int dec_msg_len;
//unsigned int enc_msg_len;
float rate;
// lengths: convolutional, Reed-Solomon
unsigned int num_dec_bytes;
unsigned int num_enc_bytes;
// convolutional : internal memory structure
unsigned char * enc_bits;
void * vp; // decoder object
int * poly; // polynomial
unsigned int R; // primitive rate, inverted (e.g. R=3 for 1/3)
unsigned int K; // constraint length
unsigned int P; // puncturing rate (e.g. p=3 for 3/4)
int * puncturing_matrix;
// viterbi decoder function pointers
void*(*create_viterbi)(int);
//void (*set_viterbi_polynomial)(int*);
int (*init_viterbi)(void*,int);
int (*update_viterbi_blk)(void*,unsigned char*,int);
int (*chainback_viterbi)(void*,unsigned char*,unsigned int,unsigned int);
void (*delete_viterbi)(void*);
// Reed-Solomon
int symsize; // symbol size (bits per symbol)
int genpoly; // generator polynomial
int fcs; //
int prim; //
int nroots; // number of roots in the polynomial
//int ntrials; //
unsigned int rspad; // number of implicit padded symbols
int nn; // 2^symsize - 1
int kk; // nn - nroots
void * rs; // Reed-Solomon internal object
// Reed-Solomon decoder
unsigned int num_blocks; // number of blocks: ceil(dec_msg_len / nn)
unsigned int dec_block_len; // number of decoded bytes per block:
unsigned int enc_block_len; // number of encoded bytes per block:
unsigned int res_block_len; // residual bytes in last block
unsigned int pad; // padding for each block
unsigned char * tblock; // decoder input sequence [size: 1 x n]
int * errlocs; // error locations [size: 1 x n]
int * derrlocs; // decoded error locations [size: 1 x n]
int erasures; // number of erasures
// encode function pointer
int (*encode_func)(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_dec,
unsigned char * _msg_enc);
// decode function pointer
int (*decode_func)(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
// decode function pointer (soft decision)
int (*decode_soft_func)(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
};
// simple type testing
int fec_scheme_is_convolutional(fec_scheme _scheme);
int fec_scheme_is_punctured(fec_scheme _scheme);
int fec_scheme_is_reedsolomon(fec_scheme _scheme);
int fec_scheme_is_hamming(fec_scheme _scheme);
int fec_scheme_is_repeat(fec_scheme _scheme);
// Pass
fec fec_pass_create(void *_opts);
int fec_pass_destroy(fec _q);
int fec_pass_print(fec _q);
int fec_pass_encode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_dec,
unsigned char * _msg_enc);
int fec_pass_decode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
// Repeat (3)
fec fec_rep3_create(void *_opts);
int fec_rep3_destroy(fec _q);
int fec_rep3_print(fec _q);
int fec_rep3_encode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_dec,
unsigned char * _msg_enc);
int fec_rep3_decode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
int fec_rep3_decode_soft(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
// Repeat (5)
fec fec_rep5_create(void *_opts);
int fec_rep5_destroy(fec _q);
int fec_rep5_print(fec _q);
int fec_rep5_encode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_dec,
unsigned char * _msg_enc);
int fec_rep5_decode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
int fec_rep5_decode_soft(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
// Hamming(7,4)
extern unsigned char hamming74_enc_gentab[16];
extern unsigned char hamming74_dec_gentab[128];
fec fec_hamming74_create(void *_opts);
int fec_hamming74_destroy(fec _q);
int fec_hamming74_print(fec _q);
int fec_hamming74_encode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_dec,
unsigned char * _msg_enc);
int fec_hamming74_decode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
int fec_hamming74_decode_soft(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
// soft decoding of one symbol
unsigned char fecsoft_hamming74_decode(unsigned char * _soft_bits);
// Hamming(8,4)
extern unsigned char hamming84_enc_gentab[16];
extern unsigned char hamming84_dec_gentab[256];
fec fec_hamming84_create(void *_opts);
int fec_hamming84_destroy(fec _q);
int fec_hamming84_print(fec _q);
int fec_hamming84_encode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_dec,
unsigned char * _msg_enc);
int fec_hamming84_decode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
int fec_hamming84_decode_soft(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
// soft decoding of one symbol
unsigned char fecsoft_hamming84_decode(unsigned char * _soft_bits);
// Hamming(12,8)
unsigned int fec_hamming128_encode_symbol(unsigned int _sym_dec);
unsigned int fec_hamming128_decode_symbol(unsigned int _sym_enc);
extern unsigned short int hamming128_enc_gentab[256]; // encoding table
fec fec_hamming128_create(void *_opts);
int fec_hamming128_destroy(fec _q);
int fec_hamming128_print(fec _q);
int fec_hamming128_encode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_dec,
unsigned char * _msg_enc);
int fec_hamming128_decode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
int fec_hamming128_decode_soft(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
// soft decoding of one symbol
unsigned int fecsoft_hamming128_decode(unsigned char * _soft_bits);
extern unsigned char fecsoft_hamming128_n3[256][17];
unsigned int fecsoft_hamming128_decode_n3(unsigned char * _soft_bits);
// Hamming(15,11)
unsigned int fec_hamming1511_encode_symbol(unsigned int _sym_dec);
unsigned int fec_hamming1511_decode_symbol(unsigned int _sym_enc);
// Hamming(31,26)
unsigned int fec_hamming3126_encode_symbol(unsigned int _sym_dec);
unsigned int fec_hamming3126_decode_symbol(unsigned int _sym_enc);
// Golay(24,12)
unsigned int fec_golay2412_encode_symbol(unsigned int _sym_dec);
unsigned int fec_golay2412_decode_symbol(unsigned int _sym_enc);
extern unsigned int golay2412_P[12];
extern unsigned int golay2412_Gt[24];
extern unsigned int golay2412_H[12];
// multiply input vector with matrix
unsigned int golay2412_matrix_mul(unsigned int _v,
unsigned int * _A,
unsigned int _n);
// search for p[i] such that w(v+p[i]) <= 2, return -1 on fail
int golay2412_parity_search(unsigned int _v);
fec fec_golay2412_create(void *_opts);
int fec_golay2412_destroy(fec _q);
int fec_golay2412_print(fec _q);
int fec_golay2412_encode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_dec,
unsigned char * _msg_enc);
int fec_golay2412_decode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
// SEC-DED (22,16)
// compute parity on 16-bit input
unsigned char fec_secded2216_compute_parity(unsigned char * _m);
// compute syndrome on 22-bit input
unsigned char fec_secded2216_compute_syndrome(unsigned char * _v);
// encode symbol
// _sym_dec : decoded symbol [size: 2 x 1]
// _sym_enc : encoded symbol [size: 3 x 1], _sym_enc[0] has only 6 bits
int fec_secded2216_encode_symbol(unsigned char * _sym_dec,
unsigned char * _sym_enc);
// decode symbol, returning 0/1/2 for zero/one/multiple errors detected
// _sym_enc : encoded symbol [size: 3 x 1], _sym_enc[0] has only 6 bits
// _sym_dec : decoded symbol [size: 2 x 1]
int fec_secded2216_decode_symbol(unsigned char * _sym_enc,
unsigned char * _sym_dec);
// estimate error vector, returning 0/1/2 for zero/one/multiple errors detected
// _sym_enc : encoded symbol [size: 3 x 1], _sym_enc[0] has only 6 bits
// _e_hat : estimated error vector [size: 3 x 1]
int fec_secded2216_estimate_ehat(unsigned char * _sym_enc,
unsigned char * _e_hat);
// parity matrix [6 x 16 bits], [6 x 2 bytes]
extern unsigned char secded2216_P[12];
// syndrome vectors of errors with weight exactly equal to 1
extern unsigned char secded2216_syndrome_w1[22];
fec fec_secded2216_create(void *_opts);
int fec_secded2216_destroy(fec _q);
int fec_secded2216_print(fec _q);
int fec_secded2216_encode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_dec,
unsigned char * _msg_enc);
int fec_secded2216_decode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
// SEC-DED (39,32)
// compute parity on 32-bit input
unsigned char fec_secded3932_compute_parity(unsigned char * _m);
// compute syndrome on 39-bit input
unsigned char fec_secded3932_compute_syndrome(unsigned char * _v);
// encode symbol
// _sym_dec : decoded symbol [size: 4 x 1]
// _sym_enc : encoded symbol [size: 5 x 1], _sym_enc[0] has only 7 bits
int fec_secded3932_encode_symbol(unsigned char * _sym_dec,
unsigned char * _sym_enc);
// estimate error vector, returning 0/1/2 for zero/one/multiple errors detected
// _sym_enc : encoded symbol [size: 5 x 1], _sym_enc[0] has only 7 bits
// _e_hat : estimated error vector [size: 5 x 1]
int fec_secded3932_estimate_ehat(unsigned char * _sym_enc,
unsigned char * _e_hat);
// decode symbol, returning 0/1/2 for zero/one/multiple errors detected
// _sym_enc : encoded symbol [size: 5 x 1], _sym_enc[0] has only 7 bits
// _sym_dec : decoded symbol [size: 4 x 1]
int fec_secded3932_decode_symbol(unsigned char * _sym_enc,
unsigned char * _sym_dec);
// parity matrix [7 x 32 bits], [7 x 4 bytes]
extern unsigned char secded3932_P[28];
// syndrome vectors of errors with weight exactly equal to 1
extern unsigned char secded3932_syndrome_w1[39];
fec fec_secded3932_create(void *_opts);
int fec_secded3932_destroy(fec _q);
int fec_secded3932_print(fec _q);
int fec_secded3932_encode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_dec,
unsigned char * _msg_enc);
int fec_secded3932_decode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
// SEC-DED (72,64)
// compute parity byte on 64-byte input
unsigned char fec_secded7264_compute_parity(unsigned char * _v);
// compute syndrome on 72-bit input
unsigned char fec_secded7264_compute_syndrome(unsigned char * _v);
// encode symbol
// _sym_dec : input symbol [size: 8 x 1]
// _sym_enc : input symbol [size: 9 x 1]
int fec_secded7264_encode_symbol(unsigned char * _sym_dec,
unsigned char * _sym_enc);
// estimate error vector, returning 0/1/2 for zero/one/multiple errors detected
// _sym_enc : encoded symbol [size: 9 x 1]
// _e_hat : estimated error vector [size: 9 x 1]
int fec_secded7264_estimate_ehat(unsigned char * _sym_enc,
unsigned char * _e_hat);
// decode symbol, returning 0/1/2 for zero/one/multiple errors detected
// _sym_enc : input symbol [size: 8 x 1]
// _sym_dec : input symbol [size: 9 x 1]
int fec_secded7264_decode_symbol(unsigned char * _sym_enc,
unsigned char * _sym_dec);
extern unsigned char secded7264_P[64];
extern unsigned char secded7264_syndrome_w1[72];
fec fec_secded7264_create(void *_opts);
int fec_secded7264_destroy(fec _q);
int fec_secded7264_print(fec _q);
int fec_secded7264_encode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_dec,
unsigned char * _msg_enc);
int fec_secded7264_decode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
// Convolutional: r1/2 K=7
// r1/2 K=9
// r1/3 K=9
// r1/6 K=15
// compute encoded message length for block codes
// _dec_msg_len : decoded message length (bytes)
// _m : input block size (bits)
// _k : output block size (bits)
unsigned int fec_block_get_enc_msg_len(unsigned int _dec_msg_len,
unsigned int _m,
unsigned int _k);
// compute encoded message length for convolutional codes
// _dec_msg_len : decoded message length
// _K : constraint length
// _p : puncturing rate, r = _p / (_p+1)
unsigned int fec_conv_get_enc_msg_len(unsigned int _dec_msg_len,
unsigned int _K,
unsigned int _p);
// convolutional code polynomials
extern int fec_conv27_poly[2];
extern int fec_conv29_poly[2];
extern int fec_conv39_poly[3];
extern int fec_conv615_poly[6];
// convolutional code puncturing matrices [R x P]
extern int fec_conv27p23_matrix[4]; // [2 x 2]
extern int fec_conv27p34_matrix[6]; // [2 x 3]
extern int fec_conv27p45_matrix[8]; // [2 x 4]
extern int fec_conv27p56_matrix[10]; // [2 x 5]
extern int fec_conv27p67_matrix[12]; // [2 x 6]
extern int fec_conv27p78_matrix[14]; // [2 x 7]
extern int fec_conv29p23_matrix[4]; // [2 x 2]
extern int fec_conv29p34_matrix[6]; // [2 x 3]
extern int fec_conv29p45_matrix[8]; // [2 x 4]
extern int fec_conv29p56_matrix[10]; // [2 x 5]
extern int fec_conv29p67_matrix[12]; // [2 x 6]
extern int fec_conv29p78_matrix[14]; // [2 x 7]
fec fec_conv_create(fec_scheme _fs);
int fec_conv_destroy(fec _q);
int fec_conv_print(fec _q);
int fec_conv_encode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_dec,
unsigned char * _msg_enc);
int fec_conv_decode_hard(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
int fec_conv_decode_soft(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
int fec_conv_decode(fec _q, unsigned char * _msg_dec);
int fec_conv_setlength(fec _q, unsigned int _dec_msg_len);
// internal initialization methods (sets r, K, viterbi methods)
int fec_conv_init_v27(fec _q);
int fec_conv_init_v29(fec _q);
int fec_conv_init_v39(fec _q);
int fec_conv_init_v615(fec _q);
// punctured convolutional codes
fec fec_conv_punctured_create(fec_scheme _fs);
int fec_conv_punctured_destroy(fec _q);
int fec_conv_punctured_print(fec _q);
int fec_conv_punctured_encode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_dec,
unsigned char * _msg_enc);
int fec_conv_punctured_decode_hard(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
int fec_conv_punctured_decode_soft(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
int fec_conv_punctured_setlength(fec _q, unsigned int _dec_msg_len);
// internal initialization methods (sets r, K, viterbi methods,
// and puncturing matrix)
int fec_conv_init_v27p23(fec _q);
int fec_conv_init_v27p34(fec _q);
int fec_conv_init_v27p45(fec _q);
int fec_conv_init_v27p56(fec _q);
int fec_conv_init_v27p67(fec _q);
int fec_conv_init_v27p78(fec _q);
int fec_conv_init_v29p23(fec _q);
int fec_conv_init_v29p34(fec _q);
int fec_conv_init_v29p45(fec _q);
int fec_conv_init_v29p56(fec _q);
int fec_conv_init_v29p67(fec _q);
int fec_conv_init_v29p78(fec _q);
// Reed-Solomon
// compute encoded message length for Reed-Solomon codes
// _dec_msg_len : decoded message length
// _nroots : number of roots in polynomial
// _nn :
// _kk :
unsigned int fec_rs_get_enc_msg_len(unsigned int _dec_msg_len,
unsigned int _nroots,
unsigned int _nn,
unsigned int _kk);
fec fec_rs_create(fec_scheme _fs);
int fec_rs_destroy(fec _q);
int fec_rs_init_p8(fec _q);
int fec_rs_setlength(fec _q,
unsigned int _dec_msg_len);
int fec_rs_encode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_dec,
unsigned char * _msg_enc);
int fec_rs_decode(fec _q,
unsigned int _dec_msg_len,
unsigned char * _msg_enc,
unsigned char * _msg_dec);
// phi(x) = -logf( tanhf( x/2 ) )
float sumproduct_phi(float _x);
// iterate over the sum-product algorithm:
// returns 1 if parity checks, 0 otherwise
// _m : rows
// _n : cols
// _H : sparse binary parity check matrix [size: _m x _n]
// _LLR : received signal (soft bits, LLR) [size: _n x 1]
// _c_hat : estimated transmitted signal [size: _n x 1]
// _max_steps : maximum number of steps before bailing
int fec_sumproduct(unsigned int _m,
unsigned int _n,
smatrixb _H,
float * _LLR,
unsigned char * _c_hat,
unsigned int _max_steps);
// sum-product algorithm, returns 1 if parity checks, 0 otherwise
// _m : rows
// _n : cols
// _H : sparse binary parity check matrix [size: _m x _n]
// _c_hat : estimated transmitted signal [size: _n x 1]
//
// internal state arrays
// _Lq : [size: _m x _n]
// _Lr : [size: _m x _n]
// _Lc : [size: _n x 1]
// _LQ : [size: _n x 1]
// _parity : _H * _c_hat [size: _m x 1]
int fec_sumproduct_step(unsigned int _m,
unsigned int _n,
smatrixb _H,
unsigned char * _c_hat,
float * _Lq,
float * _Lr,
float * _Lc,
float * _LQ,
unsigned char * _parity);
//
// packetizer
//
// fec/interleaver plan
struct fecintlv_plan {
unsigned int dec_msg_len;
unsigned int enc_msg_len;
// fec codec
fec_scheme fs;
fec f;
// interleaver
interleaver q;
};
#define PACKETIZER_VERSION (1)
// packetizer object
struct packetizer_s {
unsigned int msg_len;
unsigned int packet_len;
crc_scheme check;
unsigned int crc_length;
struct fecintlv_plan * plan;
unsigned int plan_len;
// buffers (ping-pong)
unsigned int buffer_len;
unsigned char * buffer_0;
unsigned char * buffer_1;
};
//
// MODULE : fft (fast discrete Fourier transform)
//
// fast fourier transform method
typedef enum {
LIQUID_FFT_METHOD_UNKNOWN=0, // unknown method
LIQUID_FFT_METHOD_RADIX2, // Radix-2 (decimation in time)
LIQUID_FFT_METHOD_MIXED_RADIX, // Cooley-Tukey mixed-radix FFT (decimation in time)
LIQUID_FFT_METHOD_RADER, // Rader's method for FFTs of prime length
LIQUID_FFT_METHOD_RADER2, // Rader's method for FFTs of prime length (alternate)
LIQUID_FFT_METHOD_DFT, // regular discrete Fourier transform
} liquid_fft_method;
// Macro : FFT (internal)
// FFT : name-mangling macro
// T : primitive data type
// TC : primitive data type (complex)
#define LIQUID_FFT_DEFINE_INTERNAL_API(FFT,T,TC) \
\
/* print plan recursively */ \
int FFT(_print_plan_recursive)(FFT(plan) _q, \
unsigned int _level); \
\
/* type definitions for create/destroy/execute functions */ \
typedef FFT(plan)(FFT(_create_t)) (unsigned int _nfft, \
TC * _x, \
TC * _y, \
int _dir, \
int _flags); \
typedef int (FFT(_destroy_t))(FFT(plan) _q); \
typedef int (FFT(_execute_t))(FFT(plan) _q); \
\
/* FFT create methods */ \
FFT(_create_t) FFT(_create_plan_dft); \
FFT(_create_t) FFT(_create_plan_radix2); \
FFT(_create_t) FFT(_create_plan_mixed_radix); \
FFT(_create_t) FFT(_create_plan_rader); \
FFT(_create_t) FFT(_create_plan_rader2); \
\
/* FFT destroy methods */ \
FFT(_destroy_t) FFT(_destroy_plan_dft); \
FFT(_destroy_t) FFT(_destroy_plan_radix2); \
FFT(_destroy_t) FFT(_destroy_plan_mixed_radix); \
FFT(_destroy_t) FFT(_destroy_plan_rader); \
FFT(_destroy_t) FFT(_destroy_plan_rader2); \
\
/* FFT execute methods */ \
FFT(_execute_t) FFT(_execute_dft); \
FFT(_execute_t) FFT(_execute_radix2); \
FFT(_execute_t) FFT(_execute_mixed_radix); \
FFT(_execute_t) FFT(_execute_rader); \
FFT(_execute_t) FFT(_execute_rader2); \
\
/* specific codelets for small DFTs */ \
FFT(_execute_t) FFT(_execute_dft_2); \
FFT(_execute_t) FFT(_execute_dft_3); \
FFT(_execute_t) FFT(_execute_dft_4); \
FFT(_execute_t) FFT(_execute_dft_5); \
FFT(_execute_t) FFT(_execute_dft_6); \
FFT(_execute_t) FFT(_execute_dft_7); \
FFT(_execute_t) FFT(_execute_dft_8); \
FFT(_execute_t) FFT(_execute_dft_16); \
\
/* additional methods */ \
unsigned int FFT(_estimate_mixed_radix)(unsigned int _nfft); \
\
/* discrete cosine transform (DCT) prototypes */ \
int FFT(_execute_REDFT00)(FFT(plan) _q); /* DCT-I */ \
int FFT(_execute_REDFT10)(FFT(plan) _q); /* DCT-II */ \
int FFT(_execute_REDFT01)(FFT(plan) _q); /* DCT-III */ \
int FFT(_execute_REDFT11)(FFT(plan) _q); /* DCT-IV */ \
\
/* discrete sine transform (DST) prototypes */ \
int FFT(_execute_RODFT00)(FFT(plan) _q); /* DST-I */ \
int FFT(_execute_RODFT10)(FFT(plan) _q); /* DST-II */ \
int FFT(_execute_RODFT01)(FFT(plan) _q); /* DST-III */ \
int FFT(_execute_RODFT11)(FFT(plan) _q); /* DST-IV */ \
\
/* destroy real-to-real one-dimensional plan */ \
int FFT(_destroy_plan_r2r_1d)(FFT(plan) _q); \
\
/* print real-to-real one-dimensional plan */ \
int FFT(_print_plan_r2r_1d)(FFT(plan) _q); \
// determine best FFT method based on size
liquid_fft_method liquid_fft_estimate_method(unsigned int _nfft);
// is input radix-2?
int fft_is_radix2(unsigned int _n);
// miscellaneous functions
unsigned int fft_reverse_index(unsigned int _i, unsigned int _n);
LIQUID_FFT_DEFINE_INTERNAL_API(LIQUID_FFT_MANGLE_FLOAT, float, liquid_float_complex)
// Use fftw library if installed (and not overridden with configuration),
// otherwise use internal (less efficient) fft library.
#if HAVE_FFTW3_H && !defined LIQUID_FFTOVERRIDE
# include <fftw3.h>
# define FFT_PLAN fftwf_plan
# define FFT_CREATE_PLAN fftwf_plan_dft_1d
# define FFT_DESTROY_PLAN fftwf_destroy_plan
# define FFT_EXECUTE fftwf_execute
# define FFT_DIR_FORWARD FFTW_FORWARD
# define FFT_DIR_BACKWARD FFTW_BACKWARD
# define FFT_METHOD FFTW_ESTIMATE
#else
# define FFT_PLAN fftplan
# define FFT_CREATE_PLAN fft_create_plan
# define FFT_DESTROY_PLAN fft_destroy_plan
# define FFT_EXECUTE fft_execute
# define FFT_DIR_FORWARD LIQUID_FFT_FORWARD
# define FFT_DIR_BACKWARD LIQUID_FFT_BACKWARD
# define FFT_METHOD 0
#endif
//
// MODULE : filter
//
// esimate required filter length given transition bandwidth and
// stop-band attenuation (algorithm from [Vaidyanathan:1993])
// _df : transition bandwidth (0 < _df < 0.5)
// _As : stop-band attenuation [dB] (As > 0)
float estimate_req_filter_len_Kaiser(float _df,
float _As);
// esimate required filter length given transition bandwidth and
// stop-band attenuation (algorithm from [Herrmann:1973])
// _df : transition bandwidth (0 < _df < 0.5)
// _As : stop-band attenuation [dB] (As > 0)
float estimate_req_filter_len_Herrmann(float _df,
float _As);
// fir_farrow
#define LIQUID_FIRFARROW_DEFINE_INTERNAL_API(FIRFARROW,TO,TC,TI) \
void FIRFARROW(_genpoly)(FIRFARROW() _q);
LIQUID_FIRFARROW_DEFINE_INTERNAL_API(LIQUID_FIRFARROW_MANGLE_RRRF,
float,
float,
float)
LIQUID_FIRFARROW_DEFINE_INTERNAL_API(LIQUID_FIRFARROW_MANGLE_CRCF,
liquid_float_complex,
float,
liquid_float_complex)
// firdes : finite impulse response filter design
// Find approximate bandwidth adjustment factor rho based on
// filter delay and desired excess bandwdith factor.
//
// _m : filter delay (symbols)
// _beta : filter excess bandwidth factor (0,1)
float rkaiser_approximate_rho(unsigned int _m,
float _beta);
// Design frequency-shifted root-Nyquist filter based on
// the Kaiser-windowed sinc using the bisection method
//
// _k : filter over-sampling rate (samples/symbol)
// _m : filter delay (symbols)
// _beta : filter excess bandwidth factor (0,1)
// _dt : filter fractional sample delay
// _h : resulting filter [size: 2*_k*_m+1]
// _rho : transition bandwidth adjustment, 0 < _rho < 1
void liquid_firdes_rkaiser_bisection(unsigned int _k,
unsigned int _m,
float _beta,
float _dt,
float * _h,
float * _rho);
// Design frequency-shifted root-Nyquist filter based on
// the Kaiser-windowed sinc using the quadratic method.
//
// _k : filter over-sampling rate (samples/symbol)
// _m : filter delay (symbols)
// _beta : filter excess bandwidth factor (0,1)
// _dt : filter fractional sample delay
// _h : resulting filter [size: 2*_k*_m+1]
// _rho : transition bandwidth adjustment, 0 < _rho < 1
void liquid_firdes_rkaiser_quadratic(unsigned int _k,
unsigned int _m,
float _beta,
float _dt,
float * _h,
float * _rho);
// compute filter coefficients and determine resulting ISI
//
// _k : filter over-sampling rate (samples/symbol)
// _m : filter delay (symbols)
// _beta : filter excess bandwidth factor (0,1)
// _dt : filter fractional sample delay
// _rho : transition bandwidth adjustment, 0 < _rho < 1
// _h : filter buffer [size: 2*_k*_m+1]
float liquid_firdes_rkaiser_internal_isi(unsigned int _k,
unsigned int _m,
float _beta,
float _dt,
float _rho,
float * _h);
// Design flipped Nyquist/root-Nyquist filters
void liquid_firdes_fnyquist(liquid_firfilt_type _type,
int _root,
unsigned int _k,
unsigned int _m,
float _beta,
float _dt,
float * _h);
// flipped exponential frequency response
void liquid_firdes_fexp_freqresponse(unsigned int _k,
unsigned int _m,
float _beta,
float * _H);
// flipped hyperbolic secant frequency response
void liquid_firdes_fsech_freqresponse(unsigned int _k,
unsigned int _m,
float _beta,
float * _H);
// flipped hyperbolic secant frequency response
void liquid_firdes_farcsech_freqresponse(unsigned int _k,
unsigned int _m,
float _beta,
float * _H);
// iirdes : infinite impulse response filter design
// Sorts array _z of complex numbers into complex conjugate pairs to
// within a tolerance. Conjugate pairs are ordered by increasing real
// component with the negative imaginary element first. All pure-real
// elements are placed at the end of the array.
//
// Example:
// v: liquid_cplxpair(v):
// 10 + j*3 -3 - j*4
// 5 + j*0 3 + j*4
// -3 + j*4 10 - j*3
// 10 - j*3 10 + j*3
// 3 + j*0 3 + j*0
// -3 + j*4 5 + j*0
//
// _z : complex array (size _n)
// _n : number of elements in _z
// _tol : tolerance for finding complex pairs
// _p : resulting pairs, pure real values of _z at end
void liquid_cplxpair(float complex * _z,
unsigned int _n,
float _tol,
float complex * _p);
// post-process cleanup used with liquid_cplxpair
//
// once pairs have been identified and ordered, this method
// will clean up the result by ensuring the following:
// * pairs are perfect conjugates
// * pairs have negative imaginary component first
// * pairs are ordered by increasing real component
// * pure-real elements are ordered by increasing value
//
// _p : pre-processed complex array [size: _n x 1]
// _n : array length
// _num_pairs : number of complex conjugate pairs
void liquid_cplxpair_cleanup(float complex * _p,
unsigned int _n,
unsigned int _num_pairs);
// Jacobian elliptic functions (src/filter/src/ellip.c)
// Landen transformation (_n iterations)
void landenf(float _k,
unsigned int _n,
float * _v);
// compute elliptic integral K(k) for _n recursions
void ellipkf(float _k,
unsigned int _n,
float * _K,
float * _Kp);
// elliptic degree
float ellipdegf(float _N,
float _k1,
unsigned int _n);
// elliptic cd() function (_n recursions)
float complex ellip_cdf(float complex _u,
float _k,
unsigned int _n);
// elliptic inverse cd() function (_n recursions)
float complex ellip_acdf(float complex _u,
float _k,
unsigned int _n);
// elliptic sn() function (_n recursions)
float complex ellip_snf(float complex _u,
float _k,
unsigned int _n);
// elliptic inverse sn() function (_n recursions)
float complex ellip_asnf(float complex _u,
float _k,
unsigned int _n);
//
// MODULE : framing
//
//
// bpacket
//
#define BPACKET_VERSION (101+PACKETIZER_VERSION)