Skip to content

Commit 57f5ebd

Browse files
authored
Merge pull request veeresht#10 from hoo89/fix_awgn
Fix awgn() in channels.py
2 parents f21d727 + e7b053a commit 57f5ebd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

commpy/channels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ def awgn(input_signal, snr_dB, rate=1.0):
9090
Output signal from the channel with the specified SNR.
9191
"""
9292

93-
avg_energy = sum(input_signal * input_signal)/len(input_signal)
93+
avg_energy = sum(abs(input_signal) * abs(input_signal))/len(input_signal)
9494
snr_linear = 10**(snr_dB/10.0)
9595
noise_variance = avg_energy/(2*rate*snr_linear)
9696

97-
if input_signal.dtype is complex:
97+
if input_signal.dtype == complex:
9898
noise = (sqrt(noise_variance) * randn(len(input_signal))) + (sqrt(noise_variance) * randn(len(input_signal))*1j)
9999
else:
100100
noise = sqrt(2*noise_variance) * randn(len(input_signal))

0 commit comments

Comments
 (0)