예제 #1
0
def dolpc(x, modelorder = 8):
    nbands, nframes = x.shape
    ncorr = 2 * (nbands - 1)
    R = np.zeros((ncorr, nframes))
    
    R[0:nbands, :] = x
    for i in range(nbands - 1):
        R[i + nbands - 1, :] = x[nbands - (i + 1), :]
    
    r = fft.ifft(R.T).real.T
    r = r[0:nbands, :]
    
    y = np.ones((nframes, modelorder + 1))
    e = np.zeros((nframes, 1))
    
    if modelorder == 0:
        for i in range(nframes):
            _ , e_tmp, _ = spectrum.LEVINSON(r[:, i], modelorder, allow_singularity = True)
            e[i, 0] = e_tmp
    else:
        for i in range(nframes):
            y_tmp, e_tmp, _ = spectrum.LEVINSON(r[:, i], modelorder, allow_singularity = True)
            y[i, 1:modelorder + 1] = y_tmp
            e[i, 0] = e_tmp
    
    y = np.divide(y.T, np.add(np.tile(e.T, (modelorder + 1, 1)), 1e-8))
    
    return y
예제 #2
0
파일: utils.py 프로젝트: Hadryan/pyrasta
def dolpc(x, modelorder=8):
    """
    y = dolpc(x,modelorder)
    @About: compute autoregressive model from spectral magnitude samples
    where,  x : input signal
                row_x, col_x = x.shape()
                row_x : critical band
                col_y : nframes

            modelorder : order of model, defaults to 8

            y : lpc coeff.
                row_y, col_y = y.shape()
                row_y :

    """
    nbands, nframes = x.shape
    ncorr = 2 * (nbands - 1)

    # @TO-DO : This need optimisation
    R = np.zeros((ncorr, nframes))
    R[0:nbands, :] = x
    for i in range(nbands - 1):
        R[i + nbands - 1, :] = x[nbands - (i + 1), :]

    # Calculate autocorrelation
    r = fft.ifft(R.T).real.T
    # First half only
    r = r[0:nbands, :]

    y = np.ones((nframes, modelorder + 1))
    e = np.zeros((nframes, 1))

    # Find LPC coeffs by durbin
    if modelorder == 0:
        for i in range(nframes):
            _, e_tmp, _ = spectrum.LEVINSON(r[:, i],
                                            modelorder,
                                            allow_singularity=True)
            e[i, 0] = e_tmp
    else:
        for i in range(nframes):
            y_tmp, e_tmp, _ = spectrum.LEVINSON(r[:, i],
                                                modelorder,
                                                allow_singularity=True)
            y[i, 1:modelorder + 1] = y_tmp
            e[i, 0] = e_tmp

    # Normalize each poly by gain
    y = np.divide(y.T, np.add(np.tile(e.T, (modelorder + 1, 1)), 1e-8))

    return y
예제 #3
0
def levinson(correlation, order):
    """
    Calculate the predictor coefficients for autoregressive linear prediction
    using the Levinson-Durbin algorithm

    Parameters
    ----------
    correlation : numpy array
        The autocorrelation function of a signal.
    order : int
        The order of the prediction.

    Returns
    -------
    coeffs : numpy array
        The calculated prediction coefficients
    energy : float
        The estimated residual error energy after
        prediction

    Notes
    -----

    * The first coefficient, 1, is left out.

    """
    if not order > 0:
        raise ValueError("order must be greater than zero")

    coeffs, energy, reflectioncoeffs = spectrum.LEVINSON(correlation, order)
    energy /= correlation[0]
    return (coeffs, energy)
예제 #4
0
def dolpc(x, model_order=8):
    """
    Function dolpc computes the autoregressive model from spectral magnitude samples.
    
    @param x: Critical band filters.
    @param model_order: Order of model. Default is 8.
    @returns: Autoregressive model from spectral magnitude samples.
    """
    num_bands, num_frames = x.shape

    # Calculate autocorrelation
    R = np.zeros((2 * (num_bands - 1), num_frames))
    R[0:num_bands, :] = x
    for i in range(num_bands - 1):
        R[i + num_bands - 1, :] = x[num_bands - (i + 1), :]
    r = fft.ifft(R.T).real.T
    r = r[0:num_bands, :]
    y = np.ones((num_frames, model_order + 1))
    e = np.zeros((num_frames, 1))

    # Find LPC coeffs by durbin
    if model_order == 0:
        for i in range(num_frames):
            _, e_tmp, _ = spectrum.LEVINSON(r[:, i],
                                            model_order,
                                            allow_singularity=True)
            e[i, 0] = e_tmp
    else:
        for i in range(num_frames):
            y_tmp, e_tmp, _ = spectrum.LEVINSON(r[:, i],
                                                model_order,
                                                allow_singularity=True)
            y[i, 1:model_order + 1] = y_tmp
            e[i, 0] = e_tmp

    # Normalize each poly by gain.
    y = np.divide(y.T, np.add(np.tile(e.T, (model_order + 1, 1)), 1e-8))

    return y