Ejemplo n.º 1
0
def zeroPhaseHPFilt(x,fs,f_p,f_s):
    Rp=0.5
    Rs=40
    Wp=f_p/(fs/2.)
    Ws=f_s/(fs/2.)
    [n,Wn] = buttord(Wp,Ws,Rp,Rs)
    [b,a]=butter(n,Wn,'high')
    y = filtfilt(b,a,x, padtype = 'odd', padlen=3*(max(len(b),len(a))-1))
    return y
Ejemplo n.º 2
0
def RCVD_reson_GCI(res,fs,F0mean):

    # Function to use the resonator used in RCVD (creaky voice detection),
    # applied to the LP-residual signal and give output

    ## Configure resonator (using settings in RCVD)

    Phi=2*np.pi*1*F0mean/fs
    Rho=0.9 # Set to a narrow bandwidth
    rep=filtfilt([1., 0., 0.],[1., -2*Rho*np.cos(Phi), Rho**2],res, padtype = 'odd', padlen=9) # Filter forwards and backwards to have zero-phase
    y=rep/np.max(np.abs(rep))
    return y
Ejemplo n.º 3
0
def GetLPCresidual(wave,L,shift,order,VUV):

    # ###
    #
    # Use: [res] = GetLPCresidual(wave,L,shift,VUV)
    #
    #
    # L=window length (samples) (typ.25ms)
    # shift=window shift (samples) (typ.5ms)
    # order= LPC order
    # VUV=vector of voicing decisions (=0 if Unvoiced, =1 if Voiced)
    #
    # Written originally by Thomas Drugman, TCTS Lab.
    #
    #Adapated to python by
    # J. C. Vasquez-Correa
    # Pattern recognition Lab, University of Erlangen-Nuremberg
    # Faculty of Enginerring, University of Antiqouia,
    # ###

    ## My Bit!!
    # use: L = 25/1000*fs # 25 ms frame length
    #     shift = 5/1000*fs # 5 ms shift
    #     order = 24

    start=0
    stop=int(start+L)
    res=np.zeros(len(wave))
    n=0
    while stop<len(wave):

        if np.sum(VUV[start:stop])==len(VUV[start:stop]): # if it is avoiced segment
            segment=wave[start:stop]
            segment=segment*hann(len(segment))
            try:
                A=pysptk.sptk.lpc(segment, order)
                inv=filtfilt(A,1,segment)
                inv=inv*np.sqrt(np.sum(segment**2)/np.sum(inv**2))
                res[start:stop]=inv
            except:
                print("WARNING: LPCs cannot be extracted for the segment")
        start=int(start+shift)
        stop=int(stop+shift)
        n=n+1
    res=res/max(abs(res))
    return res
Ejemplo n.º 4
0
def GetLPCresidual(wave, L, shift, order=24, VUV=1):
    """
    Get the LPC residual signal
    Written originally by Thomas Drugman, TCTS Lab.

    Adapated to python by
    J. C. Vasquez-Correa
    Pattern recognition Lab, University of Erlangen-Nuremberg
    Faculty of Enginerring, University of Antiqouia,

    :param wave: array with the speech signal
    :param L: window length (samples) (typ.25ms)
    :param shift: window shift (samples) (typ.5ms)
    :param order: LPC order
    :param VUV: vector of voicing decisions (=0 if Unvoiced, =1 if Voiced)
    :returns res: LPC residual signal 
    """
    start = 0
    stop = int(start + L)
    res = np.zeros(len(wave))
    n = 0
    while stop < len(wave):

        if np.sum(VUV[start:stop]) == len(
                VUV[start:stop]):  # if it is avoiced segment
            segment = wave[start:stop]
            segment = segment * hann(len(segment))
            try:
                A = pysptk.sptk.lpc(segment, order)
                inv = filtfilt(A, 1, segment)
                inv = inv * np.sqrt(np.sum(segment**2) / np.sum(inv**2))
                res[start:stop] = inv
            except:
                print("WARNING: LPCs cannot be extracted for the segment")
        start = int(start + shift)
        stop = int(stop + shift)
        n = n + 1
    res = res / max(abs(res))
    return res