Skip to content

Commit

Permalink
Update iq_files.rst
Browse files Browse the repository at this point in the history
# Changed one word in the description from BPSK to QPSK
# Added one line of description for how x_symbols consists
# Added your code for generating QPSK symbols (it's clear and easy to understand, so I don't think you need to make it shorter).
  • Loading branch information
accessbox777 authored Mar 31, 2024
1 parent ba3dfa4 commit 16d6436
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions content/iq_files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ In Python, the default complex type is np.complex128, which uses two 64-bit floa
Python Examples
*************************

In Python, and numpy specifically, we use the :code:`tofile()` function to store a numpy array to a file. Here is a short example of creating a simple BPSK signal plus noise and saving it to a file in the same directory we ran our script from:
In Python, and numpy specifically, we use the :code:`tofile()` function to store a numpy array to a file. Here is a short example of creating a simple QPSK signal plus noise and saving it to a file in the same directory we ran our script from:

.. code-block:: python
Expand All @@ -39,7 +39,11 @@ In Python, and numpy specifically, we use the :code:`tofile()` function to store
num_symbols = 10000
x_symbols = (np.random.randint(0, 2, num_symbols)*2-1)*(1+1j) # -1 and 1's
# x_symbols array will contain complex numbers representing the QPSK symbols. Each symbol will be a complex number with a magnitude of 1 and a phase angle corresponding to one of the four QPSK constellation points (45, 135, 225, or 315 degrees)
x_int = np.random.randint(0, 4, num_symbols) # 0 to 3
x_degrees = x_int*360/4.0 + 45 # 45, 135, 225, 315 degrees
x_radians = x_degrees*np.pi/180.0 # sin() and cos() takes in radians
x_symbols = np.cos(x_radians) + 1j*np.sin(x_radians) # this produces our QPSK complex symbols
n = (np.random.randn(num_symbols) + 1j*np.random.randn(num_symbols))/np.sqrt(2) # AWGN with unity power
r = x_symbols + n * np.sqrt(0.01) # noise power of 0.01
print(r)
Expand Down

0 comments on commit 16d6436

Please sign in to comment.