1616# You should have received a copy of the GNU General Public License
1717# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
19- """ Utilities module """
19+ """
20+ ============================================
21+ Utilities (:mod:`commpy.utilities`)
22+ ============================================
23+
24+ .. autosummary::
25+ :toctree: generated/
26+
27+ dec2bitarray -- Integer to binary (bit array).
28+ bitarray2dec -- Binary (bit array) to integer.
29+ hamming_dist -- Hamming distance.
30+ euclid_dist -- Squared Euclidean distance.
31+ upsample -- Upsample by an integral factor (zero insertion).
32+
33+ """
2034
2135import numpy as np
2236
37+ __all__ = ['dec2bitarray' , 'bitarray2dec' , 'hamming_dist' , 'euclid_dist' , 'upsample' ]
38+
2339def dec2bitarray (in_number , bit_width ):
2440 """
2541 Converts a positive integer to NumPy array of the specified size containing
@@ -54,8 +70,13 @@ def bitarray2dec(in_bitarray):
5470
5571 Parameters
5672 ----------
57- in_bitarray: 1D ndarray of ints
73+ in_bitarray : 1D ndarray of ints
5874 Input NumPy array of bits.
75+
76+ Returns
77+ -------
78+ number : int
79+ Integer representation of input bit array.
5980 """
6081
6182 number = 0
@@ -71,11 +92,16 @@ def hamming_dist(in_bitarray_1, in_bitarray_2):
7192
7293 Parameters
7394 ----------
74- in_bit_array_1: 1D ndarray of ints
95+ in_bit_array_1 : 1D ndarray of ints
7596 NumPy array of bits.
7697
77- in_bit_array_2: 1-D ndarray of ints
98+ in_bit_array_2 : 1D ndarray of ints
7899 NumPy array of bits.
100+
101+ Returns
102+ -------
103+ distance : int
104+ Hamming distance between input bit arrays.
79105 """
80106
81107 distance = np .bitwise_xor (in_bitarray_1 , in_bitarray_2 ).sum ()
@@ -88,11 +114,16 @@ def euclid_dist(in_array1, in_array2):
88114
89115 Parameters
90116 ----------
91- in_array1: 1-D ndarray of floats
117+ in_array1 : 1D ndarray of floats
92118 NumPy array of real values.
93119
94- in_array2: 1-D ndarray of floats
120+ in_array2 : 1D ndarray of floats
95121 NumPy array of real values.
122+
123+ Returns
124+ -------
125+ distance : float
126+ Squared Euclidean distance between two input arrays.
96127 """
97128 distance = ((in_array1 - in_array2 )* (in_array1 - in_array2 )).sum ()
98129
@@ -106,11 +137,16 @@ def upsample(x, n):
106137
107138 Parameters
108139 ----------
109- x: 1-D ndarray
140+ x : 1D ndarray
110141 Input array.
111142
112- n: int
143+ n : int
113144 Upsampling factor
145+
146+ Returns
147+ -------
148+ y : 1D ndarray
149+ Output upsampled array.
114150 """
115151 y = np .empty (len (x )* n , dtype = complex )
116152 y [0 ::n ] = x
0 commit comments