<commit_before>// 
// modem_demodulate_arb_gentab.c
//
// Generate fast demodulation tables for arbitrary modems
//

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <getopt.h>
#include "liquid.h"

#define OUTPUT_FILENAME "modem_demodulate_arb_gentab.m"

// print usage/help message
void usage()
{
    printf("sandbox/modem_demodulate_arb_gentab [options]\n");
    printf("  u/h   : print usage\n");
    printf("  m     : modulation scheme (qpsk default)\n");
    liquid_print_modulation_schemes();
}

// search for nearest constellation points to reference points
void modem_arbref_search(float complex * _c,
                         unsigned int _M,
                         float complex * _cref,
                         unsigned int _p,
                         unsigned char * _index,
                         unsigned int _s);

// search for nearest constellation points to single reference point
void modem_arbref_search_point(float complex * _c,
                               unsigned int _M,
                               float complex _cref,
                               unsigned char * _index,
                               unsigned int _s);

// find unassigned constellation points
unsigned int modem_arbref_search_unassigned(unsigned char * _index,
                                            unsigned int _M,
                                            unsigned int _p,
                                            unsigned int _s,
                                            unsigned char * _assigned);

int main(int argc, char*argv[])
{
    // create mod/demod objects
    unsigned int bps=6;
    modulation_scheme ms = LIQUID_MODEM_ARB64VT;
    unsigned int p=16;  // reference constellation size
    unsigned int s=12;  // number of points per reference

    int dopt;
    while ((dopt = getopt(argc,argv,"uhm:")) != EOF) {
        switch (dopt) {
        case 'u':
        case 'h': usage(); return 0;
        case 'm':
            liquid_getopt_str2modbps(optarg, &ms, &bps);
            if (ms == LIQUID_MODEM_UNKNOWN) {
                fprintf(stderr,"error: %s, unknown/unsupported modulation scheme '%s'\n", argv[0], optarg);
                return 1;
            }
            break;
        default:
            fprintf(stderr,"error: %s, unknown option\n", argv[0]);
            usage();
            return 1;
        }
    }

    // validate input

    unsigned int i;
    unsigned int j;

#if 0
    // generate the constellation
    modem q = modem_create(ms, bps);
    bps = modem_get_bps(q);
    float complex constellation[M];
    unsigned int M = 1 << bps;
    for (i=0; i<M; i++)
        modem_modulate(q, i, &c[i]);
    modem_destroy(q);
#else
    // initialize constellation (spiral)
    unsigned int M = 1 << bps;
    float complex constellation[M];
    float gamma = 0.0f;     // scaling factor
    for (i=0; i<M; i++) {
        float r   = (float)i / logf((float)M) + 4.0f;
        float phi = (float)i / logf((float)M);
        constellation[i] = r * cexpf(_Complex_I*phi);<commit_msg>sandbox: adding command-line options to arbitrary modem gentab<commit_after>// 
// modem_demodulate_arb_gentab.c
//
// Generate fast demodulation tables for arbitrary modems
//

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <getopt.h>
#include "liquid.h"

#define OUTPUT_FILENAME "modem_demodulate_arb_gentab.m"

// print usage/help message
void usage()
{
    printf("sandbox/modem_demodulate_arb_gentab [options]\n");
    printf("  u/h   : print usage\n");
    printf("  p     : reference constellation size, fixed at 16\n");
    printf("  s     : number of associated points per reference, default: 12\n");
    printf("  m     : modulation scheme (qpsk default)\n");
    liquid_print_modulation_schemes();
}

// search for nearest constellation points to reference points
void modem_arbref_search(float complex * _c,
                         unsigned int _M,
                         float complex * _cref,
                         unsigned int _p,
                         unsigned char * _index,
                         unsigned int _s);

// search for nearest constellation points to single reference point
void modem_arbref_search_point(float complex * _c,
                               unsigned int _M,
                               float complex _cref,
                               unsigned char * _index,
                               unsigned int _s);

// find unassigned constellation points
unsigned int modem_arbref_search_unassigned(unsigned char * _index,
                                            unsigned int _M,
                                            unsigned int _p,
                                            unsigned int _s,
                                            unsigned char * _assigned);

int main(int argc, char*argv[])
{
    // create mod/demod objects
    unsigned int bps=6;
    modulation_scheme ms = LIQUID_MODEM_ARB64VT;
    unsigned int p=16;  // reference constellation size
    unsigned int s=12;  // number of points per reference

    int dopt;
    while ((dopt = getopt(argc,argv,"uhp:s:m:")) != EOF) {
        switch (dopt) {
        case 'u':
        case 'h': usage(); return 0;
        case 'p': /* p = atoi(optarg); */   break;
        case 's': s = atoi(optarg);         break;
        case 'm':
            liquid_getopt_str2modbps(optarg, &ms, &bps);
            if (ms == LIQUID_MODEM_UNKNOWN) {
                fprintf(stderr,"error: %s, unknown/unsupported modulation scheme '%s'\n", argv[0], optarg);
                return 1;
            }
            break;
        default:
            fprintf(stderr,"error: %s, unknown option\n", argv[0]);
            usage();
            return 1;
        }
    }

    // validate input

    unsigned int i;
    unsigned int j;

#if 1
    // generate the constellation
    modem q = modem_create(ms, bps);
    bps = modem_get_bps(q);
    unsigned int M = 1 << bps;
    float complex constellation[M];
    for (i=0; i<M; i++)
        modem_modulate(q, i, &constellation[i]);
    modem_destroy(q);
#else
    // initialize constellation (spiral)
    unsigned int M = 1 << bps;
    float complex constellation[M];
    float gamma = 0.0f;     // scaling factor
    for (i=0; i<M; i++) {
        float r   = (float)i / logf((float)M) + 4.0f;
        float phi = (float)i / logf((float)M);
        constellation[i] = r * cexpf(_Complex_I*phi);
{'fraction_non_alphanumeric': 0.10430874147551147, 'fraction_numerical': 0.007439553626782393, 'mean_word_length': 1.7802671262386902, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2349399', 'n_tokens_mistral': 1956, 'n_tokens_neox': 1863, 'n_words': 540}