nr_polar_encoder.c 2.63 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
#include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"

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

	/*
	 * Bytewise operations
	 */

	//Calculate CRC.
	nr_matrix_multiplication_uint8_t_1D_uint8_t_2D(input, polarParams->crc_generator_matrix,
36
37
			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
38
39

	//Attach CRC to the Transport Block. (a to b)
40
41
42
	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
43
44

	//Interleaving (c to c')
45
	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
46
47

	//Bit insertion (c' to u)
48
	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
49
50
51
			polarParams->Q_I_N, polarParams->Q_PC_N, polarParams->n_pc);

	//Encoding (u to d)
52
53
	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
54
55
56

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