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
|
// main.c
// Word Error Rate test example for Q-ary RA codes over GF(64)
//
// (c) 2016 - Nico Palermo, IV3NWV
//
// Thanks to Andrea Montefusco IW0HDV for his help on adapting the sources
// to OSs other than MS Windows
//
// ------------------------------------------------------------------------------
// This file is part of the qracodes project, a Forward Error Control
// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes.
//
// Files in this package:
// main.c - this file
// normrnd.c/.h - random gaussian number generator
// npfwht.c/.h - Fast Walsh-Hadamard Transforms
// pdmath.c/.h - Elementary math on probability distributions
// qra12_63_64_irr_b.c/.h - Tables for a QRA(12,63) irregular RA code over GF(64)
// qra13_64_64_irr_e.c/.h - Tables for a QRA(13,64) irregular RA code " "
// qracodes.c/.h - QRA codes encoding/decoding functions
//
// -------------------------------------------------------------------------------
//
// qracodes 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 3 of the License, or
// (at your option) any later version.
// qracodes is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with qracodes source distribution.
// If not, see <http://www.gnu.org/licenses/>.
// -----------------------------------------------------------------------------
// Two codes are available for simulations in this sowftware release:
// QRA12_63_64_IRR_B: K=12 N=63 Q=64 irregular QRA code (defined in qra12_63_64_irr_b.h /.c)
// QRA13_64_64_IRR_E: K=13 N=64 Q=64 irregular QRA code (defined in qra13_64_64_irr_b.h /.c)
// Codes with K=13 are designed to include a CRC as the 13th information symbol
// and improve the code UER (Undetected Error Rate).
// The CRC symbol is not sent along the channel (the codes are punctured) and the
// resulting code is still a (12,63) code with an effective code rate of R = 12/63.
// ------------------------------------------------------------------------------
// OS dependent defines and includes --------------------------------------------
#if _WIN32 // note the underscore: without it, it's not msdn official!
// Windows (x64 and x86)
#include <windows.h> // required only for GetTickCount(...)
#include <process.h> // _beginthread
#endif
#if defined(__linux__)
// remove unwanted macros
#define __cdecl
// implements Windows API
#include <time.h>
unsigned int GetTickCount(void) {
struct timespec ts;
unsigned int theTick = 0U;
clock_gettime( CLOCK_REALTIME, &ts );
theTick = ts.tv_nsec / 1000000;
theTick += ts.tv_sec * 1000;
return theTick;
}
// Convert Windows millisecond sleep
//
// VOID WINAPI Sleep(_In_ DWORD dwMilliseconds);
//
// to Posix usleep (in microseconds)
//
// int usleep(useconds_t usec);
//
#include <unistd.h>
#define Sleep(x) usleep(x*1000)
#endif
#if defined(__linux__) || ( defined(__MINGW32__) || defined (__MIGW64__) )
#include <pthread.h>
#endif
#if __APPLE__
#endif
#include <stdlib.h>
#include <stdio.h>
#include "qracodes.h"
#include "normrnd.h" // gaussian numbers generator
#include "pdmath.h" // operations on probability distributions
// defined codes
#include "qra12_63_64_irr_b.h"
#include "qra13_64_64_irr_e.h"
// -----------------------------------------------------------------------------------
#define NTHREADS_MAX 160
// channel types
#define CHANNEL_AWGN 0
#define CHANNEL_RAYLEIGH 1
// amount of a-priori information provided to the decoder
#define AP_NONE 0
#define AP_28 1
#define AP_44 2
#define AP_56 3
const char ap_str[4][16] = {
"None",
"28 bit",
"44 bit",
"56 bit"
};
const char fnameout_pfx[2][64] = {
"wer-awgn-",
"wer-rayleigh-"
};
const char fnameout_sfx[4][64] = {
"-ap00.txt",
"-ap28.txt",
"-ap44.txt",
"-ap56.txt"
};
const int ap_masks_jt65[4][13] = {
// Each row must be 13 entries long (to handle puntc. codes 13,64)
// The mask of 13th symbol (crc) is alway initializated to 0
// AP0 - no a-priori knowledge
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
// AP28 - 1st field known [cq ? ?] or [dst ? ?]
{0x3F,0x3F,0x3F,0x3F,0x3C, 0, 0, 0, 0, 0, 0, 0},
// AP44 - 1st and 3rd fields known [cq ? 0] or [dst ? 0]
{0x3F,0x3F,0x3F,0x3F,0x3C, 0, 0, 0, 0,0x0F,0x3F,0x3F},
// AP56 - 1st and 2nd fields known [dst src ?]
{0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x30, 0, 0}
};
void ix_mask(const qracode *pcode, float *r, const int *mask, const int *x);
void printword(char *msg, int *x, int size)
{
int k;
printf("\n%s ",msg);
for (k=0;k<size;k++)
printf("%02hx ",x[k]);
printf("\n");
}
typedef struct {
int channel_type;
float EbNodB;
volatile int nt;
volatile int nerrs;
volatile int nerrsu;
volatile int stop;
volatile int done;
int ap_index; // index to the a priori knowledge mask
const qracode *pcode; // pointer to the code descriptor
int *x; //[qra_K]; input message buffer
int *y, *ydec; //[qra_N]; encoded/decoded codewords buffers
float *qra_v2cmsg; //[qra_NMSG*qra_M]; MP decoder v->c msg buffer
float *qra_c2vmsg; //[qra_NMSG*qra_M]; MP decoder c->v msg buffer
float *rp; // [qra_N*qra_M]; received samples (real component) buffer
float *rq; // [qra_N*qra_M]; received samples (imag component) buffer
float *chp; //[qra_N]; channel gains (real component) buffer
float *chq; //[qra_N]; channel gains (imag component) buffer
float *r; //[qra_N*qra_M]; received samples (amplitude) buffer
float *ix; // [qra_N*qra_M]; // intrinsic information to the MP algorithm
float *ex; // [qra_N*qra_M]; // extrinsic information from the MP algorithm
} wer_test_ds;
typedef void( __cdecl *pwer_test_thread)(wer_test_ds*);
// crc-6 generator polynomial
// g(x) = x^6 + a5*x^5 + ... + a1*x + a0
// g(x) = x^6 + x + 1
#define CRC6_GEN_POL 0x30 // MSB=a0 LSB=a5
// g(x) = x^6 + x^2 + x + 1 (as suggested by Joe. See: https://users.ece.cmu.edu/~koopman/crc/)
// #define CRC6_GEN_POL 0x38 // MSB=a0 LSB=a5. Simulation results are similar
int calc_crc6(int *x, int sz)
{
int k,j,t,sr = 0;
for (k=0;k<sz;k++) {
t = x[k];
for (j=0;j<6;j++) {
if ((t^sr)&0x01)
sr = (sr>>1) ^ CRC6_GEN_POL;
else
sr = (sr>>1);
t>>=1;
}
}
return sr;
}
void wer_test_thread(wer_test_ds *pdata)
{
const qracode *pcode=pdata->pcode;
const int qra_K = pcode->K;
const int qra_N = pcode->N;
const int qra_M = pcode->M;
const int qra_m = pcode->m;
const int NSAMPLES = pcode->N*pcode->M;
const float No = 1.0f; // noise spectral density
const float sigma = (float)sqrt(No/2.0f); // std dev of noise I/Q components
const float sigmach = (float)sqrt(1/2.0f); // std dev of channel I/Q gains
// Eb/No value for which we optimize the bessel metric
const float EbNodBMetric = 2.8f;
const float EbNoMetric = (float)pow(10,EbNodBMetric/10);
int k,t,j,diff;
float R;
float EsNoMetric;
float EbNo, EsNo, Es, A;
int channel_type, code_type;
int nt=0; // transmitted codewords
int nerrs = 0; // total number of errors
int nerrsu = 0; // number of undetected errors
int rc;
// inizialize pointer to required buffers
int *x=pdata->x; // message buffer
int *y=pdata->y, *ydec=pdata->ydec; // encoded/decoded codeword buffers
float *qra_v2cmsg=pdata->qra_v2cmsg; // table of the v->c messages
float *qra_c2vmsg=pdata->qra_c2vmsg; // table of the c->v messages
float *rp=pdata->rp; // received samples (real component)
float *rq=pdata->rq; // received samples (imag component)
float *chp=pdata->chp; // channel gains (real component)
float *chq=pdata->chq; // channel gains (imag component)
float *r=pdata->r; // received samples amplitudes
float *ix=pdata->ix; // intrinsic information to the MP algorithm
float *ex=pdata->ex; // extrinsic information from the MP algorithm
channel_type = pdata->channel_type;
code_type = pcode->type;
// define the (true) code rate accordingly to the code type
switch(code_type) {
case QRATYPE_CRC:
R = 1.0f*(qra_K-1)/qra_N;
break;
case QRATYPE_CRCPUNCTURED:
R = 1.0f*(qra_K-1)/(qra_N-1);
break;
case QRATYPE_NORMAL:
default:
R = 1.0f*(qra_K)/(qra_N);
}
EsNoMetric = 1.0f*qra_m*R*EbNoMetric;
EbNo = (float)pow(10,pdata->EbNodB/10);
EsNo = 1.0f*qra_m*R*EbNo;
Es = EsNo*No;
A = (float)sqrt(Es);
// encode the input
if (code_type==QRATYPE_CRC || code_type==QRATYPE_CRCPUNCTURED) {
// compute the information message symbol check as the (negated) xor of all the
// information message symbols
for (k=0;k<(qra_K-1);k++)
x[k]=k%qra_M;
x[k]=calc_crc6(x,qra_K-1);
}
else
for (k=0;k<qra_K;k++)
x[k]=k%qra_M;
qra_encode(pcode,y,x);
while (pdata->stop==0) {
// simulate the channel
// NOTE: in the case that the code is punctured, for simplicity
// we compute the channel outputs and the metric also for the crc symbol
// then we ignore its observation.
normrnd_s(rp,NSAMPLES,0,sigma);
normrnd_s(rq,NSAMPLES,0,sigma);
if (channel_type == CHANNEL_AWGN) {
for (k=0;k<qra_N;k++)
rp[k*qra_M+y[k]]+=A;
}
else if (channel_type == CHANNEL_RAYLEIGH) {
normrnd_s(chp,qra_N,0,sigmach);
normrnd_s(chq,qra_N,0,sigmach);
for (k=0;k<qra_N;k++) {
rp[k*qra_M+y[k]]+=A*chp[k];
rq[k*qra_M+y[k]]+=A*chq[k];
}
}
else {
pdata->done = 1;
return; // unknown channel type
}
// compute the squares of the amplitudes of the received samples
for (k=0;k<NSAMPLES;k++)
r[k] = rp[k]*rp[k] + rq[k]*rq[k];
// compute the intrinsic symbols probabilities
qra_mfskbesselmetric(ix,r,pcode->m,pcode->N,EsNoMetric);
if (code_type==QRATYPE_CRCPUNCTURED) {
// ignore observations of the CRC symbol as it is not actually sent
// over the channel
pd_init(PD_ROWADDR(ix,qra_M,qra_K),pd_uniform(qra_m),qra_M);
}
if (pdata->ap_index!=0)
// mask channel observations with a priori knowledge
ix_mask(pcode,ix,ap_masks_jt65[pdata->ap_index],x);
// compute the extrinsic symbols probabilities with the message-passing algorithm
// stop if extrinsic information does not converges to 1 within the given number of iterations
rc = qra_extrinsic(pcode,ex,ix,100,qra_v2cmsg,qra_c2vmsg);
if (rc>=0) { // the MP algorithm converged to Iex~1 in rc iterations
// decode the codeword
qra_mapdecode(pcode,ydec,ex,ix);
// look for undetected errors
if (code_type==QRATYPE_CRC || code_type==QRATYPE_CRCPUNCTURED) {
j = 0; diff = 0;
for (k=0;k<(qra_K-1);k++)
diff |= (ydec[k]!=x[k]);
t = calc_crc6(ydec,qra_K-1);
if (t!=ydec[k]) // error detected - crc doesn't matches
nerrs += 1;
else
if (diff) { // decoded message is not equal to the transmitted one but
// the crc test passed
// add as undetected error
nerrsu += 1;
nerrs += 1;
// uncomment to see what the undetected error pattern looks like
//printword("U", ydec);
}
}
else
for (k=0;k<qra_K;k++)
if (ydec[k]!=x[k]) { // decoded msg differs from the transmitted one
nerrsu += 1; // it's a false decode
nerrs += 1;
// uncomment to see what the undetected error pattern looks like
// printword("U", ydec);
break;
}
}
else // failed to converge to a solution within the given number of iterations
nerrs++;
nt = nt+1;
pdata->nt=nt;
pdata->nerrs=nerrs;
pdata->nerrsu=nerrsu;
}
pdata->done=1;
#if _WIN32
_endthread();
#endif
}
#if defined(__linux__) || ( defined(__MINGW32__) || defined (__MIGW64__) )
void *wer_test_pthread(void *p)
{
wer_test_thread ((wer_test_ds *)p);
return 0;
}
#endif
void ix_mask(const qracode *pcode, float *r, const int *mask, const int *x)
{
// mask intrinsic information (channel observations) with a priori knowledge
int k,kk, smask;
const int qra_K=pcode->K;
const int qra_M=pcode->M;
const int qra_m=pcode->m;
for (k=0;k<qra_K;k++) {
smask = mask[k];
if (smask) {
for (kk=0;kk<qra_M;kk++)
if (((kk^x[k])&smask)!=0)
*(PD_ROWADDR(r,qra_M,k)+kk) = 0.f;
pd_norm(PD_ROWADDR(r,qra_M,k),qra_m);
}
}
}
int wer_test_proc(const qracode *pcode, int nthreads, int chtype, int ap_index, float *EbNodB, int *nerrstgt, int nitems)
{
int k,nn,j,nt,nerrs,nerrsu,nd;
int cini,cend;
char fnameout[128];
FILE *fout;
wer_test_ds wt[NTHREADS_MAX];
float pe,avgt;
nn = sizeof(EbNodB)/sizeof(float); // size of the EbNo array to test
if (nthreads>NTHREADS_MAX) {
printf("Error: nthreads should be <=%d\n",NTHREADS_MAX);
return -1;
}
sprintf(fnameout,"%s%s%s",
fnameout_pfx[chtype],
pcode->name,
fnameout_sfx[ap_index]);
fout = fopen(fnameout,"w");
fprintf(fout,"# Channel (0=AWGN,1=Rayleigh), Eb/No (dB), Transmitted codewords, Errors, Undetected Errors, Avg dec. time (ms), WER\n");
printf("\nTesting the code %s over the %s channel\nSimulation data will be saved to %s\n",
pcode->name,
chtype==CHANNEL_AWGN?"AWGN":"Rayleigh",
fnameout);
fflush (stdout);
// init fixed thread parameters and preallocate buffers
for (j=0;j<nthreads;j++) {
wt[j].channel_type=chtype;
wt[j].ap_index = ap_index;
wt[j].pcode = pcode;
wt[j].x = (int*)malloc(pcode->K*sizeof(int));
wt[j].y = (int*)malloc(pcode->N*sizeof(int));
wt[j].ydec = (int*)malloc(pcode->N*sizeof(int));
wt[j].qra_v2cmsg = (float*)malloc(pcode->NMSG*pcode->M*sizeof(float));
wt[j].qra_c2vmsg = (float*)malloc(pcode->NMSG*pcode->M*sizeof(float));
wt[j].rp = (float*)malloc(pcode->N*pcode->M*sizeof(float));
wt[j].rq = (float*)malloc(pcode->N*pcode->M*sizeof(float));
wt[j].chp = (float*)malloc(pcode->N*sizeof(float));
wt[j].chq = (float*)malloc(pcode->N*sizeof(float));
wt[j].r = (float*)malloc(pcode->N*pcode->M*sizeof(float));
wt[j].ix = (float*)malloc(pcode->N*pcode->M*sizeof(float));
wt[j].ex = (float*)malloc(pcode->N*pcode->M*sizeof(float));
}
for (k=0;k<nitems;k++) {
printf("\nTesting at Eb/No=%4.1f dB...",EbNodB[k]);
fflush (stdout);
for (j=0;j<nthreads;j++) {
wt[j].EbNodB=EbNodB[k];
wt[j].nt=0;
wt[j].nerrs=0;
wt[j].nerrsu=0;
wt[j].done = 0;
wt[j].stop = 0;
#if defined(__linux__) || ( defined(__MINGW32__) || defined (__MIGW64__) )
if (pthread_create (&wt[j].thread, 0, wer_test_pthread, &wt[j])) {
perror ("Creating thread: ");
exit (255);
}
#else
_beginthread((void*)(void*)wer_test_thread,0,&wt[j]);
#endif
}
nd = 0;
cini = GetTickCount();
while (1) {
// count errors
nerrs = 0;
for (j=0;j<nthreads;j++)
nerrs += wt[j].nerrs;
// stop the working threads
// if number of errors reached at this Eb/No value
if (nerrs>=nerrstgt[k]) {
for (j=0;j<nthreads;j++)
wt[j].stop = 1;
break;
}
else { // continue with the simulation
Sleep(2);
nd = (nd+1)%100;
if (nd==0) {
printf(".");
fflush (stdout);
}
}
}
cend = GetTickCount();
// wait for the working threads to exit
for (j=0;j<nthreads;j++)
#if defined(__linux__) || ( defined(__MINGW32__) || defined (__MIGW64__) )
{
void *rc;
if (pthread_join (wt[j].thread, &rc)) {
perror ("Waiting working threads to exit");
exit (255);
}
}
#else
while(wt[j].done==0)
Sleep(1);
#endif
printf("\n");
fflush (stdout);
// compute the total number of transmitted codewords
// the total number of errors and the total number of undetected errors
nt = 0;
nerrs =0;
nerrsu = 0;
for (j=0;j<nthreads;j++) {
nt += wt[j].nt;
nerrs += wt[j].nerrs;
nerrsu += wt[j].nerrsu;
}
pe = 1.0f*nerrs/nt; // word error rate
avgt = 1.0f*(cend-cini)/nt; // average time per decode (ms)
printf("Elapsed Time=%6.1fs (%5.2fms/word)\nTransmitted=%8d - Errors=%6d - Undetected=%3d - WER=%.2e\n",
0.001f*(cend-cini),
avgt, nt, nerrs, nerrsu, pe);
fflush (stdout);
// save simulation data to output file
fprintf(fout,"%01d %.2f %d %d %d %.2f %.2e\n",
chtype,
EbNodB[k],
nt,
nerrs,
nerrsu,
avgt,
pe);
}
fclose(fout);
return 0;
}
const qracode *codetotest[] = {
&qra_12_63_64_irr_b,
&qra_13_64_64_irr_e
};
void syntax(void)
{
printf("\nQ-ary Repeat-Accumulate Code Word Error Rate Simulator\n");
printf("2016, Nico Palermo - IV3NWV\n\n");
printf("Syntax: qracodes [-q<code_index>] [-t<threads>] [-c<ch_type>] [-a<ap_index>] [-f<fnamein>[-h]\n");
printf("Options: \n");
printf(" -q<code_index>: code to simulate. 0=qra_12_63_64_irr_b\n");
printf(" 1=qra_13_64_64_irr_e (default)\n");
printf(" -t<threads> : number of threads to be used for the simulation [1..24]\n");
printf(" (default=8)\n");
printf(" -c<ch_type> : channel_type. 0=AWGN 1=Rayleigh \n");
printf(" (default=AWGN)\n");
printf(" -a<ap_index> : amount of a-priori information provided to decoder. \n");
printf(" 0= No a-priori (default)\n");
printf(" 1= 28 bit \n");
printf(" 2= 44 bit \n");
printf(" 3= 56 bit \n");
printf(" -f<fnamein> : name of the file containing the Eb/No values to be simulated\n");
printf(" (default=ebnovalues.txt)\n");
printf(" This file should contain lines in this format:\n");
printf(" # Eb/No(dB) Target Errors\n");
printf(" 0.1 5000\n");
printf(" 0.6 5000\n");
printf(" 1.1 1000\n");
printf(" 1.6 1000\n");
printf(" ...\n");
printf(" (lines beginning with a # are treated as comments\n\n");
}
#define SIM_POINTS_MAX 20
int main(int argc, char* argv[])
{
float EbNodB[SIM_POINTS_MAX];
int nerrstgt[SIM_POINTS_MAX];
FILE *fin;
char fnamein[128]= "ebnovalues.txt";
char buf[128];
int nitems = 0;
int code_idx = 1;
int nthreads = 8;
int ch_type = CHANNEL_AWGN;
int ap_index = AP_NONE;
// parse command line
while(--argc) {
argv++;
if (strncmp(*argv,"-h",2)==0) {
syntax();
return 0;
}
else
if (strncmp(*argv,"-q",2)==0) {
code_idx = (int)atoi((*argv)+2);
if (code_idx>1) {
printf("Invalid code index\n");
syntax();
return -1;
}
}
else
if (strncmp(*argv,"-t",2)==0) {
nthreads = (int)atoi((*argv)+2);
printf("nthreads = %d\n",nthreads);
if (nthreads>NTHREADS_MAX) {
printf("Invalid number of threads\n");
syntax();
return -1;
}
}
else
if (strncmp(*argv,"-c",2)==0) {
ch_type = (int)atoi((*argv)+2);
if (ch_type>CHANNEL_RAYLEIGH) {
printf("Invalid channel type\n");
syntax();
return -1;
}
}
else
if (strncmp(*argv,"-a",2)==0) {
ap_index = (int)atoi((*argv)+2);
if (ap_index>AP_56) {
printf("Invalid a-priori information index\n");
syntax();
return -1;
}
}
else
if (strncmp(*argv,"-f",2)==0) {
strncpy(fnamein,(*argv)+2,127);
}
else
if (strncmp(*argv,"-h",2)==0) {
syntax();
return -1;
}
else {
printf("Invalid option\n");
syntax();
return -1;
}
}
// parse points to be simulated from the input file
fin = fopen(fnamein,"r");
if (!fin) {
printf("Can't open file: %s\n",fnamein);
syntax();
}
while (fgets(buf,128,fin)!=0)
if (*buf=='#' || *buf=='\n' )
continue;
else
if (nitems==SIM_POINTS_MAX)
break;
else
if (sscanf(buf,"%f %u",&EbNodB[nitems],&nerrstgt[nitems])!=2) {
printf("Invalid input file format\n");
syntax();
return -1;
}
else
nitems++;
fclose(fin);
if (nitems==0) {
printf("No Eb/No point specified in file %s\n",fnamein);
syntax();
return -1;
}
printf("\nQ-ary Repeat-Accumulate Code Word Error Rate Simulator\n");
printf("2016, Nico Palermo - IV3NWV\n\n");
printf("Nthreads = %d\n",nthreads);
printf("Channel = %s\n",ch_type==CHANNEL_AWGN?"AWGN":"Rayleigh");
printf("Codename = %s\n",codetotest[code_idx]->name);
printf("A-priori = %s\n",ap_str[ap_index]);
printf("Eb/No input file = %s\n\n",fnamein);
wer_test_proc(codetotest[code_idx], nthreads, ch_type, ap_index, EbNodB, nerrstgt, nitems);
return 0;
}
|