コード例 #1
0
def idct_2d_ref(x, **kwargs):
    """ used as a reference in testing idct2. """
    x = np.array(x, copy=True)
    for row in range(x.shape[0]):
        x[row, :] = idct(x[row, :], **kwargs)
    for col in range(x.shape[1]):
        x[:, col] = idct(x[:, col], **kwargs)
    return x
コード例 #2
0
def idct_2d_ref(x, **kwargs):
    """Calculate reference values for testing idct2."""
    x = np.array(x, copy=True)
    for row in range(x.shape[0]):
        x[row, :] = idct(x[row, :], **kwargs)
    for col in range(x.shape[1]):
        x[:, col] = idct(x[:, col], **kwargs)
    return x
コード例 #3
0
 def test_definition(self):
     for i in FFTWDATA_SIZES:
         xr, yr, dt = fftw_dct_ref(self.type, i, self.rdt)
         x = idct(yr, type=self.type)
         if self.type == 1:
             x /= 2 * (i-1)
         else:
             x /= 2 * i
         assert_equal(x.dtype, dt)
         # 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(x / np.max(x), xr / np.max(x), decimal=self.dec,
                 err_msg="Size %d failed" % i)
コード例 #4
0
def IDCTcoefficient(sig,
                    samplerate=16000,
                    win_length=0.025,
                    win_step=0.01,
                    pre_emphasis_coeff=0.97):
    '''
    计算初始IDCT系数
    :param sig:
    :param samplerate:
    :param win_length:
    :param win_step:
    :param pre_emphasis_coeff:
    :return:
    '''

    #预处理
    signal = pre_emphasis(sig, pre_emphasis_coeff)
    #分帧
    frames = audio2frame(signal, win_length * samplerate,
                         win_step * samplerate)  # 得到帧数组
    #加窗
    frames *= np.hamming(int(round(win_length * samplerate)))  # 加窗
    #DCT
    dctfeat = dct(frames, type=2, axis=1, norm='ortho')  # 进行离散余弦变换
    #为0无法取对数
    #dctfeat[dctfeat < 1e-30] = 1e-30
    dctfeatnoz = np.where(dctfeat == 0,
                          np.finfo(float).eps,
                          dctfeat)  #对为0的地方调整为eps,这样便于进行对数处理
    dctfeatnoz = np.absolute(dctfeatnoz)
    #取对数
    logfeat = np.log(dctfeatnoz)
    del dctfeatnoz
    #取IDCT
    idctfeat = idct(logfeat, type=2, axis=1, norm='ortho')  # 进行反离散余弦变换

    return idctfeat
コード例 #5
0
 def test_idct_complex(self):
     y = idct(np.arange(5) * 1j)
     x = 1j * idct(np.arange(5))
     assert_array_almost_equal(x, y)
コード例 #6
0
    # plt.subplot(4, 1, 2)
    # plt.title("DCT")
    # plt.plot(range(feat.shape[1]), feat[0])

    # feat=np.power(feat,2)
    feat = abs(feat)
    feat = np.where(feat == 0, np.finfo(float).eps, feat)
    feat = np.log(feat)

    # plt.subplot(4, 1, 3)
    # plt.title("Log")
    # # plt.plot(range(175),feat[0][25:200])
    # plt.plot(range(feat.shape[1]), feat[0])

    feat = idct(feat)

    # plt.subplot(4,1,4)
    plt.title("IDCT")
    # plt.plot(range(175),feat[0][25:200])
    plt.plot(range(feat.shape[1]), abs(feat[0]))

    # plt.subplot(4, 1, 3)
    # plt.plot(range(feat.shape[1]), feat[0]-np.array( sig[:pointnum]))
    plt.show()

    # x = np.linspace(-0, 1, 10000)
    # a = np.sin(2*np.pi*x)#+np.cos(2*np.pi*x) +np.sin(8*np.pi*x)+np.cos(2*np.pi*x)+np.sin(np.pi*x)+np.sin(6*np.pi*x)
    # plt.subplot(4, 1, 1)
    # plt.plot(x,a)
    #