File: tqam16.c

package info (click to toggle)
codec2 1.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 121,056 kB
  • sloc: ansic: 414,118; sh: 2,612; objc: 2,574; python: 2,105; cpp: 2,091; asm: 683; makefile: 598
file content (37 lines) | stat: -rw-r--r-- 1,114 bytes parent folder | download
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
/*---------------------------------------------------------------------------*\

  FILE........: tqam16.c
  AUTHOR......: David Rowe
  DATE CREATED: August 2020

  Simple sanity check for QAM16 symbol mapping.

\*---------------------------------------------------------------------------*/

#include <stdio.h>
#include <string.h>
#include "ofdm_internal.h"

int main(void) {
    int c;
    for(c=0; c<16; c++) {
        int tx_bits[4], rx_bits[4];
        for(int i=0; i<4; i++)
            tx_bits[i] = (c >> (3-i)) & 0x1;
        complex float symbol = qam16_mod(tx_bits);
        qam16_demod(symbol, rx_bits);
        if (memcmp(tx_bits, rx_bits, 4)) {
            fprintf(stderr, "FAIL on %d!\ntx_bits: ",c);
            for(int i=0; i<4; i++) fprintf(stderr, "%d ", tx_bits[i]);
            fprintf(stderr, "%f %f\nrx_bits: ", creal(symbol), cimag(symbol));
            for(int i=0; i<4; i++) fprintf(stderr, "%d ", rx_bits[i]);
            fprintf(stderr, "%f %f\n", creal(symbol), cimag(symbol));
            return 1;
        }
    }

    fprintf(stderr, "%d tested OK...\nPASS!\n", c);
    return 0;
}