简体   繁体   English

如何将 5% 的高斯噪声添加到信号数据中

[英]How to add 5% Gaussian noise to the signal data

I want to add 5% Gaussian noise to the multivaraite data.我想在多元数据中添加 5% 的高斯噪声。 Here is the approach这是方法

import numpy as np 
mu, sigma = 0, np.std(data)*0.05 
noise = np.random.normal(mu, sigma, data.shape)
noise.shape

Here is the signal.这里是信号。 Is this a correct approach to add 5% Gaussian noise这是添加 5% 高斯噪声的正确方法吗在此处输入图片说明

I think you are on the right track, noise is additive in nature and if you look at the (SNR) Signal to Noise Ratio calculation我认为您在正确的轨道上,噪声本质上是可加的,如果您查看(SNR)信噪比计算

SNR = 20 * log(p_s)/(p_n) SNR = 20 * log(p_s)/(p_n)

which is nothing but这不过是

SNR = 20 (log(p_s) - log(p_n)) SNR = 20 (log(p_s) - log(p_n))

so we are basically subtracting the power of noise from the signal(which has noise)所以我们基本上是从信号中减去噪声的功率(有噪声)

To add noise to the entire signal向整个信号添加噪声

I would do the same as what you have posted我会和你发布的一样

import numpy as np
import matplotlib.pyplot as plt

np.random.seed(137)
t = np.linspace(0, 10, 100)
p = np.sin(t)
percentage = 0.05
n = np.random.normal(0, p.std(), t.size) * percentage
pn = p + n

fig = plt.figure()

ax1 = fig.add_subplot(211)
ax1.set_title('Noise added to entire signal')
ax1.plot(t, p, label='pure signal')
ax1.plot(t, pn, label='signal+noise')

ax2 = fig.add_subplot(212)
ax2.plot(t, pn - p, label='added noise', c='r')
plt.legend()

fig = plt.figure()

ax1 = fig.add_subplot(211)
ax1.set_title('Noise added to part of the signal')
ax1.plot(t, p, label='pure signal')
random_indices = np.random.randint(0, t.size, int(t.size*percentage))

pr = p.copy()
pr[random_indices] += n[random_indices]
ax1.plot(t, pr, label='signal+noise')

ax2 = fig.add_subplot(212)
ax2.plot(t, pr - p, label='added noise', c='r')
plt.legend()
plt.show()

在此处输入图片说明

在此处输入图片说明

Note笔记

One interesting thing that I have noticed is np.random.normal for very small values of variance mainly samples positive values, so it is better to scale the 5% ie, the variance after sampling with a higher variance value我注意到的一件有趣的事情是np.random.normal对于非常小的方差值主要采样正值,所以最好缩放 5%,即采样后的方差具有更高的方差值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM