pseudo random input signal python

Solutions on MaxInterview for pseudo random input signal python by the best coders in the world

showing results for - "pseudo random input signal python"
Lautaro
04 Oct 2020
1import numpy as np
2import matplotlib.pyplot as plt
3
4nstep = 300
5
6# random signal generation
7
8a_range = [0,2]
9a = np.random.rand(nstep) * (a_range[1]-a_range[0]) + a_range[0] # range for amplitude
10
11b_range = [2, 10]
12b = np.random.rand(nstep) *(b_range[1]-b_range[0]) + b_range[0] # range for frequency
13b = np.round(b)
14b = b.astype(int)
15
16b[0] = 0
17
18for i in range(1,np.size(b)):
19    b[i] = b[i-1]+b[i]
20
21# Random Signal
22i=0
23random_signal = np.zeros(nstep)
24while b[i]<np.size(random_signal):
25    k = b[i]
26    random_signal[k:] = a[i]
27    i=i+1
28
29# PRBS
30a = np.zeros(nstep)
31j = 0
32while j < nstep:
33    a[j] = 5
34    a[j+1] = -5
35    j = j+2
36
37i=0
38prbs = np.zeros(nstep)
39while b[i]<np.size(prbs):
40    k = b[i]
41    prbs[k:] = a[i]
42    i=i+1
43
44plt.figure(0) 
45plt.subplot(2,1,1)
46plt.plot(random_signal, drawstyle='steps',label='Random Signal')
47plt.legend()
48plt.subplot(2,1,2)
49plt.plot(prbs, drawstyle='steps', label='PRBS')
50plt.legend()
51plt.show()
52
similar questions
queries leading to this page
pseudo random input signal python