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.



BER-SNR Curve of BPSK



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()









share|improve this question



















  • 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















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.



BER-SNR Curve of BPSK



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()









share|improve this question



















  • 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













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.



BER-SNR Curve of BPSK



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()









share|improve this question















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.



BER-SNR Curve of BPSK



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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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













  • 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


















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto