Skip to content

Commit 152346a

Browse files
committed
modulation: python3/numpy fixes on modulate method
Use numpy's vectorize to create a mapping function, then evaluate that out to baseband_symbols The original version throws indexing errors.
1 parent 9e91c12 commit 152346a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

commpy/modulation.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
1717
"""
1818
from numpy import arange, array, zeros, pi, cos, sin, sqrt, log2, argmin, \
19-
hstack, repeat, tile, dot, sum, shape, concatenate, exp, log
19+
hstack, repeat, tile, dot, sum, shape, concatenate, exp, \
20+
log, vectorize
2021
from itertools import product
2122
from commpy.utilities import bitarray2dec, dec2bitarray
2223
from numpy.fft import fft, ifft
@@ -39,10 +40,10 @@ def modulate(self, input_bits):
3940
Modulated complex symbols.
4041
4142
"""
43+
mapfunc = vectorize(lambda i:
44+
self.constellation[bitarray2dec(input_bits[i:i+self.num_bits_symbol])])
4245

43-
index_list = map(lambda i: bitarray2dec(input_bits[i:i+self.num_bits_symbol]), \
44-
xrange(0, len(input_bits), self.num_bits_symbol))
45-
baseband_symbols = self.constellation[index_list]
46+
baseband_symbols = mapfunc(arange(0, len(input_bits), self.num_bits_symbol))
4647

4748
return baseband_symbols
4849

0 commit comments

Comments
 (0)