From ac7c48b4dee99d4c772f133d70d8d1b38262fcd2 Mon Sep 17 00:00:00 2001 From: Author Name Date: Fri, 7 Jul 2023 12:20:59 +0930 Subject: shallow zip-file copy from codec2 e9d726bf20 --- src/fsk_put_test_bits.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 src/fsk_put_test_bits.c (limited to 'src/fsk_put_test_bits.c') diff --git a/src/fsk_put_test_bits.c b/src/fsk_put_test_bits.c new file mode 100644 index 0000000..7b2da34 --- /dev/null +++ b/src/fsk_put_test_bits.c @@ -0,0 +1,170 @@ +/*---------------------------------------------------------------------------*\ + + FILE........: fsk_get_test_bits.c + AUTHOR......: Brady O'Brien + DATE CREATED: January 2016 + + Generates a pseudorandom sequence of bits for testing of fsk_mod and + fsk_demod. + +\*---------------------------------------------------------------------------*/ + + +/* + Copyright (C) 2016 David Rowe + + All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 2.1, as + published by the Free Software Foundation. This program 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 Lesser General Public License + along with this program; if not, see . +*/ + +#include +#include +#include +#include +#include "fsk.h" + +#define TEST_FRAME_SIZE 100 /* must match fsk_get_test_bits.c */ + +#define VALID_PACKET_BER_THRESH 0.1 + +int main(int argc,char *argv[]){ + int bitcnt,biterr,i,errs,packetcnt; + int framesize = TEST_FRAME_SIZE; + float valid_packet_ber_thresh = VALID_PACKET_BER_THRESH; + int packet_pass_thresh = 0; + float ber_pass_thresh = 0; + FILE *fin; + uint8_t *bitbuf_tx, *bitbuf_rx, abyte, abit; + int verbose = 1; + int packed_in = 0; + + char usage[] = "usage: %s [-f frameSizeBits] [-t VaildFrameBERThreshold] [-b BERPass] [-p numPacketsPass] [-k] InputOneBitPerByte\n" + " [-k] packet byte input\n"; + + int opt; + while ((opt = getopt(argc, argv, "f:b:p:hqt:k")) != -1) { + switch (opt) { + case 't': + valid_packet_ber_thresh = atof(optarg); + break; + case 'b': + ber_pass_thresh = atof(optarg); + break; + case 'p': + packet_pass_thresh = atoi(optarg); + break; + case 'f': + framesize = atoi(optarg); + break; + case 'q': + verbose = 0; + break; + case 'k': + packed_in = 1; + break; + case 'h': + default: + fprintf(stderr, usage, argv[0]); + exit(1); + } + } + if (argc == 1) { + fprintf(stderr, usage, argv[0]); + exit(1); + } + + int bits_per_byte = 1; + if (packed_in) { + if (framesize % 8) { + fprintf(stderr, "framesize (-f) must be a multiple of 8 for packed byte input (-k)\n"); + exit(1); + } + bits_per_byte = 8; + } + + char *fname = argv[optind++]; + if ((strcmp(fname,"-")==0) || (argc<2)){ + fin = stdin; + } else { + fin = fopen(fname,"r"); + } + + if(fin==NULL){ + fprintf(stderr,"Couldn't open input file: %s\n", argv[1]); + exit(1); + } + + /* allocate buffers for processing */ + bitbuf_tx = (uint8_t*)malloc(sizeof(uint8_t)*framesize); + bitbuf_rx = (uint8_t*)malloc(sizeof(uint8_t)*framesize); + + /* Generate known tx frame from known seed */ + srand(158324); + for(i=0; i0){ + + for (int b=0; b> ((bits_per_byte-1)-b)) & 0x1; + + /* update sliding window of input bits */ + + for(i=0; i= packet_pass_thresh) && (ber <= ber_pass_thresh)) { + fprintf(stderr,"PASS\n"); + return 0; + } + else { + fprintf(stderr,"FAIL\n"); + return 1; + } +} -- cgit v1.2.3