python实现柏林噪声
- User
python实现柏林噪声
- Assistant
以下是使用Python实现高斯白噪声和差分高斯白噪声的代码:
import numpy as np import matplotlib.pyplot as plt
生成高斯白噪声
def gauss_noise(size): return np.random.normal(0, 1, size)
生成差分高斯白噪声
def diff_gauss_noise(size, alpha): x = np.zeros(size) for i in range(1, size): x[i] = x[i-1] - alpha * x[i-1] + np.random.normal(0, 1) return x
绘制高斯白噪声和差分高斯白噪声的图像
size = 1000 t = np.linspace(0, 1, size)
gauss = gauss_noise(size) diff_gauss = diff_gauss_noise(size, 0.1)
fig, axs = plt.subplots(2, 1, figsize=(12, 6), tight_layout=True)
axs[0].plot(t, gauss, 'r-', label='Gaussian White Noise') axs[1].plot(t, diff_gauss, 'b-', label='Diff Gaussian White Noise')
axs[0].set_xlabel('Time') axs[0].set_ylabel('Amplitude') axs[0].set_title('Gaussian White Noise')
axs[1].set_xlabel('Time') axs[1].set_ylabel('Amplitude') axs[1].set_title('Diff Gaussian White Noise')
plt.show()
注意:实现中使用了numpy和matplotlib库。可以根据需要调整图像的大小和参数。
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.