欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python-振动信号加入噪声-代码实现

程序员文章站 2022-07-01 10:54:43
...

1. 原理

Python-振动信号加入噪声-代码实现

2.代码

def wgn(x, snr):
    ## x: input vibration signal shape (a,b); a:samples number; b samples length
    ## snr: noise intensity,like -8,4,2,0,2,4,8
    ### snr=0 means noise equal to vibration signal 
    ### snr>0 means vibration signal stronger than noise, →∞ means no noise
    ### snr<0 means noise stronger than vibration signal  →-∞ means no signal
    Ps = np.sum(abs(x)**2,axis=1)/len(x)
    Pn = Ps/(10**((snr/10)))
    row,columns=x.shape
    Pn = np.repeat(Pn.reshape(-1,1),columns, axis=1)

    noise = np.random.randn(row,columns) * np.sqrt(Pn)
    signal_add_noise = x + noise
    return signal_add_noise