Python scipy.signal 模块,tukey() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用scipy.signal.tukey()

项目:fem    作者:mlp6    | 项目源码 | 文件源码
def tukey_z_scale(z, center, length, alpha=0.25, points=101):
    """

    :param z: z-coordinate
    :param center: center of Tukey window
    :param length: length of Tukey window
    :param alpha: rolloff (percentage of window)
    :param points: number of points in Tukey window
    :return: z_scale (scale, relative to 1.0)
    """
    import numpy as np
    from scipy.signal import tukey

    z = np.abs(z)
    zmin = np.abs(center) - length / 2
    zmax = np.abs(center) + length / 2
    z_tukey_win = np.linspace(zmin, zmax, points)
    z_tukey_amp = tukey(points, alpha)
    if z < zmin or z > zmax:
        z_scale = 0.0
    else:
        z_scale = z_tukey_amp[np.min(np.where(z_tukey_win >= z))]

    return z_scale
项目:BirdAudioDetectionChallenge2016    作者:RSPB    | 项目源码 | 文件源码
def plot_spectrogram(data, rate, name, dir_label):
    window_size = 2 ** 10
    overlap = window_size // 8
    window = sig.tukey(M=window_size, alpha=0.25)

    freq, time, spectrogram = sig.spectrogram(data, fs=rate, window=window, nperseg=window_size, scaling='density', noverlap=overlap)
    spectrogram = np.log10(np.flipud(spectrogram))
    try:
        if spectrogram.shape[1] > 512:
            spec_padded = spectrogram[:512,:512]
        elif spectrogram.shape[1] < 512:
            spec_padded = np.pad(spectrogram, ((0, 0), (0, 512 - spectrogram.shape[1])), mode='median')[:512, :]
        else:
            spec_padded = spectrogram
    except Exception as e:
        print('ERROR!')
        print('Fault in: {}'.format(name))
        raise
    spec_padded = transform.downscale_local_mean(spec_padded, (2, 2))

    final_path = os.path.join(output_dir, dir_label, name + '.png')
    plt.imsave(final_path, spec_padded, cmap=plt.get_cmap('gray'))
项目:SiteResponseTool    作者:GEMScienceTools    | 项目源码 | 文件源码
def Taper(self, Alpha):
    """
    Tukey window tapering
    """

    Win = _sig.tukey(self.HDR['NSMP'], alpha=Alpha)

    for I,S in enumerate(self.CHN):
      self.CHN[I] *= Win

  #---------------------------------------------------------------------------------------
项目:arlpy    作者:org-arl    | 项目源码 | 文件源码
def test_cw(self):
        self.assertArrayEqual(signal.cw(10000, 0.1, 50000), np.sin(2*np.pi*10000*np.arange(5000, dtype=np.float)/50000), precision=6)
        self.assertArrayEqual(signal.cw(10000, 0.1, 50000, ('tukey', 0.1)), sp.tukey(5000, 0.1)*np.sin(2*np.pi*10000*np.arange(5000, dtype=np.float)/50000), precision=2)
项目:arlpy    作者:org-arl    | 项目源码 | 文件源码
def test_sweep(self):
        self.assertArrayEqual(signal.sweep(5000, 10000, 0.1, 50000), sp.chirp(np.arange(5000, dtype=np.float)/50000, 5000, 0.1, 10000, 'linear'))
        self.assertArrayEqual(signal.sweep(5000, 10000, 0.1, 50000, 'hyperbolic'), sp.chirp(np.arange(5000, dtype=np.float)/50000, 5000, 0.1, 10000, 'hyperbolic'))
        self.assertArrayEqual(signal.sweep(5000, 10000, 0.1, 50000, window=('tukey', 0.1)), sp.tukey(5000, 0.1)*sp.chirp(np.arange(5000, dtype=np.float)/50000, 5000, 0.1, 10000), precision=2)
项目:stfinv    作者:seismology    | 项目源码 | 文件源码
def shift_waveform(tr, dtshift):
    """
    tr_shift = shift_waveform(tr, dtshift):

    Shift data in trace tr by dtshift seconds backwards.

    Parameters
    ----------
    tr : obspy.Trace
        Trace that contains the data to shift

    dtshift : float
        Time shift in seconds


    Returns
    -------
    tr_shift : obspy.Trace
        Copy of tr, but with data shifted dtshift seconds backwards.

    """
    data_pad = np.r_[tr.data, np.zeros_like(tr.data)]

    freq = fft.fftfreq(len(data_pad), tr.stats.delta)
    shiftvec = np.exp(- 2 * np.pi * complex(0., 1.) * freq * dtshift)
    data_fd = shiftvec * fft.fft(data_pad *
                                 signal.tukey(len(data_pad),
                                              alpha=0.2))

    tr.data = np.real(fft.ifft(data_fd))[0:tr.stats.npts]