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


Python signal.correlate方法代码示例

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


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

示例1: test_pdos_1d

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_pdos_1d():
    pad=lambda x: pad_zeros(x, nadd=len(x)-1)
    n=500; w=welch(n)
    # 1 second signal
    t=np.linspace(0,1,n); dt=t[1]-t[0]
    # sum of sin()s with random freq and phase shift, 10 frequencies from
    # f=0...100 Hz
    v=np.array([np.sin(2*np.pi*f*t + rand()*2*np.pi) for f in rand(10)*100]).sum(0)
    f=np.fft.fftfreq(2*n-1, dt)[:n]

    c1=mirror(ifft(abs(fft(pad(v)))**2.0)[:n].real)
    c2=correlate(v,v,'full')
    c3=mirror(acorr(v,norm=False))
    assert np.allclose(c1, c2)
    assert np.allclose(c1, c3)

    p1=(abs(fft(pad(v)))**2.0)[:n]
    p2=(abs(fft(mirror(acorr(v,norm=False)))))[:n]
    assert np.allclose(p1, p2)

    p1=(abs(fft(pad(v*w)))**2.0)[:n]
    p2=(abs(fft(mirror(acorr(v*w,norm=False)))))[:n]
    assert np.allclose(p1, p2) 
开发者ID:elcorto,项目名称:pwtools,代码行数:25,代码来源:test_pdos.py

示例2: test_rank0

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_rank0(self, dt):
        a = np.array(np.random.randn()).astype(dt)
        a += 1j * np.array(np.random.randn()).astype(dt)
        b = np.array(np.random.randn()).astype(dt)
        b += 1j * np.array(np.random.randn()).astype(dt)

        y_r = (correlate(a.real, b.real)
               + correlate(a.imag, b.imag)).astype(dt)
        y_r += 1j * (-correlate(a.real, b.imag) + correlate(a.imag, b.real))

        y = correlate(a, b, 'full')
        assert_array_almost_equal(y, y_r, decimal=self.decimal(dt) - 1)
        assert_equal(y.dtype, dt)

        assert_equal(correlate([1], [2j]), correlate(1, 2j))
        assert_equal(correlate([2j], [3j]), correlate(2j, 3j))
        assert_equal(correlate([3j], [4]), correlate(3j, 4)) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:19,代码来源:test_signaltools.py

示例3: test_consistency_correlate_funcs

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_consistency_correlate_funcs(self):
        # Compare np.correlate, signal.correlate, signal.correlate2d
        a = np.arange(5)
        b = np.array([3.2, 1.4, 3])
        for mode in ['full', 'valid', 'same']:
            assert_almost_equal(np.correlate(a, b, mode=mode),
                                signal.correlate(a, b, mode=mode))
            assert_almost_equal(np.squeeze(signal.correlate2d([a], [b],
                                                              mode=mode)),
                                signal.correlate(a, b, mode=mode))

            # See gh-5897
            if mode == 'valid':
                assert_almost_equal(np.correlate(b, a, mode=mode),
                                    signal.correlate(b, a, mode=mode))
                assert_almost_equal(np.squeeze(signal.correlate2d([b], [a],
                                                                  mode=mode)),
                                    signal.correlate(b, a, mode=mode)) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:20,代码来源:test_signaltools.py

示例4: calculateBackgroundSignal

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def calculateBackgroundSignal(self, mat, vmat, nuc_cov):
        offset=self.start-mat.start-vmat.w
        if offset<0:
            raise Exception("Insufficient flanking region on \
                    mat to calculate signal")
        self.vmat = vmat
        self.bias_mat = mat
        self.cov = CoverageTrack(self.chrom, self.start, self.end)
        self.cov.calculateCoverage(self.bias_mat, vmat.lower,
                                   vmat.upper, vmat.w*2+1)
        self.nuc_cov = nuc_cov.vals
        self.vals = signal.correlate(self.bias_mat.get(vmat.lower,vmat.upper,
                                                         self.bias_mat.start + offset,
                                                         self.bias_mat.end - offset),
                                       vmat.mat,mode = 'valid')[0]
        self.vals = self.vals * self.nuc_cov/ self.cov.vals 
开发者ID:GreenleafLab,项目名称:NucleoATAC,代码行数:18,代码来源:NucleosomeCalling.py

示例5: gabor_feature_single_job

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def gabor_feature_single_job(a, filters, fm_i, label, cluster_center_number, save_flag):
    # convolution
    start_time = time.time()
    # b=SN.correlate(a,filters[i]) # too slow
    b = signal.correlate(a, filters[fm_i], mode='same')
    end_time = time.time()
    print('feature %d done (%f s)' % (fm_i, end_time - start_time))

    # show Gabor filter output
    if save_flag:
        img = (b[:, :, int(a.shape[2] / 2)]).copy()
        plt.imsave('./result/gabor_output(%d).png' % fm_i, img, cmap='gray')  # save fig

    # generate feature vector
    start_time = time.time()
    result = generate_feature_vector(b=b, label=label, cluster_center_number=cluster_center_number)
    end_time = time.time()
    print('feature vector %d done (%f s)' % (fm_i, end_time - start_time))
    return fm_i, result 
开发者ID:xulabs,项目名称:aitom,代码行数:21,代码来源:saliency_detection.py

示例6: offset_compensation

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def offset_compensation(x1, x2, ns, ndec, nlag=2000):
    '''Find and correct a constant time offset between two signals using a 
    cross-correlation
    
    Parameters:
        s1, s2:     Arrays containing the input signals
        ns:         Number of samples to use for cross-correlation
        ndec:       Decimation factor prior to cross-correlation
        nlag:       Number of lag bins for cross-correlation
    Returns:
        x2s:        The signal x2 time-shifted so that it aligns with x1. Edges 
                    are padded with zeros.         
    '''
    s1 = x1[0:int(ns)]
    s2 = x2[0:int(ns)]

    # cross-correlate to find the offset
    os = find_channel_offset(s1, s2, ndec, nlag)

    if(os == 0):
        return x2
    else:
        return shift(x2, os) 
开发者ID:Max-Manning,项目名称:passiveRadar,代码行数:25,代码来源:signal_utils.py

示例7: filter_and_smooth_angular_velocity

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def filter_and_smooth_angular_velocity(angular_velocity,
                                       low_pass_kernel_size, clip_percentile, plot=False):
  """Reduce the noise in a velocity signal."""

  max_value = np.percentile(angular_velocity, clip_percentile)
  print("Clipping angular velocity norms to {} rad/s ...".format(max_value))
  angular_velocity_clipped = np.clip(angular_velocity, -max_value, max_value)
  print("Done clipping angular velocity norms...")

  low_pass_kernel = np.ones((low_pass_kernel_size, 1)) / low_pass_kernel_size
  print("Smoothing with kernel size {} samples...".format(low_pass_kernel_size))

  angular_velocity_smoothed = signal.correlate(angular_velocity_clipped,
                                               low_pass_kernel, 'same')

  print("Done smoothing angular velocity norms...")

  if plot:
    plot_angular_velocities("Angular Velocities", angular_velocity,
                            angular_velocity_smoothed, True)

  return angular_velocity_smoothed.copy() 
开发者ID:ethz-asl,项目名称:hand_eye_calibration,代码行数:24,代码来源:time_alignment.py

示例8: _rmatvec

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def _rmatvec(self, x):
        x = np.reshape(x, self.dims)
        y = correlate(x, self.h, mode='same', method=self.method)
        y = y.ravel()
        return y 
开发者ID:equinor,项目名称:pylops,代码行数:7,代码来源:ConvolveND.py

示例9: estimate_time_shift

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def estimate_time_shift(x, y):
    """ Computes the cross-correlation between time series x and y, grabs the
        index of where it's a maximum.  This yields the time difference in
        samples between x and y.
    """
    if DEBUG: print("computing cross-correlation")
    corr = signal.correlate(y, x, mode='same', method='fft')
    if DEBUG: print("finished computing cross-correlation")

    nx, ny = len(x), len(y)
    t_samples = np.arange(nx)
    ct_samples = t_samples - nx//2  # try to center time shift (x axis) on zero
    cmax_ind = np.argmax(corr)      # where is the max of the cross-correlation?
    dt = ct_samples[cmax_ind]       # grab the time shift value corresponding to the max c-corr

    if DEBUG:
        print("cmax_ind, nx//2, ny//2, dt =",cmax_ind, nx//2, ny//2, dt)
        fig, (ax_x, ax_y, ax_corr) = plt.subplots(3, 1)
        ax_x.get_shared_x_axes().join(ax_x, ax_y)
        ax_x.plot(t_samples, x)
        ax_y.plot(t_samples, y)
        ax_corr.plot(ct_samples, corr)
        plt.show()
        
    return dt


#  for use in filtering filenames 
开发者ID:drscotthawley,项目名称:signaltrain,代码行数:30,代码来源:check_dataset.py

示例10: test_rank1_valid

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_rank1_valid(self):
        a, b, y_r = self._setup_rank1()
        y = correlate(a, b, 'valid')
        assert_array_almost_equal(y, y_r[1:4])
        self.assertTrue(y.dtype == self.dt) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:test_signaltools.py

示例11: test_rank1_same

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_rank1_same(self):
        a, b, y_r = self._setup_rank1()
        y = correlate(a, b, 'same')
        assert_array_almost_equal(y, y_r[:-1])
        self.assertTrue(y.dtype == self.dt) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:test_signaltools.py

示例12: test_rank1_full

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_rank1_full(self):
        a, b, y_r = self._setup_rank1()
        y = correlate(a, b, 'full')
        assert_array_almost_equal(y, y_r)
        self.assertTrue(y.dtype == self.dt) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:test_signaltools.py

示例13: test_rank3_valid

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_rank3_valid(self):
        a, b, y_r = self._setup_rank3()
        y = correlate(a, b, "valid")
        assert_array_almost_equal(y, y_r[1:2,2:4,3:5])
        self.assertTrue(y.dtype == self.dt) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:test_signaltools.py

示例14: test_rank3_same

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_rank3_same(self):
        a, b, y_r = self._setup_rank3()
        y = correlate(a, b, "same")
        assert_array_almost_equal(y, y_r[0:-1,1:-1,1:-2])
        self.assertTrue(y.dtype == self.dt) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:test_signaltools.py

示例15: _setup_rank1

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def _setup_rank1(self, mode):
        np.random.seed(9)
        a = np.random.randn(10).astype(self.dt)
        a += 1j * np.random.randn(10).astype(self.dt)
        b = np.random.randn(8).astype(self.dt)
        b += 1j * np.random.randn(8).astype(self.dt)

        y_r = (correlate(a.real, b.real, mode=mode) +
               correlate(a.imag, b.imag, mode=mode)).astype(self.dt)
        y_r += 1j * (-correlate(a.real, b.imag, mode=mode) +
                correlate(a.imag, b.real, mode=mode))
        return a, b, y_r 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:14,代码来源:test_signaltools.py


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