{"id":2651,"date":"2017-06-23T05:07:12","date_gmt":"2017-06-23T05:07:12","guid":{"rendered":"http:\/\/www.raymaps.com\/?p=2651"},"modified":"2022-05-07T09:18:46","modified_gmt":"2022-05-07T09:18:46","slug":"bpsk-bit-error-rate-calculation-using-python","status":"publish","type":"post","link":"https:\/\/www.raymaps.com\/index.php\/bpsk-bit-error-rate-calculation-using-python\/","title":{"rendered":"BPSK Bit Error Rate Calculation Using Python"},"content":{"rendered":"<p style=\"text-align: justify;\">Have you ever thought about how life would be without MATLAB. As it turns out there are free and open source options such as Python. We have so far restricted ourselves to MATLAB in this blog but now we venture out to find out what are the other options. Given below is a most basic Python code that calculates the Bit Error Rate of Binary Phase Shift Keying (BPSK). Compare this to our MATLAB implementation earlier <a href=\"http:\/\/www.raymaps.com\/index.php\/bit-error-rate-of-bpsk\/\">[BPSK BER]<\/a>.<\/p>\n<p style=\"text-align: justify;\">There are various IDEs available for writing your code but I have used Enthought Canopy Editor (32 bit) which is free to download and is also quite easy to use <a href=\"https:\/\/store.enthought.com\/downloads\/\">[download here]<\/a>. So as it turns out that there is life beyond MATLAB. In fact there are several advantages of using Python over MATLAB which we will discuss later in another post. Lastly please note the indentation in the code below as there is no &#8220;end&#8221; statement in a &#8220;for loop&#8221; in Python.<\/p>\n<pre>from numpy import sqrt\nfrom numpy.random import rand, randn\nimport matplotlib.pyplot as plt\n  \nN = 5000000\nEbNodB_range = range(0,11)\nitr = len(EbNodB_range)\nber = [None]*itr\n\nfor n in range (0, itr): \n \n    EbNodB = EbNodB_range[n]   \n    EbNo=10.0**(EbNodB\/10.0)\n    x = 2 * (rand(N) &gt;= 0.5) - 1\n    noise_std = 1\/sqrt(2*EbNo)\n    y = x + noise_std * randn(N)\n    y_d = 2 * (y &gt;= 0) - 1\n    errors = (x != y_d).sum()\n    ber[n] = 1.0 * errors \/ N\n    \n    print \"EbNodB:\", EbNodB\n    print \"Error bits:\", errors\n    print \"Error probability:\", ber[n] \n        \nplt.plot(EbNodB_range, ber, 'bo', EbNodB_range, ber, 'k')\nplt.axis([0, 10, 1e-6, 0.1])\nplt.xscale('linear')\nplt.yscale('log')\nplt.xlabel('EbNo(dB)')\nplt.ylabel('BER')\nplt.grid(True)\nplt.title('BPSK Modulation')\nplt.show()\n<\/pre>\n<figure id=\"attachment_2664\" aria-describedby=\"caption-attachment-2664\" style=\"width: 640px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.raymaps.com\/index.php\/bpsk-bit-error-rate-calculation-using-python\/numpy_fig\/\" rel=\"attachment wp-att-2664\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2664\" src=\"http:\/\/www.raymaps.com\/wp-content\/uploads\/2017\/06\/numpy_fig.png\" alt=\"BPSK Bit Error Rate\" width=\"640\" height=\"478\" srcset=\"https:\/\/www.raymaps.com\/wp-content\/uploads\/2017\/06\/numpy_fig.png 640w, https:\/\/www.raymaps.com\/wp-content\/uploads\/2017\/06\/numpy_fig-300x224.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><figcaption id=\"caption-attachment-2664\" class=\"wp-caption-text\">BPSK Bit Error Rate<\/figcaption><\/figure>\n<p><a href=\"http:\/\/www.pyzo.org\/python_vs_matlab.html\">MATLAB vs PYTHON A COMPARISON<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever thought about how life would be without MATLAB. As it turns out there are free and open source options such as Python. We have so far restricted ourselves to MATLAB in this blog but now we venture out to find out what are the other options. Given below is a most basic Python code that calculates the Bit Error Rate of Binary Phase Shift Keying (BPSK). Compare this to our MATLAB implementation earlier [BPSK BER]. There are various IDEs available for writing your code but I have used Enthought Canopy Editor (32 bit) which is free to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,81],"tags":[104,37,134],"class_list":["post-2651","post","type-post","status-publish","format-standard","hentry","category-berp","category-fundamentals","tag-bit-error-rate","tag-bpsk","tag-python"],"_links":{"self":[{"href":"https:\/\/www.raymaps.com\/index.php\/wp-json\/wp\/v2\/posts\/2651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.raymaps.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.raymaps.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.raymaps.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.raymaps.com\/index.php\/wp-json\/wp\/v2\/comments?post=2651"}],"version-history":[{"count":18,"href":"https:\/\/www.raymaps.com\/index.php\/wp-json\/wp\/v2\/posts\/2651\/revisions"}],"predecessor-version":[{"id":4208,"href":"https:\/\/www.raymaps.com\/index.php\/wp-json\/wp\/v2\/posts\/2651\/revisions\/4208"}],"wp:attachment":[{"href":"https:\/\/www.raymaps.com\/index.php\/wp-json\/wp\/v2\/media?parent=2651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.raymaps.com\/index.php\/wp-json\/wp\/v2\/categories?post=2651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.raymaps.com\/index.php\/wp-json\/wp\/v2\/tags?post=2651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}