nr_polar_encoder.c 2.68 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

Guy De Souza's avatar
Guy De Souza committed
22 23 24
#include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
#include "PHY/CODING/nrPolar_tools/nr_polar_pbch_defs.h"

25 26 27 28 29
void polar_encoder(
		uint8_t *input,
		uint8_t *output,
		t_nrPolar_params *polarParams)
{
Guy De Souza's avatar
Guy De Souza committed
30 31 32 33 34 35 36

	/*
	 * Bytewise operations
	 */

	//Calculate CRC.
	nr_matrix_multiplication_uint8_t_1D_uint8_t_2D(input, polarParams->crc_generator_matrix,
37 38
			polarParams->nr_polar_crc, polarParams->payloadBits, polarParams->crcParityBits);
	for (uint8_t i = 0; i < polarParams->crcParityBits; i++) polarParams->nr_polar_crc[i] = (polarParams->nr_polar_crc[i] % 2);
Guy De Souza's avatar
Guy De Souza committed
39 40

	//Attach CRC to the Transport Block. (a to b)
41 42 43
	for (uint16_t i = 0; i < polarParams->payloadBits; i++) polarParams->nr_polar_b[i] = input[i];
	for (uint16_t i = polarParams->payloadBits; i < polarParams->K; i++)
		polarParams->nr_polar_b[i]= polarParams->nr_polar_crc[i-(polarParams->payloadBits)];
Guy De Souza's avatar
Guy De Souza committed
44 45

	//Interleaving (c to c')
46
	nr_polar_interleaver(polarParams->nr_polar_b, polarParams->nr_polar_cPrime, polarParams->interleaving_pattern, polarParams->K);
Guy De Souza's avatar
Guy De Souza committed
47 48

	//Bit insertion (c' to u)
49
	nr_polar_bit_insertion(polarParams->nr_polar_cPrime, polarParams->nr_polar_u, polarParams->N, polarParams->K,
Guy De Souza's avatar
Guy De Souza committed
50 51 52
			polarParams->Q_I_N, polarParams->Q_PC_N, polarParams->n_pc);

	//Encoding (u to d)
53 54
	nr_matrix_multiplication_uint8_t_1D_uint8_t_2D(polarParams->nr_polar_u, polarParams->G_N, polarParams->nr_polar_d, polarParams->N, polarParams->N);
	for (uint16_t i = 0; i < polarParams->N; i++) polarParams->nr_polar_d[i] = (polarParams->nr_polar_d[i] % 2);
Guy De Souza's avatar
Guy De Souza committed
55 56 57

	//Rate matching
	//Sub-block interleaving (d to y) and Bit selection (y to e)
58
	nr_polar_rate_matcher(polarParams->nr_polar_d, output, polarParams->rate_matching_pattern, polarParams->encoderLength);
Guy De Souza's avatar
Guy De Souza committed
59
}