Skip to content

Commit

Permalink
Add uniform and cartesian_product methods for PAM constellation
Browse files Browse the repository at this point in the history
generation
  • Loading branch information
eliasrg committed Sep 25, 2017
1 parent a3ab02e commit d6a2f11
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions code/separate/coding/PAM.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,40 @@

class Constellation:
"""A mapping m: ℤ2^n → ℝ^K."""
@classmethod
def uniform(cls, n):
"Equidistant points (K = 1)."

# {-(2^n - 1), -(2^n - 3), ..., 2^n - 3, 2^n - 1} (2^n integers)
ints = 2 * np.arange(2**n) - (2**n - 1)

# Normalize
points = ints / np.sqrt((ints**2).mean())

return cls(n, 1, [(p,) for p in points])

@classmethod
def cartesian_product(cls, *constellations, repeat=None):
# Cartesian power
if repeat is not None:
(constellation,) = constellations
return cls.cartesian_product(*(repeat * [constellation]))

if len(constellations) == 1:
return constellations[0]
else:
last = constellations[-1]
init = constellations[:-1]
inner = cls.cartesian_product(*init)

for p, q in zip(inner.points, last.points):
assert type(p) == type(q) == tuple

points = [p + q # Concatenation of tuples
for p in inner.points for q in last.points]

return cls(inner.n + last.n, inner.K + last.K, points)

def __init__(self, n, K, points):
self.n = n
self.K = K
Expand Down

0 comments on commit d6a2f11

Please sign in to comment.