BER-SNR curve in Rayleigh channel using BPSK
up vote
0
down vote
favorite
I am trying to generate BER-SNR curve in Rayleigh channel using BPSK modulation. Can anyone help me to find what is wrong with the python code? The theoretical BER differs from the simulated BER. The red dotted line is theoretical and the blue one is simulated.
import math as mt
import numpy as np
import matplotlib.pyplot as plt
import numpy.random as nr
from scipy.linalg import toeplitz
# ------------Simulation parameters------------------------
N = 500 #No.of symbols
H_n = 10 #No.of channel elements
h_ray = np.zeros((H_n, 1), dtype = complex)
# ---------------------------------------------------------
EbN0dB = np.array(range(0, 11))
itr = len(EbN0dB)
ber = [None] * itr
theoreticalBER = [None] * itr
# -----------------------------Transmitter----------------------------
s = 2 * (nr.rand(N, 1) >= 0.5) - 1 # BPSK
# ------------------------------Channel-------------------------------
h_ray = (1/mt.sqrt(2)) * (nr.randn(H_n, 1) + 1j * nr.randn(H_n, 1))
# Rayleigh fading channel
z = np.zeros((N-1,1))
c = np.concatenate((h_ray, z), axis=0)
r = np.concatenate(([h_ray[0]], np.zeros((1, N-1))), axis=1)
h_ray_y=toeplitz(c, r) # Toeplitz matrix instead of convolution
y_ray = np.dot(h_ray_y, s)
for n in range(itr):
EbN0dB_n = EbN0dB[n]
EbN0 = 10.0 ** (-EbN0dB_n/ 20.0)
noise = 1/mt.sqrt(2) * (nr.randn(N+H_n-1) + 1j * nr.randn(N+H_n-1))
r_ray = y_ray + EbN0 * noise
# --------------------------Receiver------------------------------
r_t = np.dot(np.dot(np.linalg.pinv(np.dot(h_ray_y.T, h_ray_y)), h_ray_y.T), r_ray) # (H.T * H)^(-1)*H.T*received
r_d = 2 * (np.real(r_t) >= 0) - 1
errors = (s != r_d).sum()
ber[n] = 1.0 * errors / N
EbN0_th = 10.0 ** (EbN0dB_n / 10.0)
theoreticalBER[n] = 0.5 *(1 - mt.sqrt(EbN0_th/ (1 + EbN0_th)))
ber=np.asanyarray(ber)
#-------------------------------------------------------------------------
plt.plot(EbN0dB, np.log10(ber), '--bo')
plt.plot(EbN0dB, np.log10(theoreticalBER), 'ro')
plt.xlabel('EbN0(dB)')
plt.ylabel('BER')
plt.grid(True)
plt.title('BPSK - Rayleigh')
plt.show()
python scipy
add a comment |
up vote
0
down vote
favorite
I am trying to generate BER-SNR curve in Rayleigh channel using BPSK modulation. Can anyone help me to find what is wrong with the python code? The theoretical BER differs from the simulated BER. The red dotted line is theoretical and the blue one is simulated.
import math as mt
import numpy as np
import matplotlib.pyplot as plt
import numpy.random as nr
from scipy.linalg import toeplitz
# ------------Simulation parameters------------------------
N = 500 #No.of symbols
H_n = 10 #No.of channel elements
h_ray = np.zeros((H_n, 1), dtype = complex)
# ---------------------------------------------------------
EbN0dB = np.array(range(0, 11))
itr = len(EbN0dB)
ber = [None] * itr
theoreticalBER = [None] * itr
# -----------------------------Transmitter----------------------------
s = 2 * (nr.rand(N, 1) >= 0.5) - 1 # BPSK
# ------------------------------Channel-------------------------------
h_ray = (1/mt.sqrt(2)) * (nr.randn(H_n, 1) + 1j * nr.randn(H_n, 1))
# Rayleigh fading channel
z = np.zeros((N-1,1))
c = np.concatenate((h_ray, z), axis=0)
r = np.concatenate(([h_ray[0]], np.zeros((1, N-1))), axis=1)
h_ray_y=toeplitz(c, r) # Toeplitz matrix instead of convolution
y_ray = np.dot(h_ray_y, s)
for n in range(itr):
EbN0dB_n = EbN0dB[n]
EbN0 = 10.0 ** (-EbN0dB_n/ 20.0)
noise = 1/mt.sqrt(2) * (nr.randn(N+H_n-1) + 1j * nr.randn(N+H_n-1))
r_ray = y_ray + EbN0 * noise
# --------------------------Receiver------------------------------
r_t = np.dot(np.dot(np.linalg.pinv(np.dot(h_ray_y.T, h_ray_y)), h_ray_y.T), r_ray) # (H.T * H)^(-1)*H.T*received
r_d = 2 * (np.real(r_t) >= 0) - 1
errors = (s != r_d).sum()
ber[n] = 1.0 * errors / N
EbN0_th = 10.0 ** (EbN0dB_n / 10.0)
theoreticalBER[n] = 0.5 *(1 - mt.sqrt(EbN0_th/ (1 + EbN0_th)))
ber=np.asanyarray(ber)
#-------------------------------------------------------------------------
plt.plot(EbN0dB, np.log10(ber), '--bo')
plt.plot(EbN0dB, np.log10(theoreticalBER), 'ro')
plt.xlabel('EbN0(dB)')
plt.ylabel('BER')
plt.grid(True)
plt.title('BPSK - Rayleigh')
plt.show()
python scipy
3
What makes you think something is wrong? Give a Minimal, Complete, and Verifiable example.
– jonrsharpe
Nov 11 at 15:21
The simulated BER differs from the theoretical BER. The screenshot of the graphs will be attached to the question shortly. Thank you.
– POOJA P ANIL
Nov 11 at 15:26
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to generate BER-SNR curve in Rayleigh channel using BPSK modulation. Can anyone help me to find what is wrong with the python code? The theoretical BER differs from the simulated BER. The red dotted line is theoretical and the blue one is simulated.
import math as mt
import numpy as np
import matplotlib.pyplot as plt
import numpy.random as nr
from scipy.linalg import toeplitz
# ------------Simulation parameters------------------------
N = 500 #No.of symbols
H_n = 10 #No.of channel elements
h_ray = np.zeros((H_n, 1), dtype = complex)
# ---------------------------------------------------------
EbN0dB = np.array(range(0, 11))
itr = len(EbN0dB)
ber = [None] * itr
theoreticalBER = [None] * itr
# -----------------------------Transmitter----------------------------
s = 2 * (nr.rand(N, 1) >= 0.5) - 1 # BPSK
# ------------------------------Channel-------------------------------
h_ray = (1/mt.sqrt(2)) * (nr.randn(H_n, 1) + 1j * nr.randn(H_n, 1))
# Rayleigh fading channel
z = np.zeros((N-1,1))
c = np.concatenate((h_ray, z), axis=0)
r = np.concatenate(([h_ray[0]], np.zeros((1, N-1))), axis=1)
h_ray_y=toeplitz(c, r) # Toeplitz matrix instead of convolution
y_ray = np.dot(h_ray_y, s)
for n in range(itr):
EbN0dB_n = EbN0dB[n]
EbN0 = 10.0 ** (-EbN0dB_n/ 20.0)
noise = 1/mt.sqrt(2) * (nr.randn(N+H_n-1) + 1j * nr.randn(N+H_n-1))
r_ray = y_ray + EbN0 * noise
# --------------------------Receiver------------------------------
r_t = np.dot(np.dot(np.linalg.pinv(np.dot(h_ray_y.T, h_ray_y)), h_ray_y.T), r_ray) # (H.T * H)^(-1)*H.T*received
r_d = 2 * (np.real(r_t) >= 0) - 1
errors = (s != r_d).sum()
ber[n] = 1.0 * errors / N
EbN0_th = 10.0 ** (EbN0dB_n / 10.0)
theoreticalBER[n] = 0.5 *(1 - mt.sqrt(EbN0_th/ (1 + EbN0_th)))
ber=np.asanyarray(ber)
#-------------------------------------------------------------------------
plt.plot(EbN0dB, np.log10(ber), '--bo')
plt.plot(EbN0dB, np.log10(theoreticalBER), 'ro')
plt.xlabel('EbN0(dB)')
plt.ylabel('BER')
plt.grid(True)
plt.title('BPSK - Rayleigh')
plt.show()
python scipy
I am trying to generate BER-SNR curve in Rayleigh channel using BPSK modulation. Can anyone help me to find what is wrong with the python code? The theoretical BER differs from the simulated BER. The red dotted line is theoretical and the blue one is simulated.
import math as mt
import numpy as np
import matplotlib.pyplot as plt
import numpy.random as nr
from scipy.linalg import toeplitz
# ------------Simulation parameters------------------------
N = 500 #No.of symbols
H_n = 10 #No.of channel elements
h_ray = np.zeros((H_n, 1), dtype = complex)
# ---------------------------------------------------------
EbN0dB = np.array(range(0, 11))
itr = len(EbN0dB)
ber = [None] * itr
theoreticalBER = [None] * itr
# -----------------------------Transmitter----------------------------
s = 2 * (nr.rand(N, 1) >= 0.5) - 1 # BPSK
# ------------------------------Channel-------------------------------
h_ray = (1/mt.sqrt(2)) * (nr.randn(H_n, 1) + 1j * nr.randn(H_n, 1))
# Rayleigh fading channel
z = np.zeros((N-1,1))
c = np.concatenate((h_ray, z), axis=0)
r = np.concatenate(([h_ray[0]], np.zeros((1, N-1))), axis=1)
h_ray_y=toeplitz(c, r) # Toeplitz matrix instead of convolution
y_ray = np.dot(h_ray_y, s)
for n in range(itr):
EbN0dB_n = EbN0dB[n]
EbN0 = 10.0 ** (-EbN0dB_n/ 20.0)
noise = 1/mt.sqrt(2) * (nr.randn(N+H_n-1) + 1j * nr.randn(N+H_n-1))
r_ray = y_ray + EbN0 * noise
# --------------------------Receiver------------------------------
r_t = np.dot(np.dot(np.linalg.pinv(np.dot(h_ray_y.T, h_ray_y)), h_ray_y.T), r_ray) # (H.T * H)^(-1)*H.T*received
r_d = 2 * (np.real(r_t) >= 0) - 1
errors = (s != r_d).sum()
ber[n] = 1.0 * errors / N
EbN0_th = 10.0 ** (EbN0dB_n / 10.0)
theoreticalBER[n] = 0.5 *(1 - mt.sqrt(EbN0_th/ (1 + EbN0_th)))
ber=np.asanyarray(ber)
#-------------------------------------------------------------------------
plt.plot(EbN0dB, np.log10(ber), '--bo')
plt.plot(EbN0dB, np.log10(theoreticalBER), 'ro')
plt.xlabel('EbN0(dB)')
plt.ylabel('BER')
plt.grid(True)
plt.title('BPSK - Rayleigh')
plt.show()
python scipy
python scipy
edited Nov 11 at 15:32
jonrsharpe
76.3k10100206
76.3k10100206
asked Nov 11 at 15:18
POOJA P ANIL
11
11
3
What makes you think something is wrong? Give a Minimal, Complete, and Verifiable example.
– jonrsharpe
Nov 11 at 15:21
The simulated BER differs from the theoretical BER. The screenshot of the graphs will be attached to the question shortly. Thank you.
– POOJA P ANIL
Nov 11 at 15:26
add a comment |
3
What makes you think something is wrong? Give a Minimal, Complete, and Verifiable example.
– jonrsharpe
Nov 11 at 15:21
The simulated BER differs from the theoretical BER. The screenshot of the graphs will be attached to the question shortly. Thank you.
– POOJA P ANIL
Nov 11 at 15:26
3
3
What makes you think something is wrong? Give a Minimal, Complete, and Verifiable example.
– jonrsharpe
Nov 11 at 15:21
What makes you think something is wrong? Give a Minimal, Complete, and Verifiable example.
– jonrsharpe
Nov 11 at 15:21
The simulated BER differs from the theoretical BER. The screenshot of the graphs will be attached to the question shortly. Thank you.
– POOJA P ANIL
Nov 11 at 15:26
The simulated BER differs from the theoretical BER. The screenshot of the graphs will be attached to the question shortly. Thank you.
– POOJA P ANIL
Nov 11 at 15:26
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250143%2fber-snr-curve-in-rayleigh-channel-using-bpsk%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
What makes you think something is wrong? Give a Minimal, Complete, and Verifiable example.
– jonrsharpe
Nov 11 at 15:21
The simulated BER differs from the theoretical BER. The screenshot of the graphs will be attached to the question shortly. Thank you.
– POOJA P ANIL
Nov 11 at 15:26