1 /*
2 * Copyright 2018 Oticon A/S
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #include "modem_if.h"
7 #include "bs_pc_base.h"
8 #include "bs_pc_base.h"
9 #include "bs_pc_2G4_utils.h"
10 #include "bs_rand_main.h"
11 #include <stdlib.h>
12 #include <stdio.h>
13
14 #ifdef BASIC
15 //compile as
16 /* gcc -DBASIC test_ber.c ../modem_BLE_simple.c ../modem_BLE_simple_args.c -I../../../ext_2G4_libPhyComv1/src/ -I../../../libRandv2/src/ -I../../../libPhyComv1/src/ -I../../../ext_2G4_phy_v1/src/ -I../../../libUtilv1/src/ ../../../../lib/libUtilv1.a ../../../../lib/libPhyComv1.a ../../../../lib/libRandv2.a ../../../../lib/lib2G4PhyComv1.a -lm -o test_ber -std=c99 -Wall -pedantic -g
17 */
18 //run as ./test_ber > BER.txt
19 //the results to be compared using matlab/BER_test.m
20
main(int argc,char ** argv)21 int main(int argc, char**argv){
22
23 double SNR;
24 double BER;
25
26 void* ModemObj;
27 p2G4_radioparams_t RxRadioParams;
28
29 ModemObj = modem_init(argc-1, &argv[1], 0, 1);
30
31 for ( SNR = -10; SNR < 30; SNR += 0.01 ) {
32 uint32_t BER_i = modem_digital_perf_ber(ModemObj, &RxRadioParams, SNR);
33 BER = ((double)BER_i)/RAND_PROB_1;
34 fprintf(stdout,"%e %e\n",SNR,BER);
35 }
36
37 modem_delete(ModemObj);
38 }
39
40 #else
41
42 //compile as
43 /* gcc test_ber.c ../modem_BLE_simple.c ../modem_BLE_simple_args.c -I../../../ext_2G4_libPhyComv1/src/ -I../../../libRandv2/src/ -I../../../libPhyComv1/src/ -I../../../ext_2G4_phy_v1/src/ -I../../../libUtilv1/src/ ../../../../lib/libUtilv1.a ../../../../lib/libPhyComv1.a ../../../../lib/libRandv2.a ../../../../lib/lib2G4PhyComv1.a -lm -o test_ber -std=c99 -Wall -pedantic -g
44 */
45 //run as ./test_ber > BER.txt
46 //the results to be compared using matlab/BER_test2.m
47
main(int argc,char ** argv)48 int main(int argc, char**argv){
49 #define Ndevices 15
50
51 uint device_nbr = 0;
52 uint nbr_devices = Ndevices;
53 void* ModemObj;
54 double *RxPowers;
55 tx_l_c_t Tx_List_container;
56 uint desired_tx_nbr;
57 p2G4_radioparams_t RxRadioParams;
58
59 ModemObj = modem_init(argc-1, &argv[1], device_nbr, nbr_devices);
60
61 Tx_List_container.tx_list = calloc(sizeof(tx_el_t), Ndevices);
62 Tx_List_container.used = calloc(sizeof(tx_state_t), Ndevices);
63 RxPowers = calloc(sizeof(double),Ndevices);
64
65 desired_tx_nbr = 2;
66 Tx_List_container.used[2] = 1;
67 RxRadioParams.modulation = P2G4_MOD_BLE;
68 p2G4_freq_from_d( 2450, 0, &RxRadioParams.center_freq );
69
70 for ( double level = -110; level < -60; level += 0.2 ) {
71 double OutputSNR;
72 double Output_RSSI_power_level;
73
74 RxPowers[2] = level;
75 modem_analog_rx(ModemObj, &RxRadioParams, &OutputSNR, &Output_RSSI_power_level,
76 RxPowers, &Tx_List_container, desired_tx_nbr);
77
78 uint32_t BER_i = modem_digital_perf_ber(ModemObj, &RxRadioParams, OutputSNR);
79 double BER = ((double)BER_i)/RAND_PROB_1;
80 fprintf(stdout,"%e %e %e\n",level, OutputSNR, BER);
81 }
82
83 modem_delete(ModemObj);
84
85 free(Tx_List_container.tx_list);
86 free(Tx_List_container.used);
87 free(RxPowers);
88 }
89
90 #endif
91