Skip to content

Commit fe2158f

Browse files
committed
Adding doc for impairments and utilities modules.
1 parent 4c6cb93 commit fe2158f

File tree

5 files changed

+84
-11
lines changed

5 files changed

+84
-11
lines changed

commpy/impairments.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Copyright 2012 Veeresh Taranalli <veeresht@gmail.com>
33
#
4-
# This file is part of CommPy.
4+
# This file is part of CommPy.
55
#
66
# CommPy is free software: you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -16,10 +16,43 @@
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+
20+
"""
21+
============================================
22+
Impairments (:mod:`commpy.impairments`)
23+
============================================
24+
25+
.. autosummary::
26+
:toctree: generated/
27+
28+
add_frequency_offset -- Add frequency offset impairment.
29+
30+
"""
31+
1932
from numpy import exp, pi, arange
2033

2134
__all__ = ['add_frequency_offset']
2235

2336
def add_frequency_offset(waveform, Fs, delta_f):
24-
25-
return waveform*exp(1j*2*pi*(delta_f/Fs)*arange(len(waveform)))
37+
"""
38+
Add frequency offset impairment to input signal.
39+
40+
Parameters
41+
----------
42+
waveform : 1D ndarray of floats
43+
Input signal.
44+
45+
Fs : float
46+
Sampling frequency (in Hz).
47+
48+
delta_f : float
49+
Frequency offset (in Hz).
50+
51+
Returns
52+
-------
53+
output_waveform : 1D ndarray of floats
54+
Output signal with frequency offset.
55+
"""
56+
57+
output_waveform = waveform*exp(1j*2*pi*(delta_f/Fs)*arange(len(waveform)))
58+
return output_waveform

commpy/utilities.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,26 @@
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

2135
import numpy as np
2236

37+
__all__ = ['dec2bitarray', 'bitarray2dec', 'hamming_dist', 'euclid_dist', 'upsample']
38+
2339
def 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

doc/impairments.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. automodule:: commpy.impairments

doc/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,7 @@ Reference
6565
channelcoding
6666
channels
6767
filters
68+
impairments
6869
modulation
6970
sequences
71+
utilities

doc/utilities.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. automodule:: commpy.utilities

0 commit comments

Comments
 (0)