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


Python signal.periodogram方法代码示例

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


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

示例1: find_peak

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import periodogram [as 别名]
def find_peak(fname):
    """Find the signal frequency and maximum value"""
    #print("find_peak",fname)
    Fs, x = wavfile.read(fname)
    f,s = periodogram(x, Fs,'blackman',8192,'linear', False, scaling='spectrum')
    threshold = max(s)*0.8  # only 0.4 ... 1.0 of max value freq peaks included
    maxtab, mintab = peakdet(abs(s[0:int(len(s)/2-1)]), threshold,f[0:int(len(f)/2-1)] )
    try:
        val = maxtab[0,0]
    except:
        print("Error: {}".format(maxtab))
        val = 600.
    return val

# Fs should be 8000 Hz 
# with decimation down to 125 Hz we get 8 msec / sample
# with WPM equals to 20 => Tdit = 1200/WPM = 60 msec   (time of 'dit')
# 4 seconds equals 256 samples ~ 66.67 Tdits 
# word 'PARIS' is 50 Tdits 
开发者ID:ag1le,项目名称:LSTM_morse,代码行数:21,代码来源:MorseDecoder.py

示例2: test_real_onesided_odd

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import periodogram [as 别名]
def test_real_onesided_odd(self):
        x = np.zeros(15)
        x[0] = 1
        f, p = periodogram(x)
        assert_allclose(f, np.arange(8.0)/15.0)
        q = np.ones(8)
        q[0] = 0
        q[-1] /= 2.0
        q *= 2.0/15.0
        assert_allclose(p, q, atol=1e-15) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:12,代码来源:test_spectral.py

示例3: test_real_onesided_even

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import periodogram [as 别名]
def test_real_onesided_even(self):
        x = np.zeros(16)
        x[0] = 1
        f, p = periodogram(x)
        assert_allclose(f, np.linspace(0, 0.5, 9))
        q = np.ones(9)
        q[0] = 0
        q[-1] /= 2.0
        q /= 8
        assert_allclose(p, q) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:12,代码来源:test_spectral.py

示例4: test_real_twosided

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import periodogram [as 别名]
def test_real_twosided(self):
        x = np.zeros(16)
        x[0] = 1
        f, p = periodogram(x, return_onesided=False)
        assert_allclose(f, fftpack.fftfreq(16, 1.0))
        q = np.ones(16)/16.0
        q[0] = 0
        assert_allclose(p, q) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_spectral.py

示例5: test_real_spectrum

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import periodogram [as 别名]
def test_real_spectrum(self):
        x = np.zeros(16)
        x[0] = 1
        f, p = periodogram(x, scaling='spectrum')
        g, q = periodogram(x, scaling='density')
        assert_allclose(f, np.linspace(0, 0.5, 9))
        assert_allclose(p, q/16.0) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:9,代码来源:test_spectral.py

示例6: test_complex

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import periodogram [as 别名]
def test_complex(self):
        x = np.zeros(16, np.complex128)
        x[0] = 1.0 + 2.0j
        f, p = periodogram(x)
        assert_allclose(f, fftpack.fftfreq(16, 1.0))
        q = 5.0*np.ones(16)/16.0
        q[0] = 0
        assert_allclose(p, q) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_spectral.py

示例7: test_nd_axis_m1

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import periodogram [as 别名]
def test_nd_axis_m1(self):
        x = np.zeros(20, dtype=np.float64)
        x = x.reshape((2,1,10))
        x[:,:,0] = 1.0
        f, p = periodogram(x)
        assert_array_equal(p.shape, (2, 1, 6))
        assert_array_almost_equal_nulp(p[0,0,:], p[1,0,:], 60)
        f0, p0 = periodogram(x[0,0,:])
        assert_array_almost_equal_nulp(p0[np.newaxis,:], p[1,:], 60) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:test_spectral.py

示例8: test_nd_axis_0

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import periodogram [as 别名]
def test_nd_axis_0(self):
        x = np.zeros(20, dtype=np.float64)
        x = x.reshape((10,2,1))
        x[0,:,:] = 1.0
        f, p = periodogram(x, axis=0)
        assert_array_equal(p.shape, (6,2,1))
        assert_array_almost_equal_nulp(p[:,0,0], p[:,1,0], 60)
        f0, p0 = periodogram(x[:,0,0])
        assert_array_almost_equal_nulp(p0, p[:,1,0]) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:test_spectral.py

示例9: test_window_external

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import periodogram [as 别名]
def test_window_external(self):
        x = np.zeros(16)
        x[0] = 1
        f, p = periodogram(x, 10, 'hanning')
        win = signal.get_window('hanning', 16)
        fe, pe = periodogram(x, 10, win)
        assert_array_almost_equal_nulp(p, pe)
        assert_array_almost_equal_nulp(f, fe) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_spectral.py

示例10: test_padded_fft

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import periodogram [as 别名]
def test_padded_fft(self):
        x = np.zeros(16)
        x[0] = 1
        f, p = periodogram(x)
        fp, pp = periodogram(x, nfft=32)
        assert_allclose(f, fp[::2])
        assert_allclose(p, pp[::2])
        assert_array_equal(pp.shape, (17,)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_spectral.py

示例11: test_empty_input

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import periodogram [as 别名]
def test_empty_input(self):
        f, p = periodogram([])
        assert_array_equal(f.shape, (0,))
        assert_array_equal(p.shape, (0,))
        for shape in [(0,), (3,0), (0,5,2)]:
            f, p = periodogram(np.empty(shape))
            assert_array_equal(f.shape, shape)
            assert_array_equal(p.shape, shape) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_spectral.py

示例12: test_nfft_is_xshape

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import periodogram [as 别名]
def test_nfft_is_xshape(self):
        x = np.zeros(16)
        x[0] = 1
        f, p = periodogram(x, nfft=16)
        assert_allclose(f, np.linspace(0, 0.5, 9))
        q = np.ones(9)
        q[0] = 0
        q[-1] /= 2.0
        q /= 8
        assert_allclose(p, q) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:12,代码来源:test_spectral.py

示例13: test_frequency

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import periodogram [as 别名]
def test_frequency(self):
        """Test if frequency location of peak corresponds to frequency of
        generated input signal.
        """

        # Input parameters
        ampl = 2.
        w = 1.
        phi = 0.5 * np.pi
        nin = 100
        nout = 1000
        p = 0.7  # Fraction of points to select

        # Randomly select a fraction of an array with timesteps
        np.random.seed(2353425)
        r = np.random.rand(nin)
        t = np.linspace(0.01*np.pi, 10.*np.pi, nin)[r >= p]

        # Plot a sine wave for the selected times
        x = ampl * np.sin(w*t + phi)

        # Define the array of frequencies for which to compute the periodogram
        f = np.linspace(0.01, 10., nout)

        # Calculate Lomb-Scargle periodogram
        P = lombscargle(t, x, f)

        # Check if difference between found frequency maximum and input
        # frequency is less than accuracy
        delta = f[1] - f[0]
        assert_(w - f[np.argmax(P)] < (delta/2.)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:33,代码来源:test_spectral.py

示例14: test_amplitude

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import periodogram [as 别名]
def test_amplitude(self):
        """Test if height of peak in normalized Lomb-Scargle periodogram
        corresponds to amplitude of the generated input signal.
        """

        # Input parameters
        ampl = 2.
        w = 1.
        phi = 0.5 * np.pi
        nin = 100
        nout = 1000
        p = 0.7  # Fraction of points to select

        # Randomly select a fraction of an array with timesteps
        np.random.seed(2353425)
        r = np.random.rand(nin)
        t = np.linspace(0.01*np.pi, 10.*np.pi, nin)[r >= p]

        # Plot a sine wave for the selected times
        x = ampl * np.sin(w*t + phi)

        # Define the array of frequencies for which to compute the periodogram
        f = np.linspace(0.01, 10., nout)

        # Calculate Lomb-Scargle periodogram
        pgram = lombscargle(t, x, f)

        # Normalize
        pgram = np.sqrt(4 * pgram / t.shape[0])

        # Check if difference between found frequency maximum and input
        # frequency is less than accuracy
        assert_approx_equal(np.max(pgram), ampl, significant=2) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:35,代码来源:test_spectral.py

示例15: plot_freq_response

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import periodogram [as 别名]
def plot_freq_response(noise, a, b, fs=44100):

    def spec(sig):
        return signal.periodogram(sig, fs=fs, window='hann', scaling='spectrum')

    f, noise_s = spec(noise)
    print('noise', noise_s.shape)

    df = pandas.DataFrame({
        'f': f,
        'original': noise_s,
        'a': spec(a)[1],
        'b': spec(b)[1],
    })
    df.plot(x='f', logy=True, logx=True, xlim=(10, fs/2)) 
开发者ID:emlearn,项目名称:emlearn,代码行数:17,代码来源:test_filters.py


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