import numpy as np
import matplotlib.pyplot as plt
nstep = 300
# random signal generation
a_range = [0,2]
a = np.random.rand(nstep) * (a_range[1]-a_range[0]) + a_range[0] # range for amplitude
b_range = [2, 10]
b = np.random.rand(nstep) *(b_range[1]-b_range[0]) + b_range[0] # range for frequency
b = np.round(b)
b = b.astype(int)
b[0] = 0
for i in range(1,np.size(b)):
b[i] = b[i-1]+b[i]
# Random Signal
i=0
random_signal = np.zeros(nstep)
while b[i]<np.size(random_signal):
k = b[i]
random_signal[k:] = a[i]
i=i+1
# PRBS
a = np.zeros(nstep)
j = 0
while j < nstep:
a[j] = 5
a[j+1] = -5
j = j+2
i=0
prbs = np.zeros(nstep)
while b[i]<np.size(prbs):
k = b[i]
prbs[k:] = a[i]
i=i+1
plt.figure(0)
plt.subplot(2,1,1)
plt.plot(random_signal, drawstyle='steps',label='Random Signal')
plt.legend()
plt.subplot(2,1,2)
plt.plot(prbs, drawstyle='steps', label='PRBS')
plt.legend()
plt.show()