gpt4 book ai didi

python - Python 中的伪随机二进制序列 (prbs)

转载 作者:行者123 更新时间:2023-12-05 05:28:14 52 4
gpt4 key购买 nike

如何通过 Python 生成伪随机二进制序列 (prbs) 信号?

最佳答案

请看下面的代码。它有点粗糙,但您可以了解如何使用 NumPy 创建随机信号PRBS

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()

enter image description here

关于python - Python 中的伪随机二进制序列 (prbs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13006929/

52 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com