def predlin(s,p,w):
    """
    Function that computes de linear prediction using lpc for a given signal
    """
    x = s*w
    
    lpc,e = spectrum.lpc(x,N = p)
    #E = np.sqrt(np.sum(x**2))
    ar,sigma,lt = spectrum.aryule(x,p)
    
    
    plt.subplot(3,1,1)
    plt.plot(s)
    plt.title("Speech signal")
    xx = np.arange(0,len(w))
    plt.plot(xx,w*np.max(s))

    plt.subplot(312)
    plt.plot(x)
    plt.title("Windowed signal")
    
    plt.subplot(313)
    S_x = 20*np.log10(np.abs(np.fft.fft(x,2*len(w))))
    plt.plot(S_x[0:len(w)])
    ff,h = scipy.signal.freqz(1,ar,len(w),whole=False)
    h2 = spectrum.arma2psd(ar,NFFT=len(w)*2)
    plt.plot(20*np.log10(np.abs(h2[0:len(w)])))
Пример #2
0
def func(n_frames, n_freqs, data_frames):
    #win=np.hanning(frame_length)
    print("computing the weight factor...")
    w_matrix = np.ones_like(data_frames)
    for i in range(n_frames):
            
        ak, _ = lpc(data_frames[i, :], 10)
        a_numerator = np.insert(ak, 0, 1)
        a_denominator = np.ones_like(a_numerator)
        for ii in range(1, len(a_numerator)):
            a_denominator[ii] = (0.8 ** ii) * a_numerator[ii]

        _, H = signal.freqz(a_numerator, a_denominator, worN=n_freqs, whole=True)
        w_matrix[i, :] = H.copy()
     
    return 20*np.log10(abs(w_matrix[:, 0:n_freqs]))
Пример #3
0
def lpc_cepstrum_frame(sig, order=None):
    """
    :param lpc: A sequence of lpc components. Need to be preprocessed by lpc()
    :param g: Error term for lpc sequence
    :param order: size of the array. Function returns order+1 length array. Default is len(seq)
    :return:
    """
    lp, g = spectrum.lpc(sig, order)
    cepst = np.zeros((order, ), dtype=np.float32)

    for i in range(0, order):
        sum = 0
        for j in range(0, i):
            sum += (j - i) * lp[j] * cepst[i - j - 1]
        cepst[i] = -lp[i] + sum / (i + 1)

    return cepst
def predlin2(s,p,w):
    x = s*w
    
    lpc,e = spectrum.lpc(x,N = p)
    return lpc
Пример #5
0
def lpc_spectrum_frame(sig, order, nfft):
    lp, e = spectrum.lpc(sig, order)

    # Need to add 1 to the lp coefficients to make it similar to result from Matlab
    w, h = freqz(1, np.concatenate((np.array([1]), lp)), nfft)
    return h
Пример #6
0
def lp_coefficients_frame(sig, order):
    lp, e = spectrum.lpc(sig, order)
    return lp.astype(np.float32)
Пример #7
0
 def lpc_coeff(self, p):
     #print "LPC coeff for: " + str(self)
     sc_data = self.data - np.mean(self.data)
     sc_data = sc_data/np.max(sc_data)
     (coeff, err) = lpc(sc_data, p);
     return coeff
 def lpc_coeff(self, p):
     # print "LPC coeff for: " + str(self)
     sc_data = self.data - np.mean(self.data)
     sc_data = sc_data / np.max(sc_data)
     (coeff, err) = lpc(sc_data, p)
     return coeff
Пример #9
0
import voice_sample

def frame(x, framesize, framehop):
    w = scipy.hamming(framesize)
    return scipy.array([w*x[i:i+framesize] 
                     for i in range(0, len(x)-framesize, framehop)])

if __name__ == '__main__':
    import scipy.io.wavfile as wf
    names = voice_sample.get_names()
    for num, name in zip(range(1, len(names) + 1), names):
        pylab.subplot(2,3, num)
        for it in range(0, 9):
            (fs, sd) = wf.read(voice_sample.SAMPLES_DIR + '/%s/imie/%02d.wav' % (name, it+1) )
            sd = sd - scipy.mean(sd)
            sd = sd / scipy.amax(sd)
            #sf = frame(sd, int(fs*0.03), int(fs*0.02))

            #lpcc = scipy.array([ lpc(f, 10) for f in sf ]);
            #lpcc_mean = scipy.mean(lpcc, 0)

            #pylab.figure();
            #pylab.plot(sd);
            lpcc, e = spectrum.lpc(sd, 12)
            pylab.plot(lpcc, label="Zapis {:02d}".format(it+1) );
        pylab.title(name)
        pylab.ylim(-5, 5)

    pylab.show();