@@ -203,6 +203,10 @@ class PSKModem(Modem):
203
203
def __init__ (self , m ):
204
204
""" Creates a Phase Shift Keying (PSK) Modem object. """
205
205
206
+ num_bits_symbol = log2 (m )
207
+ if num_bits_symbol != int (num_bits_symbol ):
208
+ raise ValueError ('Constellation length must be a power of 2.' )
209
+
206
210
super ().__init__ (exp (1j * arange (0 , 2 * pi , 2 * pi / m )))
207
211
208
212
@@ -232,6 +236,7 @@ class QAMModem(Modem):
232
236
------
233
237
ValueError
234
238
If the constellation is changed to an array-like with length that is not a power of 2.
239
+ If the parameter m would lead to an non-square QAM during initialization.
235
240
"""
236
241
237
242
def __init__ (self , m ):
@@ -240,13 +245,20 @@ def __init__(self, m):
240
245
Parameters
241
246
----------
242
247
m : int
243
- Size of the QAM constellation.
248
+ Size of the QAM constellation. Must lead to a square QAM (ie sqrt(m) is an integer).
244
249
250
+ Raises
251
+ ------
252
+ ValueError
253
+ If m would lead to an non-square QAM.
245
254
"""
246
255
247
- num_symb_pam = int (sqrt (m ))
256
+ num_symb_pam = sqrt (m )
257
+ if num_symb_pam != int (num_symb_pam ):
258
+ raise ValueError ('m must lead to a square QAM.' )
259
+
248
260
pam = arange (- num_symb_pam + 1 , num_symb_pam , 2 )
249
- constellation = tile (hstack ((pam , pam [::- 1 ])), num_symb_pam // 2 ) * 1j + pam .repeat (num_symb_pam )
261
+ constellation = tile (hstack ((pam , pam [::- 1 ])), int ( num_symb_pam ) // 2 ) * 1j + pam .repeat (num_symb_pam )
250
262
super ().__init__ (constellation )
251
263
252
264
0 commit comments