filter_sim_routines.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:sketchrls 作者: LCAV 项目源码 文件源码
def generate_signal(n, p, loops, SNR_dB=100, noise='white', h=None):

    # First generate a random signal
    if noise == 'pink':
        x = noise_pink(n, rows=loops, alpha=1e-10)
    elif noise == 'ar1':
        x = noise_ar1(n, rows=loops)
    else:
        x = noise_white(n, rows=loops)

    # Generate random filters on the sphere
    if h is None:
        h = np.random.randn(loops,p)
        norm = np.linalg.norm(h, axis=1)
        h = (h.T/norm).T

    if h.ndim == 1:
        if h.shape[0] >= p:
            h = np.tile(h[:p], (loops,1))
        else:
            h2 = np.zeros(loops,p)
            for i in xrange(loops):
                h2[i,:h.shape[0]] = h
            h = h2

    # Finally generate the filtered signal
    sigma_noise = 10.**(-SNR_dB/20.)
    d = np.zeros((loops,n+h.shape[1]-1))
    for l in xrange(loops):
        d[l,:] = fftconvolve(x[l], h[l])
        d[l,:] += np.random.randn(n+h.shape[1]-1)*sigma_noise

    return x, h, d
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号