Created
September 10, 2020 18:44
-
-
Save mobilinkd/d7f3943b4cfb76d582239c1d7f7276c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# *************************************************************************** | |
# * Copyright (C) 2016 Mobilinkd LLC (rob@mobilinkd.com) * | |
# * * | |
# * 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 2 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, write to the * | |
# * Free Software Foundation, Inc., * | |
# * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
# *************************************************************************** | |
class PolynomialInterleaver(object): | |
"""Polynomial bit interleaver. Default to 80. | |
Valid LTE polynomials can be found here: | |
https://github.com/supermihi/lpdec/blob/master/lpdec/codes/interleaver.py#L264 | |
""" | |
def __init__(self, f1 = 11, f2 = 20, k = 80): | |
self.f1 = f1 | |
self.f2 = f2 | |
self.K = k | |
def index(self, i): | |
return ((self.f1 * i) + (self.f2 * i * i)) % self.K | |
def interleave(self, data): | |
result = np.zeros(self.K, dtype = data.dtype) | |
for i in range(len(data)): | |
result[self.index(i)] = data[i] | |
return result | |
def deinterleave(self, data): | |
result = np.zeros(len(data), dtype = data.dtype) | |
for i in range(len(data)): | |
if i == self.K: break | |
result[i] = data[self.index(i)] | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment