Punctured code: Difference between revisions

Content deleted Content added
Kirlf (talk | contribs)
No edit summary
Kirlf (talk | contribs)
No edit summary
Line 14:
2011.
</ref>
 
==== Python example ====
<source lang="python">
import numpy as np
 
def puncturing(message, punct_vec):
shift = 0
N = len(punct_vec)
punctured = []
for idx, item in enumerate(message):
if punct_vec[idx-shift*N] == 1:
punctured.append(item)
if idx%N == 0:
shift = shift + 1
return np.array(punctured)
 
def depuncturing(punctured, punct_vec, shouldbe):
shift = 0
shift2 = 0
N = len(punct_vec)
depunctured = np.zeros((shouldbe,))
for idx, item in enumerate(depunctured):
if punct_vec[idx - shift*N] == 1:
depunctured[idx] = float(punctured[idx-shift2])
else:
shift2 = shift2 + 1
if idx%N == 0:
shift = shift + 1;
return depunctured
 
message = np.array([1, 2, 3, 4, 5, 6, 7, 8])
punct_vec = np.array([1, 1, 0])
punctured = puncturing(message, punct_vec)
print(punctured)
 
depunctured = depuncturing(punctured, punct_vec, len(message))
print(depunctured)
 
</source>
 
==See also==