1 /*
2  * Copyright (c) 2007 - 2015 Joseph Gaeddert
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 //
24 // framesyncstats.c
25 //
26 // Default and generic frame statistics
27 //
28 
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <math.h>
33 #include <complex.h>
34 
35 #include "liquid.internal.h"
36 
37 framesyncstats_s framesyncstats_default = {
38     // signal quality
39     0.0f,                   // error vector magnitude
40     0.0f,                   // rssi
41     0.0f,                   // carrier frequency offset
42 
43     // demodulated frame symbols
44     NULL,                   // framesyms
45     0,                      // num_framesyms
46 
47     // modulation/coding scheme, etc.
48     LIQUID_MODEM_UNKNOWN,   // mod_scheme
49     0,                      // mod_bps
50     LIQUID_CRC_UNKNOWN,     // check
51     LIQUID_FEC_UNKNOWN,     // fec0
52     LIQUID_FEC_UNKNOWN      // fec1
53 };
54 
55 // initialize framesyncstats object on default
framesyncstats_init_default(framesyncstats_s * _stats)56 void framesyncstats_init_default(framesyncstats_s * _stats)
57 {
58     memmove(_stats, &framesyncstats_default, sizeof(framesyncstats_s));
59 }
60 // print framesyncstats object
framesyncstats_print(framesyncstats_s * _stats)61 void framesyncstats_print(framesyncstats_s * _stats)
62 {
63     // validate statistics object
64     if (_stats->mod_scheme >= LIQUID_MODEM_NUM_SCHEMES) {
65         fprintf(stderr,"error: framesyncstats_print(), invalid modulation scheme\n");
66         exit(1);
67      } else if (_stats->check >= LIQUID_CRC_NUM_SCHEMES) {
68         fprintf(stderr,"error: framesyncstats_print(), invalid CRC scheme\n");
69         exit(1);
70      } else if (_stats->fec0 >= LIQUID_FEC_NUM_SCHEMES) {
71         fprintf(stderr,"error: framesyncstats_print(), invalid FEC scheme (inner)\n");
72         exit(1);
73      } else if (_stats->fec1 >= LIQUID_FEC_NUM_SCHEMES) {
74         fprintf(stderr,"error: framesyncstats_print(), invalid FEC scheme (outer)\n");
75         exit(1);
76     }
77 
78     printf("    EVM                 :   %12.8f dB\n", _stats->evm);
79     printf("    rssi                :   %12.8f dB\n", _stats->rssi);
80     printf("    carrier offset      :   %12.8f Fs\n", _stats->cfo);
81     printf("    num symbols         :   %u\n", _stats->num_framesyms);
82     printf("    mod scheme          :   %s (%u bits/symbol)\n",
83             modulation_types[_stats->mod_scheme].name,
84             _stats->mod_bps);
85     printf("    validity check      :   %s\n", crc_scheme_str[_stats->check][0]);
86     printf("    fec (inner)         :   %s\n", fec_scheme_str[_stats->fec0][0]);
87     printf("    fec (outer)         :   %s\n", fec_scheme_str[_stats->fec1][0]);
88 }
89 
90