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


Python fftpack.dct方法代码示例

本文整理汇总了Python中scipy.fftpack.dct方法的典型用法代码示例。如果您正苦于以下问题:Python fftpack.dct方法的具体用法?Python fftpack.dct怎么用?Python fftpack.dct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.fftpack的用法示例。


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

示例1: amplitudes_at_frequencies

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import dct [as 别名]
def amplitudes_at_frequencies(freqInds, timeseries, times=None, transform='dct'):
    """
    Finds the amplitudes in the data at the specified frequency indices.
    Todo: better docstring. Currently only works for the DCT.
    """
    amplitudes = {}
    for o in timeseries.keys():

        if transform == 'dct':
            temp = _dct(timeseries[o], norm='ortho')[freqInds] / _np.sqrt(len(timeseries[o]) / 2)
            if 0. in freqInds:
                temp[0] = temp[0] / _np.sqrt(2)
            amplitudes[o] = list(temp)

        else:
            raise NotImplementedError("This function only currently works for the DCT!")

    return amplitudes 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:20,代码来源:signal.py

示例2: block_dct

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import dct [as 别名]
def block_dct(x, block_size=8, masked=False, ratio=0.5):
    z = torch.zeros(x.size())
    num_blocks = int(x.size(2) / block_size)
    mask = np.zeros((x.size(0), x.size(1), block_size, block_size))
    mask[:, :, :int(block_size * ratio), :int(block_size * ratio)] = 1
    for i in range(num_blocks):
        for j in range(num_blocks):
            submat = x[:, :, (i * block_size):((i + 1) * block_size), (j * block_size):((j + 1) * block_size)].numpy()
            submat_dct = dct(dct(submat, axis=2, norm='ortho'), axis=3, norm='ortho')
            if masked:
                submat_dct = submat_dct * mask
            submat_dct = torch.from_numpy(submat_dct)
            z[:, :, (i * block_size):((i + 1) * block_size), (j * block_size):((j + 1) * block_size)] = submat_dct
    return z


# applies IDCT to each block of size block_size 
开发者ID:cg563,项目名称:simple-blackbox-attack,代码行数:19,代码来源:utils.py

示例3: run_fft_dct_example

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import dct [as 别名]
def run_fft_dct_example():
    random_state = np.random.RandomState(1999)

    fs, d = fetch_sample_speech_fruit()
    n_fft = 64
    X = d[0]
    X_stft = stft(X, n_fft)
    X_rr = complex_to_real_view(X_stft)
    X_dct = fftpack.dct(X_rr, axis=-1, norm='ortho')
    X_dct_sub = X_dct[1:] - X_dct[:-1]
    std = X_dct_sub.std(axis=0, keepdims=True)
    X_dct_sub += .01 * std * random_state.randn(
        X_dct_sub.shape[0], X_dct_sub.shape[1])
    X_dct_unsub = np.cumsum(X_dct_sub, axis=0)
    X_idct = fftpack.idct(X_dct_unsub, axis=-1, norm='ortho')
    X_irr = real_to_complex_view(X_idct)
    X_r = istft(X_irr, n_fft)[:len(X)]

    SNR = 20 * np.log10(np.linalg.norm(X - X_r) / np.linalg.norm(X))
    print(SNR)

    wavfile.write("fftdct_orig.wav", fs, soundsc(X))
    wavfile.write("fftdct_rec.wav", fs, soundsc(X_r)) 
开发者ID:kastnerkyle,项目名称:tools,代码行数:25,代码来源:audio_tools.py

示例4: plot

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import dct [as 别名]
def plot(self, ax=None, **kwargs):
        warnings.warn("Plotting the gammas and x_rotation_angles through DCT "
                      "and DST. If you are interested in v, u_singles and "
                      "u_pairs you can access them via params.v, "
                      "params.u_singles, params.u_pairs")
        if ax is None:
            fig, ax = plt.subplots()

        ax.plot(dct(self.v, n=self.n_steps),
                label="betas", marker="s", ls="", **kwargs)
        if not _is_iterable_empty(self.u_singles):
            ax.plot(dst(self.u_singles, n=self.n_steps),
                    label="gammas_singles", marker="^", ls="", **kwargs)
        if not _is_iterable_empty(self.u_pairs):
            ax.plot(dst(self.u_pairs, n=self.n_steps),
                    label="gammas_pairs", marker="v", ls="", **kwargs)
        ax.set_xlabel("timestep")
        ax.legend() 
开发者ID:entropicalabs,项目名称:entropica_qaoa,代码行数:20,代码来源:parameters.py

示例5: fourier_extended_to_extended

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import dct [as 别名]
def fourier_extended_to_extended(
        params: FourierExtendedParams) -> ExtendedParams:
    out = deepcopy(params)
    out.__class__ = ExtendedParams
    out.betas = dct(params.v, n=out.n_steps, axis=0)
    out.gammas_singles = dst(params.u_singles, n=out.n_steps, axis=0)
    out.gammas_pairs = dst(params.u_pairs, n=out.n_steps, axis=0)

    # and clean up
    del out.__u_singles
    del out.__u_pairs
    del out.__v
    del out.q

    return out


# #############################################################################
# And now all the possible compositions as well:
# Todo: Create this code automatically by traversing the tree?
# ############################################################################# 
开发者ID:entropicalabs,项目名称:entropica_qaoa,代码行数:23,代码来源:_parameter_conversions.py

示例6: mfcc

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import dct [as 别名]
def mfcc(signal,samplerate=16000,winlen=0.025,winstep=0.01,numcep=13,
          nfilt=26,nfft=512,lowfreq=0,highfreq=None,preemph=0.97,ceplifter=22,appendEnergy=True):
    """Compute MFCC features from an audio signal.

    :param signal: the audio signal from which to compute features. Should be an N*1 array
    :param samplerate: the samplerate of the signal we are working with.
    :param winlen: the length of the analysis window in seconds. Default is 0.025s (25 milliseconds)    
    :param winstep: the step between successive windows in seconds. Default is 0.01s (10 milliseconds)    
    :param numcep: the number of cepstrum to return, default 13    
    :param nfilt: the number of filters in the filterbank, default 26.
    :param nfft: the FFT size. Default is 512.
    :param lowfreq: lowest band edge of mel filters. In Hz, default is 0.
    :param highfreq: highest band edge of mel filters. In Hz, default is samplerate/2
    :param preemph: apply preemphasis filter with preemph as coefficient. 0 is no filter. Default is 0.97. 
    :param ceplifter: apply a lifter to final cepstral coefficients. 0 is no lifter. Default is 22. 
    :param appendEnergy: if this is true, the zeroth cepstral coefficient is replaced with the log of the total frame energy.
    :returns: A numpy array of size (NUMFRAMES by numcep) containing features. Each row holds 1 feature vector.
    """            
    feat,energy = fbank(signal,samplerate,winlen,winstep,nfilt,nfft,lowfreq,highfreq,preemph)
    feat = numpy.log(feat)
    feat = dct(feat, type=2, axis=1, norm='ortho')[:,:numcep]
    feat = lifter(feat,ceplifter)
    if appendEnergy: feat[:,0] = numpy.log(energy) # replace first cepstral coefficient with log of frame energy
    return feat 
开发者ID:znaoya,项目名称:aenet,代码行数:26,代码来源:base.py

示例7: mfccVTLP

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import dct [as 别名]
def mfccVTLP(signal,samplerate=16000,winlen=0.025,winstep=0.01,numcep=13,
          nfilt=26,nfft=512,lowfreq=0,highfreq=None,preemph=0.97,ceplifter=22,appendEnergy=True, alpha=1.0):
    """Compute MFCC features from an audio signal.

    :param signal: the audio signal from which to compute features. Should be an N*1 array
    :param samplerate: the samplerate of the signal we are working with.
    :param winlen: the length of the analysis window in seconds. Default is 0.025s (25 milliseconds)
    :param winstep: the step between successive windows in seconds. Default is 0.01s (10 milliseconds)
    :param numcep: the number of cepstrum to return, default 13
    :param nfilt: the number of filters in the filterbank, default 26.
    :param nfft: the FFT size. Default is 512.
    :param lowfreq: lowest band edge of mel filters. In Hz, default is 0.
    :param highfreq: highest band edge of mel filters. In Hz, default is samplerate/2
    :param preemph: apply preemphasis filter with preemph as coefficient. 0 is no filter. Default is 0.97.
    :param ceplifter: apply a lifter to final cepstral coefficients. 0 is no lifter. Default is 22.
    :param appendEnergy: if this is true, the zeroth cepstral coefficient is replaced with the log of the total frame energy.
    :returns: A numpy array of size (NUMFRAMES by numcep) containing features. Each row holds 1 feature vector.
    """
    feat,energy = fbankVTLP(signal,samplerate,winlen,winstep,nfilt,nfft,lowfreq,highfreq,preemph,False,alpha)
    feat = numpy.log(feat)
    feat = dct(feat, type=2, axis=1, norm='ortho')[:,:numcep]
    feat = lifter(feat,ceplifter)
    if appendEnergy: feat[:,0] = numpy.log(energy) # replace first cepstral coefficient with log of frame energy
    return feat 
开发者ID:znaoya,项目名称:aenet,代码行数:26,代码来源:base.py

示例8: DCT4

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import dct [as 别名]
def DCT4(samples):
    """
        Method to create DCT4 transformation using DCT3

        Arguments   :

            samples : (1D Array) Input samples to be transformed

        Returns     :

            y       :  (1D Array) Transformed output samples

    """

    # Initialize
    samplesup=np.zeros(2*N, dtype = np.float32)
    # Upsample signal:
    samplesup[1::2]=samples

    y=spfft.dct(samplesup,type=3,norm='ortho')*np.sqrt(2)#/2

    return y[0:N]

#The DST4 transform: 
开发者ID:TUIlmenauAMS,项目名称:ASP,代码行数:26,代码来源:qmf_realtime_class.py

示例9: main

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import dct [as 别名]
def main():
    ## Settings
    parser = argparse.ArgumentParser(description='PyTorch MNIST Example')
    parser.add_argument('--input-scp')
    parser.add_argument('--output-scp')
    parser.add_argument('--output-ark')
    parser.add_argument('--dct-dim', type=int)
    args = parser.parse_args()

    ark_scp_output='ark:| copy-feats --compress=true ark:- ark,scp:' + args.output_ark + ',' + args.output_scp
    
    with ko.open_or_fd(ark_scp_output,'wb') as f:
        for key, mat in ko.read_mat_scp(args.input_scp):
            dct_mat = fft.dct(mat, type=2, n=args.dct_dim)
            ko.write_mat(f, dct_mat, key=key)
            
    print('#################success#################') 
开发者ID:jefflai108,项目名称:Contrastive-Predictive-Coding-PyTorch,代码行数:19,代码来源:apply_dct.py

示例10: forward_dct

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import dct [as 别名]
def forward_dct(args, cpc_model, device, data_loader, output_ark, output_scp, dct_dim=24):
    ''' forward with dct '''

    logger.info("Starting Forward Passing")
    cpc_model.eval() # not training cdc model 

    ark_scp_output='ark:| copy-feats --compress=true ark:- ark,scp:' + output_ark + ',' + output_scp 
    with torch.no_grad():
        with ko.open_or_fd(ark_scp_output,'wb') as f:
            for [utt_id, data] in data_loader:
                data = data.float().unsqueeze(1).to(device) # add channel dimension
                data = data.contiguous()
                hidden = cpc_model.init_hidden(len(data))
                output, hidden = cpc_model.predict(data, hidden)
                mat = output.squeeze(0).cpu().numpy() # kaldi io does not accept torch tensor
                dct_mat = fft.dct(mat, type=2, n=dct_dim) # apply dct 
                ko.write_mat(f, dct_mat, key=utt_id[0]) 
开发者ID:jefflai108,项目名称:Contrastive-Predictive-Coding-PyTorch,代码行数:19,代码来源:forward_pass_v1.py

示例11: dctii

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import dct [as 别名]
def dctii(x, axes=None):
    """
    Compute a multi-dimensional DCT-II over specified array axes. This
    function is implemented by calling the one-dimensional DCT-II
    :func:`scipy.fftpack.dct` with normalization mode 'ortho' for each
    of the specified axes.

    Parameters
    ----------
    a : array_like
      Input array
    axes : sequence of ints, optional (default None)
      Axes over which to compute the DCT-II.

    Returns
    -------
    y : ndarray
      DCT-II of input array
    """

    if axes is None:
        axes = list(range(x.ndim))
    for ax in axes:
        x = fftpack.dct(x, type=2, axis=ax, norm='ortho')
    return x 
开发者ID:alphacsc,项目名称:alphacsc,代码行数:27,代码来源:linalg.py

示例12: run_fft_dct_example

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import dct [as 别名]
def run_fft_dct_example():
    random_state = np.random.RandomState(1999)

    fs, d = fetch_sample_speech_fruit()
    n_fft = 64
    X = d[0]
    X_stft = stft(X, fftsize=n_fft)
    X_rr = complex_to_real_view(X_stft)
    X_dct = fftpack.dct(X_rr, axis=-1, norm='ortho')
    X_dct_sub = X_dct[1:] - X_dct[:-1]
    std = X_dct_sub.std(axis=0, keepdims=True)
    X_dct_sub += .01 * std * random_state.randn(
        X_dct_sub.shape[0], X_dct_sub.shape[1])
    X_dct_unsub = np.cumsum(X_dct_sub, axis=0)
    X_idct = fftpack.idct(X_dct_unsub, axis=-1, norm='ortho')
    X_irr = real_to_complex_view(X_idct)
    X_r = istft(X_irr, n_fft)[:len(X)]

    SNR = 20 * np.log10(np.linalg.norm(X - X_r) / np.linalg.norm(X))
    print(SNR)

    wavfile.write("fftdct_orig.wav", fs, soundsc(X))
    wavfile.write("fftdct_rec.wav", fs, soundsc(X_r)) 
开发者ID:kastnerkyle,项目名称:representation_mixing,代码行数:25,代码来源:audio.py

示例13: dct

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import dct [as 别名]
def dct(x, null_hypothesis=None, counts=1):
    """
    Returns the Type-II discrete cosine transform of y, with an orthogonal normalization, where

    y = (x - counts * null_hypothesis)  / sqrt(counts * null_hypothesis * (1-null_hypothesis)),

    where the arithmetic is element-wise, and `null_hypothesis` is a vector in (0,1).
    If `null_hypothesis` is None it is set to the mean of x. If that mean is 0 or 1 then
    the vector of all ones, except for the first element which is set to zero, is returned.

    Parameters
    ----------
    x : array
        Data string, on which the normalization and discrete cosine transformation is performed. If
        counts is not specified, this must be a bit string.

    null_hypothesis : array, optional
        If not None, an array to use in the normalization before the dct. If None, it is
        taken to be an array in which every element is the mean of x.

    counts : int, optional
        A factor in the normalization, that should correspond to the counts-per-timestep (so
        for full time resolution this is 1).

    Returns
    -------
    array
        The DCT modes described above.

    """
    standardized_x = standardizer(x, null_hypothesis, counts)

    if standardized_x is None:
        out = _np.ones(len(x))
        out[0] = 0.
        return out

    modes = _dct(standardized_x, norm='ortho')

    return modes 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:42,代码来源:signal.py

示例14: lowpass_filter

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import dct [as 别名]
def lowpass_filter(data, max_freq=None):
    """
    Implements a low-pass filter on the input array, by DCTing the input, mapping all but the lowest
    `max_freq` modes to zero, and then inverting the transform.

    Parameters
    ----------
    data : numpy.array,
        The vector to low-pass filter

    max_freq : None or int, optional
        The highest frequency to keep. If None then it keeps the minimum of 50 or l/10 frequencies, where l is the
        length of the data vector

    Returns
    -------
    numpy.array
        The low-pass-filtered data.
    """
    n = len(data)

    if max_freq is None:
        max_freq = min(int(_np.ceil(n / 10)), 50)

    modes = _dct(data, norm='ortho')

    if max_freq < n - 1:
        modes[max_freq + 1:] = _np.zeros(len(data) - max_freq - 1)

    out = _idct(modes, norm='ortho')

    return out 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:34,代码来源:signal.py

示例15: mfcc_spec

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import dct [as 别名]
def mfcc_spec(audio, sample_rate, window_stride=(160, 80),
              fft_size=512, num_filt=20, num_coeffs=13, return_parts=False):
    """Calculates mel frequency cepstrum coefficient spectrogram"""
    powers = power_spec(audio, window_stride, fft_size)
    if powers.size == 0:
        return np.empty((0, min(num_filt, num_coeffs)))

    filters = filterbanks(sample_rate, num_filt, powers.shape[1])
    mels = safe_log(np.dot(powers, filters.T))  # Mel energies (condensed spectrogram)
    mfccs = dct(mels, norm='ortho')[:, :num_coeffs]  # machine readable spectrogram
    mfccs[:, 0] = safe_log(np.sum(powers, 1))  # Replace first band with log energies
    if return_parts:
        return powers, filters, mels, mfccs
    else:
        return mfccs 
开发者ID:MycroftAI,项目名称:sonopy,代码行数:17,代码来源:sonopy.py


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