@@ -245,28 +245,28 @@ def de2bin(self, decs):
245245 for d in decs ]
246246 return bin_out
247247
248- def bin2de (self , b ):
249-
248+ def bin2de (self , bin_in ):
250249 ''' Converts values from binary to decimal representation.
251250 Parameters
252251 ----------
253- b : list of ints
252+ bin_in : list of ints
254253 Input binary values.
255254 Returns
256255 -------
257- s : list of ints
256+ dec_out : list of ints
258257 Output decimal values.
259258 '''
260259
261- s = []
262- m = self .N
263- for i in range ( int (len (b ) / m )):
264- outp = b [i * m :i * m + m ]
265- str_o = "" .join ([str (int (o )) for o in outp ])
266- if np .log2 (self .M )% 2 == 0 :
260+ dec_out = []
261+ N = self .N # bits per modulation symbol (local variables are tiny bit faster)
262+ Ndecs = int (len (bin_in ) / N ) # length of the decimal output
263+ for i in range (Ndecs ):
264+ bin_seq = bin_in [i * N :i * N + N ] # binary equivalent of the one decimal value
265+ str_o = "" .join ([str (int (b )) for b in bin_seq ]) # binary sequence to string
266+ if N % 2 == 0 :
267267 str_o = str_o [::- 1 ]
268- s .append (int (str_o , 2 ))
269- return s
268+ dec_out .append (int (str_o , 2 ))
269+ return dec_out
270270
271271 def plot_const (self ):
272272 ''' Plots signal constellation '''
@@ -318,10 +318,8 @@ def plot_const(self):
318318 plt .title (M + 'PSK, phase rotation: ' + str (round (self .phi , 5 ))+ \
319319 ', Mapping: ' + mapping + ', Input: ' + inputs )
320320 plt .show ()
321-
322-
323-
324-
321+
322+
325323class QAMModem (Modem ):
326324 def __init__ (self , M , gray_map = True , bin_input = True , soft_decision = True , bin_output = True ):
327325 super ().__init__ (M , gray_map , bin_input , soft_decision , bin_output )
@@ -359,7 +357,6 @@ def __gray_qam_arange(self):
359357
360358
361359 def de2bin (self , decs ):
362-
363360 ''' Converts values from decimal to binary representation.
364361 Parameters
365362 ----------
@@ -370,30 +367,29 @@ def de2bin(self, decs):
370367 bin_out : list of ints
371368 Output binary sequences.
372369 '''
373-
374370 bin_out = [np .binary_repr (d , width = self .N ) for d in decs ]
375371 return bin_out
376372
377- def bin2de (self , b ):
378-
373+ def bin2de (self , bin_in ):
379374 ''' Converts values from binary to decimal representation.
380375 Parameters
381376 ----------
382- b : list of ints
377+ bin_in : list of ints
383378 Input binary values.
384379 Returns
385380 -------
386- s : list of ints
381+ dec_out : list of ints
387382 Output decimal values.
388383 '''
389384
390- m = self .N
391- s = []
392- for i in range ( int (len (b ) / m )):
393- outp = b [i * m :i * m + m ]
394- str_o = "" .join ([str (int (o )) for o in outp ])
395- s .append (int (str_o , 2 ))
396- return s
385+ dec_out = []
386+ N = self .N # bits per modulation symbol (local variables are tiny bit faster)
387+ Ndecs = int (len (bin_in ) / N ) # length of the decimal output
388+ for i in range (Ndecs ):
389+ bin_seq = bin_in [i * N :i * N + N ] # binary equivalent of the one decimal value
390+ str_o = "" .join ([str (int (b )) for b in bin_seq ]) # binary sequence to string
391+ dec_out .append (int (str_o , 2 ))
392+ return dec_out
397393
398394
399395 def plot_const (self ):
0 commit comments