Skip to content

Commit 72ba702

Browse files
committed
Updated docstrings.
1 parent a709f63 commit 72ba702

File tree

2 files changed

+43
-44
lines changed

2 files changed

+43
-44
lines changed

commpy/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from modulation import *
1919
from impairments import *
2020
from sequences import *
21+
from channels import *
2122

2223
try:
2324
from numpy.testing import Tester

commpy/channels.py

Lines changed: 42 additions & 44 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,27 +16,30 @@
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-
from numpy import complex, sum, pi, arange, array, size, shape, real, sqrt
19+
from numpy import complex, sum, pi, arange, array, size, shape, real, sqrt
2020
from numpy import matrix, sqrt, sum, zeros, concatenate, sinc
2121
from numpy.random import randn, seed, random
22-
from scipy.special import gamma, jn
22+
from scipy.special import gamma, jn
2323
from scipy.signal import hamming, convolve, resample
2424
from scipy.fftpack import ifft, fftshift, fftfreq
2525
from scipy.interpolate import interp1d
2626

27+
__all__=['bec', 'bsc', 'awgn']
28+
2729
def bec(input_bits, p_e):
28-
""" Binary Erasure Channel.
30+
"""
31+
Binary Erasure Channel.
2932
3033
Parameters
31-
__________
34+
----------
3235
input_bits : 1D ndarray containing {0, 1}
3336
Input arrary of bits to the channel.
3437
3538
p_e : float in [0, 1]
3639
Erasure probability of the channel.
3740
3841
Returns
39-
_______
42+
-------
4043
output_bits : 1D ndarray containing {0, 1}
4144
Output bits from the channel.
4245
"""
@@ -45,7 +48,8 @@ def bec(input_bits, p_e):
4548
return output_bits
4649

4750
def bsc(input_bits, p_t):
48-
""" Binary Symmetric Channel.
51+
"""
52+
Binary Symmetric Channel.
4953
5054
Parameters
5155
__________
@@ -56,7 +60,7 @@ def bsc(input_bits, p_t):
5660
Transition/Error probability of the channel.
5761
5862
Returns
59-
_______
63+
-------
6064
output_bits : 1D ndarray containing {0, 1}
6165
Output bits from the channel.
6266
"""
@@ -66,37 +70,38 @@ def bsc(input_bits, p_t):
6670
return output_bits
6771

6872
def awgn(input_signal, snr_dB, rate=1.0):
69-
""" Addditive White Gaussian Noise (AWGN) Channel.
73+
"""
74+
Addditive White Gaussian Noise (AWGN) Channel.
7075
7176
Parameters
72-
__________
77+
----------
7378
input_signal : 1D ndarray of floats
7479
Input signal to the channel.
7580
76-
snr_dB : float
77-
Output SNR required in dB.
78-
81+
snr_dB : float
82+
Output SNR required in dB.
83+
7984
rate : float
8085
Rate of the a FEC code used if any, otherwise 1.
8186
8287
Returns
83-
_______
84-
output_signal : 1D ndarray of floats
88+
-------
89+
output_signal : 1D ndarray of floats
8590
Output signal from the channel with the specified SNR.
8691
"""
8792

8893
avg_energy = sum(input_signal * input_signal)/len(input_signal)
8994
snr_linear = 10**(snr_dB/10.0)
9095
noise_variance = avg_energy/(2*rate*snr_linear)
91-
96+
9297
if input_signal.dtype is complex:
9398
noise = sqrt(noise_variance) * randn(len(input_signal)) * (1+1j)
9499
else:
95100
noise = sqrt(2*noise_variance) * randn(len(input_signal))
96-
101+
97102
output_signal = input_signal + noise
98-
99-
return output_signal
103+
104+
return output_signal
100105

101106

102107

@@ -113,21 +118,21 @@ def awgn(input_signal, snr_dB, rate=1.0):
113118
# fs = 32.0*max_doppler
114119
# ts = 1/fs
115120
# m = arange(0, filter_length/2)
116-
117-
# Generate the Jakes Doppler Spectrum impulse response h[m]
118-
# h_jakes_left = (gamma(3.0/4) *
121+
122+
# Generate the Jakes Doppler Spectrum impulse response h[m]
123+
# h_jakes_left = (gamma(3.0/4) *
119124
# pow((max_doppler/(pi*abs((m-(filter_length/2))*ts))), 0.25) *
120125
# jn(0.25, 2*pi*max_doppler*abs((m-(filter_length/2))*ts)))
121126
# h_jakes_center = array([(gamma(3.0/4)/gamma(5.0/4)) * pow(max_doppler, 0.5)])
122-
# h_jakes = concatenate((h_jakes_left[0:filter_length/2-1],
127+
# h_jakes = concatenate((h_jakes_left[0:filter_length/2-1],
123128
# h_jakes_center, h_jakes_left[::-1]))
124129
# h_jakes = h_jakes*hamming(filter_length)
125-
# h_jakes = h_jakes/(sum(h_jakes**2)**0.5)
130+
# h_jakes = h_jakes/(sum(h_jakes**2)**0.5)
126131

127132
# -----------------------------------------------------------------------------
128133
# jakes_psd_right = (1/(pi*max_doppler*(1-(freqs/max_doppler)**2)**0.5))**0.5
129-
# zero_pad = zeros([(fft_size-filter_length)/2, ])
130-
# jakes_psd = concatenate((zero_pad, jakes_psd_right[::-1],
134+
# zero_pad = zeros([(fft_size-filter_length)/2, ])
135+
# jakes_psd = concatenate((zero_pad, jakes_psd_right[::-1],
131136
# jakes_psd_right, zero_pad))
132137
#print size(jakes_psd)
133138
# jakes_impulse = real(fftshift(ifft(jakes_psd, fft_size)))
@@ -137,41 +142,34 @@ def awgn(input_signal, snr_dB, rate=1.0):
137142
# -----------------------------------------------------------------------------
138143
# return h_jakes
139144

140-
#def rayleigh_channel(ts_input, max_doppler, block_length, path_gains,
145+
#def rayleigh_channel(ts_input, max_doppler, block_length, path_gains,
141146
# path_delays):
142-
147+
143148
# fs_input = 1.0/ts_input
144149
# fs_channel = 32.0*max_doppler
145150
# ts_channel = 1.0/fs_channel
146151
# interp_factor = fs_input/fs_channel
147152
# channel_length = block_length/interp_factor
148-
# n1 = -10
149-
# n2 = 10
153+
# n1 = -10
154+
# n2 = 10
150155

151156
# filter_length = 1024
152157

153-
# Generate the Jakes Doppler Spectrum impulse response h[m]
158+
# Generate the Jakes Doppler Spectrum impulse response h[m]
154159
# h_jakes = doppler_jakes(max_doppler, filter_length)
155-
160+
156161
# Generate the complex Gaussian Random Process
157162
# g_var = 0.5
158-
# gain_process = zeros([len(path_gains), block_length], dtype=complex)
159-
# delay_process = zeros([n2+1-n1, len(path_delays)])
163+
# gain_process = zeros([len(path_gains), block_length], dtype=complex)
164+
# delay_process = zeros([n2+1-n1, len(path_delays)])
160165
# for k in xrange(len(path_gains)):
161166
# g = (g_var**0.5) * (randn(channel_length) + 1j*randn(channel_length))
162167
# g_filt = convolve(g, h_jakes, mode='same')
163168
# g_filt_interp = resample(g_filt, block_length)
164169
# gain_process[k,:] = pow(10, (path_gains[k]/10.0)) * g_filt_interp
165170
# delay_process[:,k] = sinc((path_delays[k]/ts_input) - arange(n1, n2+1))
166-
167-
#channel_matrix = 0
171+
172+
#channel_matrix = 0
168173
# channel_matrix = matrix(delay_process)*matrix(gain_process)
169-
170-
# return channel_matrix, gain_process, h_jakes
171-
172174

173-
174-
175-
176-
177-
175+
# return channel_matrix, gain_process, h_jakes

0 commit comments

Comments
 (0)