@@ -203,6 +203,10 @@ class PSKModem(Modem):
203203 def __init__ (self , m ):
204204 """ Creates a Phase Shift Keying (PSK) Modem object. """
205205
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+
206210 super ().__init__ (exp (1j * arange (0 , 2 * pi , 2 * pi / m )))
207211
208212
@@ -232,6 +236,7 @@ class QAMModem(Modem):
232236 ------
233237 ValueError
234238 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.
235240 """
236241
237242 def __init__ (self , m ):
@@ -240,13 +245,20 @@ def __init__(self, m):
240245 Parameters
241246 ----------
242247 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).
244249
250+ Raises
251+ ------
252+ ValueError
253+ If m would lead to an non-square QAM.
245254 """
246255
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+
248260 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 )
250262 super ().__init__ (constellation )
251263
252264
0 commit comments