add ofdm_utils
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bastian Bloessl <bloessl@ccs-labs.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "ofdm_utils.h"
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
ofdm_param::ofdm_param(ENCODING e) {
|
||||
encoding = e;
|
||||
|
||||
switch(e) {
|
||||
case BPSK_1_2:
|
||||
n_bpsc = 1;
|
||||
n_cbps = 48;
|
||||
n_dbps = 24;
|
||||
rate_field = 0x0D; // 0b00001101
|
||||
break;
|
||||
|
||||
case BPSK_3_4:
|
||||
n_bpsc = 1;
|
||||
n_cbps = 48;
|
||||
n_dbps = 36;
|
||||
rate_field = 0x0F; // 0b00001111
|
||||
break;
|
||||
|
||||
case QPSK_1_2:
|
||||
n_bpsc = 2;
|
||||
n_cbps = 96;
|
||||
n_dbps = 48;
|
||||
rate_field = 0x05; // 0b00000101
|
||||
break;
|
||||
|
||||
case QPSK_3_4:
|
||||
n_bpsc = 2;
|
||||
n_cbps = 96;
|
||||
n_dbps = 72;
|
||||
rate_field = 0x07; // 0b00000111
|
||||
break;
|
||||
|
||||
case QAM16_1_2:
|
||||
n_bpsc = 4;
|
||||
n_cbps = 192;
|
||||
n_dbps = 96;
|
||||
rate_field = 0x09; // 0b00001001
|
||||
break;
|
||||
|
||||
case QAM16_3_4:
|
||||
n_bpsc = 4;
|
||||
n_cbps = 192;
|
||||
n_dbps = 144;
|
||||
rate_field = 0x0B; // 0b00001011
|
||||
break;
|
||||
|
||||
case QAM64_2_3:
|
||||
n_bpsc = 6;
|
||||
n_cbps = 288;
|
||||
n_dbps = 192;
|
||||
rate_field = 0x01; // 0b00000001
|
||||
break;
|
||||
|
||||
case QAM64_3_4:
|
||||
n_bpsc = 6;
|
||||
n_cbps = 288;
|
||||
n_dbps = 216;
|
||||
rate_field = 0x03; // 0b00000011
|
||||
break;
|
||||
defaut:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ofdm_param::print_out() {
|
||||
std::cout << "OFDM Parameters:" << std::endl;
|
||||
std::cout << "endcoding :" << encoding << std::endl;
|
||||
std::cout << "rate_field :" << (int)rate_field << std::endl;
|
||||
std::cout << "n_bpsc :" << n_bpsc << std::endl;
|
||||
std::cout << "n_cbps :" << n_cbps << std::endl;
|
||||
std::cout << "n_dbps :" << n_dbps << std::endl;
|
||||
}
|
||||
|
||||
tx_param::tx_param(ofdm_param &ofdm, int psdu_length) {
|
||||
|
||||
psdu_size = psdu_length;
|
||||
|
||||
// number of symbols (17-11)
|
||||
n_sym = (int) ceil((16 + 8 * psdu_size + 6) / (double) ofdm.n_dbps);
|
||||
|
||||
// number of bits of the data field (17-12)
|
||||
n_data = n_sym * ofdm.n_dbps;
|
||||
|
||||
// number of padding bits (17-13)
|
||||
n_pad = n_data - (16 + 8 * psdu_size + 6);
|
||||
|
||||
n_encoded_bits = n_sym * ofdm.n_cbps;
|
||||
}
|
||||
void
|
||||
tx_param::print_out() {
|
||||
std::cout << "TX Parameters:" << std::endl;
|
||||
std::cout << "psdu_size: " << psdu_size << std::endl;
|
||||
std::cout << "n_sym: " << n_sym << std::endl;
|
||||
std::cout << "n_data: " << n_data << std::endl;
|
||||
std::cout << "n_pad: " << n_pad << std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user