Created
November 10, 2018 06:47
-
-
Save RJ722/3a4053c58c6b2c15bb93d11a32cf3f70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
BIT_DURATION = 1 | |
MODULATION_FREQ = 3 / BIT_DURATION | |
N_SAMPLES = 1000 | |
ALPHABET = ['00', '01', '10', '11'] | |
def generate_random_sequence(length): | |
random_indices = np.random.randint(0, 4, (length, )) | |
return [ALPHABET[i] for i in random_indices] | |
def ask(arr, alphabet): | |
amplitudes = [alphabet.index(e) for e in arr] | |
return amplitudes | |
def main(): | |
length = int(input("Please enter the length of the signal: ")) | |
arr = generate_random_sequence(length) | |
unipolar_arr = np.array(arr) | |
ask_arr = ask(unipolar_arr, ALPHABET) | |
time = np.linspace(0, unipolar_arr.size, N_SAMPLES) | |
samples_per_bit = N_SAMPLES/unipolar_arr.size | |
bb = np.repeat(ask_arr, samples_per_bit) | |
_, ax = plt.subplots(1, 1, sharex=True, sharey=True, squeeze=True) | |
ax.plot(time, bb) | |
ax.set_xlabel('Time') | |
ax.set_ylabel('ASK Signal') | |
label = "Random numbers generated: " + str(arr) | |
print(label) | |
plt.text(3, 3.5, label, ha='right') | |
plt.show() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment