FilterDesign.py 文件源码

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

项目:signal_subspace 作者: scivision 项目源码 文件源码
def computefir(fc,L:int, ofn, fs:int, method:str):
    """
    bandpass FIR design

    https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.firwin.html
    http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.remez.html

    L: number of taps

    output:
    b: FIR filter coefficients
    """

    assert len(fc) == 2,'specify lower and upper bandpass filter corner frequencies in Hz.'

    if method == 'remez':
        b  = signal.remez(numtaps=L,
                      bands=[0, 0.9*fc[0], fc[0],fc[1], 1.1*fc[1], 0.5*fs],
                      desired=[0, 1,0],
                      Hz=fs)
    elif method == 'firwin':
        b = signal.firwin(L,[fc[0],fc[1]],
                          window='blackman',
                          pass_zero=False,nyq=fs//2)
    elif method == 'firwin2':
        b = signal.firwin2(L,[0,fc[0],fc[1],fs//2],[0,1,1,0],
                           window='blackman',
                           nyq=fs//2,
                           #antisymmetric=True,
                           )
    else:
        raise ValueError(f'unknown filter design method {method}')

    if ofn:
        ofn = Path(ofn).expanduser()
        print(f'writing {ofn}')
# FIXME make binary
        with ofn.open('w') as h:
            h.write(f'{b.size}\n') # first line is number of coefficients
            b.tofile(h,sep=" ") # second line is space-delimited coefficents

    return b
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号