当前位置: 首页>>代码示例>>Python>>正文


Python realtransforms.dct函数代码示例

本文整理汇总了Python中scipy.fftpack.realtransforms.dct函数的典型用法代码示例。如果您正苦于以下问题:Python dct函数的具体用法?Python dct怎么用?Python dct使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了dct函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_definition_ortho

 def test_definition_ortho(self):
     """Test orthornomal mode."""
     for i in range(len(X)):
         x = np.array(X[i], dtype=self.rdt)
         y = dct(x, norm="ortho", type=2)
         xi = dct(y, norm="ortho", type=3)
         self.assertTrue(xi.dtype == self.rdt, "Output dtype is %s, expected %s" % (xi.dtype, self.rdt))
         assert_array_almost_equal(xi, x, decimal=self.dec)
开发者ID:mattyhk,项目名称:basketball-django,代码行数:8,代码来源:test_real_transforms.py

示例2: dct_2d_ref

def dct_2d_ref(x, **kwargs):
    """Calculate reference values for testing dct2."""
    x = np.array(x, copy=True)
    for row in range(x.shape[0]):
        x[row, :] = dct(x[row, :], **kwargs)
    for col in range(x.shape[1]):
        x[:, col] = dct(x[:, col], **kwargs)
    return x
开发者ID:ElDeveloper,项目名称:scipy,代码行数:8,代码来源:test_real_transforms.py

示例3: test_definition_ortho

 def test_definition_ortho(self):
     # Test orthornomal mode.
     for i in range(len(X)):
         x = np.array(X[i], dtype=self.rdt)
         y = dct(x, norm='ortho', type=2)
         xi = dct(y, norm="ortho", type=3)
         assert_equal(xi.dtype, self.rdt)
         assert_array_almost_equal(xi, x, decimal=self.dec)
开发者ID:Arasz,项目名称:scipy,代码行数:8,代码来源:test_real_transforms.py

示例4: test_axis

    def test_axis(self):
        nt = 2
        for i in [7, 8, 9, 16, 32, 64]:
            x = np.random.randn(nt, i)
            y = dct(x, type=self.type)
            for j in range(nt):
                assert_array_almost_equal(y[j], dct(x[j], type=self.type), decimal=self.dec)

            x = x.T
            y = dct(x, axis=0, type=self.type)
            for j in range(nt):
                assert_array_almost_equal(y[:, j], dct(x[:, j], type=self.type), decimal=self.dec)
开发者ID:mattyhk,项目名称:basketball-django,代码行数:12,代码来源:test_real_transforms.py

示例5: st_mfcc

def st_mfcc(cur_pos_signal, fbank, nceps):
    """
    短时mfcc
    """
    mspec = numpy.log10(numpy.dot(cur_pos_signal, fbank.T) + EPS)
    ceps = dct(mspec, type=2, norm='ortho', axis=-1)[:nceps]
    return ceps
开发者ID:jhuiac,项目名称:Speech_Feature_Extraction,代码行数:7,代码来源:feature_extraction_functions.py

示例6: smoothData

 def smoothData(self,x,y,weight,nMiss=0):
   '''
   smooth data
   '''
   import scipy.optimize.lbfgsb as lbfgsb
   from scipy.fftpack.realtransforms import dct,idct
   n0 = len(x)
   #x = np.array([x,x,x]).flatten()
   #y = np.array([y,y,y]).flatten()
   #weight = np.array([weight,weight,weight]).flatten()
   n = len(x)
   weight = 1./weight
   # scale 0 to 1
   weight = weight/np.max(weight)
   i = np.arange(1,n+1)
   eigenvalues = -2. + 2.*np.cos((i-1)*np.pi/n)
   DCTy = dct(y,norm='ortho',type=2)
   dcty2 = DCTy**2
   eigenvalues2 = eigenvalues**2
   x0 = np.atleast_1d(1.)
   y_hat = np.zeros_like(y)
   xpost,f,d = lbfgsb.fmin_l_bfgs_b(gcv,x0,fprime=None,factr=10.,\
          approx_grad=True,args=(y,weight,eigenvalues2,n,nMiss,y_hat))
   solvedGamma = np.exp(xpost)[0]
   return y_hat,solvedGamma 
开发者ID:GerardoLopez,项目名称:eoldas_release,代码行数:25,代码来源:sentinel.py

示例7: mfcc

def mfcc(input, nceps=13):
    """Compute Mel Frequency Cepstral Coefficients.

    Parameters
    ----------
    input: ndarray
        input spectrogram from which the coefficients are computed

    Returns
    -------
    ceps: ndarray
        Mel-cepstrum coefficients
    mspec: ndarray
        Log-spectrum in the mel-domain.

    Notes
    -----
    MFCC are computed as follows:
        * Pre-processing in time-domain (pre-emphasizing)
        * Compute the spectrum amplitude by windowing with a Hamming window
        * Filter the signal in the spectral domain with a triangular
        filter-bank, whose filters are approximatively linearly spaced on the
        mel scale, and have equal bandwith in the mel scale
        * Compute the DCT of the log-spectrum

    This is based on the talkbox module:
    http://pydoc.net/Python/scikits.talkbox/0.2.4.dev/scikits.talkbox.features.mfcc/

    References
    ----------
    .. [1] S.B. Davis and P. Mermelstein, "Comparison of parametric
           representations for monosyllabic word recognition in continuously
           spoken sentences", IEEE Trans. Acoustics. Speech, Signal Proc.
           ASSP-28 (4): 357-366, August 1980."""


    nfft = input.metadata.sampling_configuration.dft_length
    fs = input.metadata.sampling_configuration.fs
    over = input.metadata.sampling_configuration.window_length \
        - input.metadata.sampling_configuration.window_step

    #lowfreq = 400 / 3.
    lowfreq = 133.33
    #highfreq = 6855.4976
    linsc = 200/3.
    logsc = 1.0711703

    nlinfil = 13
    nlogfil = 27
    nlinfil + nlogfil

    fbank = trfbank(fs, nfft, lowfreq, linsc, logsc, nlinfil, nlogfil)[0]
    fbank = fbank.T[0:input.data.shape[0], :]

    mspec = np.log10(np.maximum(np.dot(fbank.T, input.data), 0.0000001)).T

    # Use the DCT to 'compress' the coefficients (spectrum -> cepstrum domain)
    ceps = dct(mspec, type=2, norm='ortho', axis=-1)[:, :nceps]

    return ceps
开发者ID:pymir3,项目名称:pymir3,代码行数:60,代码来源:mfcc.py

示例8: get_mfcc

def get_mfcc(path):
    """Finds the MFCCs and FFTs of a WAVE file.

  Args:
    path: The path to a WAVE file.

  Returns:
    A tuple of two iterables, the FFTs and MFCCs of the frames of the
    WAVE file.
  """
    global COMP_FRAME_SIZE
    # Read the file, and determine its length in frames
    (sample, data) = utils.read_wave_from_file(path)
    total_frames = (data.size / sample) / COMP_FRAME_SIZE

    step = COMP_FRAME_SIZE * sample
    window = hamming(step)

    # Allocate space for the FFT decompositions of each frame of sound data
    fft_out = []
    mfcc_out = []

    # Loop invariant:
    #   0 <= frame_index <= total_frames
    #   results in an array (fft_out) of FFTs that correspond to the
    #    frames of the WAVE file
    filterbank_cache = {}
    frame_index = 0

    while frame_index + (1 - FRAME_OVERLAP_FACTOR) < total_frames:
        # Obtain the frame_indexth frame from the data
        frame = data[frame_index * step : (frame_index + 1) * step]

        # Generate the FFT of the frame windowed by the hamming window
        frame_fft = numpy.fft.rfft(frame * window, n=256)
        frame_fft[frame_fft == 0] = 0.000003
        nfft = len(frame_fft)

        # Compute the mel triangular filterbank or get a cached version
        fb_key = (sample, nfft)
        if fb_key in filterbank_cache:
            filterbank = filterbank_cache[fb_key]
        else:
            filterbank = triangular_filters(sample, nfft).T
            filterbank[filterbank == 0] = 0.00003
            filterbank_cache[fb_key] = filterbank

        # The power spectrum of the frame
        power_spectrum = numpy.abs(frame_fft)
        # Filtered by the mel filterbank
        mel_power_spectrum = numpy.log10(numpy.dot(power_spectrum, filterbank))
        # With the discrete cosine transform to find the cepstrum
        cepstrum = dct(mel_power_spectrum, type=2, norm="ortho", axis=-1)

        fft_out.append(frame_fft)
        mfcc_out.append(cepstrum[: int(len(cepstrum) * SIGNIFICANT_MFCC)])
        frame_index = frame_index + FRAME_OVERLAP_FACTOR

    return numpy.array(mfcc_out)
开发者ID:pranav,项目名称:cs4500,代码行数:59,代码来源:normalize.py

示例9: test_definition_matlab

 def test_definition_matlab(self):
     """Test correspondance with matlab (orthornomal mode)."""
     for i in range(len(X)):
         x = np.array(X[i], dtype=self.rdt)
         yr = Y[i]
         y = dct(x, norm="ortho", type=2)
         self.assertTrue(y.dtype == self.rdt, "Output dtype is %s, expected %s" % (y.dtype, self.rdt))
         assert_array_almost_equal(y, yr, decimal=self.dec)
开发者ID:mattyhk,项目名称:basketball-django,代码行数:8,代码来源:test_real_transforms.py

示例10: test_definition_matlab

 def test_definition_matlab(self):
     # Test correspondance with matlab (orthornomal mode).
     for i in range(len(X)):
         x = np.array(X[i], dtype=self.rdt)
         yr = Y[i]
         y = dct(x, norm="ortho", type=2)
         assert_equal(y.dtype, self.rdt)
         assert_array_almost_equal(y, yr, decimal=self.dec)
开发者ID:Arasz,项目名称:scipy,代码行数:8,代码来源:test_real_transforms.py

示例11: test_definition_ortho

 def test_definition_ortho(self):
     # Test orthornomal mode.
     for i in range(len(X)):
         x = np.array(X[i], dtype=self.rdt)
         dt = np.result_type(np.float32, self.rdt)
         y = dct(x, norm='ortho', type=4)
         y2 = naive_dct4(x, norm='ortho')
         assert_equal(y.dtype, dt)
         assert_array_almost_equal(y / np.max(y), y2 / np.max(y), decimal=self.dec)
开发者ID:ElDeveloper,项目名称:scipy,代码行数:9,代码来源:test_real_transforms.py

示例12: test_definition

 def test_definition(self):
     for i in FFTWDATA_SIZES:
         x, yr = fftw_ref(self.type, i, self.rdt)
         y = dct(x, type=self.type)
         self.assertTrue(y.dtype == self.rdt, "Output dtype is %s, expected %s" % (y.dtype, self.rdt))
         # XXX: we divide by np.max(y) because the tests fail otherwise. We
         # should really use something like assert_array_approx_equal. The
         # difference is due to fftw using a better algorithm w.r.t error
         # propagation compared to the ones from fftpack.
         assert_array_almost_equal(y / np.max(y), yr / np.max(y), decimal=self.dec, err_msg="Size %d failed" % i)
开发者ID:mattyhk,项目名称:basketball-django,代码行数:10,代码来源:test_real_transforms.py

示例13: stMFCC

def stMFCC(X, fbank, nceps):
    """
    Computes the MFCCs of a frame, given the fft mag
    ARGUMENTS:
        X:        fft magnitude abs(FFT)
        fbank:    filter bank (see mfccInitFilterBanks)
    RETURN
        ceps:     MFCCs (13 element vector)
    Note:    MFCC calculation is, in general, taken from the scikits.talkbox library (MIT Licence),
    #    with a small number of modifications to make it more compact and suitable for the pyAudioAnalysis Lib
    """

    mspec = numpy.log10(numpy.dot(X, fbank.T)+eps)
    ceps = dct(mspec, type=2, norm='ortho', axis=-1)[:nceps]
    return ceps
开发者ID:sterling239,项目名称:audio-emotion-recognition,代码行数:15,代码来源:cf.py

示例14: gcv

def gcv(gamma_,y,weight,eigenvalues2,n,nMiss,y_hat_final):
  # a GCV function for the smoother
  from scipy.fftpack.realtransforms import dct,idct
  gamma = np.exp((gamma_))
  G = 1./(1+gamma*eigenvalues2)
  y0 = y.copy()
  e = 1e20
  while (e > 1e-10):
    y_hat = idct(G*dct(weight*weight*(y-y0)+y0,norm='ortho',type=2),norm='ortho',type=2)
    dy = y_hat - y0
    e = np.mean(dy*dy)
    y0 = y_hat
  y_hat_final[:] = y_hat
  d = weight*(y_hat-y)
  numerator = np.dot(d,d)/(n-nMiss)
  traceH = (1./(1 + gamma*eigenvalues2)).sum()
  denominator = (1 - traceH/n)**2
  return numerator/denominator
开发者ID:GerardoLopez,项目名称:eoldas_release,代码行数:18,代码来源:sentinel.py

示例15: mfcc

def mfcc(input, nwin=256, nfft=512, fs=16000, nceps=13):
    import numpy as numpy
    from scipy.io import loadmat
    from scipy.signal import lfilter, hamming
    from scipy.fftpack import fft
    from scipy.fftpack.realtransforms import dct
    over = nwin - 160
    prefac = 0.97

    #lowfreq = 400 / 3.
    lowfreq = 133.33

    linsc = 200/3.
    logsc = 1.0711703

    nlinfil = 13
    nlogfil = 27
    nfil = nlinfil + nlogfil

    w = hamming(nwin, sym=0)

    fbank = trfbank(fs, nfft, lowfreq, linsc, logsc, nlinfil, nlogfil)[0]
    if fbank<=0:
        fbank=0.0001
    #------------------
    # Compute the MFCC
    #------------------
    extract = preemp(input, prefac)
    framed = segment_axis(extract, nwin, over) * w

    # Compute the spectrum magnitude
    spec = numpy.abs(fft(framed, nfft, axis=-1))

    if spec<=0:
        spec=0.00001

    # Filter the spectrum through the triangle filterbank
    arr= numpy.dot(spec,fbank.T)                                         ##CHANGED CODE
    print "LOG ARRAy =",arr
    mspec=numpy.log10(arr)
    # Use the DCT to 'compress' the coefficients (spectrum -> cepstrum domain)
    ceps = dct(mspec, type=2, norm='ortho', axis=-1)[:, :nceps]

    return ceps
开发者ID:vikaspalkar,项目名称:Parallel-Music-Genre-Classification,代码行数:44,代码来源:MFCC.py


注:本文中的scipy.fftpack.realtransforms.dct函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。