Skip to content

Instantly share code, notes, and snippets.

@RJ722
Created Nov 10, 2018
Embed
What would you like to do?
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