本文整理汇总了Python中scipy.signal.correlate方法的典型用法代码示例。如果您正苦于以下问题:Python signal.correlate方法的具体用法?Python signal.correlate怎么用?Python signal.correlate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块scipy.signal的用法示例。
在下文中一共展示了signal.correlate方法的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_pdos_1d
点赞 6
# 需要导入模块: 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,
示例2: test_rank0
点赞 6
# 需要导入模块: 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,
示例3: test_consistency_correlate_funcs
点赞 6
# 需要导入模块: 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,
示例4: calculateBackgroundSignal
点赞 6
# 需要导入模块: 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,
示例5: gabor_feature_single_job
点赞 6
# 需要导入模块: 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,
示例6: offset_compensation
点赞 6
# 需要导入模块: 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,
示例7: filter_and_smooth_angular_velocity
点赞 6
# 需要导入模块: 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,
示例8: _rmatvec
点赞 5
# 需要导入模块: 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,
示例9: estimate_time_shift
点赞 5
# 需要导入模块: 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,
示例10: test_rank1_valid
点赞 5
# 需要导入模块: 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,
示例11: test_rank1_same
点赞 5
# 需要导入模块: 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,
示例12: test_rank1_full
点赞 5
# 需要导入模块: 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,
示例13: test_rank3_valid
点赞 5
# 需要导入模块: 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,
示例14: test_rank3_same
点赞 5
# 需要导入模块: 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,
示例15: _setup_rank1
点赞 5
# 需要导入模块: 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,
示例16: test_rank3
点赞 5
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_rank3(self):
a = np.random.randn(10, 8, 6).astype(self.dt)
a += 1j * np.random.randn(10, 8, 6).astype(self.dt)
b = np.random.randn(8, 6, 4).astype(self.dt)
b += 1j * np.random.randn(8, 6, 4).astype(self.dt)
y_r = (correlate(a.real, b.real)
+ correlate(a.imag, b.imag)).astype(self.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-1)
self.assertTrue(y.dtype == self.dt)
开发者ID:ktraunmueller,项目名称:Computable,代码行数:15,
示例17: test_autocorr
点赞 5
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_autocorr(PM_da_control_3d):
"""Check autocorr results with scipy."""
ds = PM_da_control_3d.isel(x=5, y=5)
actual = autocorr(ds)
expected = correlate(ds, ds)
np.allclose(actual, expected)
开发者ID:bradyrx,项目名称:climpred,代码行数:8,
示例18: test_corr
点赞 5
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_corr(PM_da_control_3d):
"""Check autocorr results with scipy."""
ds = PM_da_control_3d.isel(x=5, y=5)
lag = 1
actual = corr(ds, ds, lag=lag)
expected = correlate(ds[:-lag], ds[lag:])
np.allclose(actual, expected)
开发者ID:bradyrx,项目名称:climpred,代码行数:9,
示例19: test_method
点赞 5
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_method(self, dt):
if dt == Decimal:
method = choose_conv_method([Decimal(4)], [Decimal(3)])
assert_equal(method, 'direct')
else:
a, b, y_r = self._setup_rank3(dt)
y_fft = correlate(a, b, method='fft')
y_direct = correlate(a, b, method='direct')
assert_array_almost_equal(y_r, y_fft, decimal=self.equal_tolerance(y_fft.dtype))
assert_array_almost_equal(y_r, y_direct, decimal=self.equal_tolerance(y_fft.dtype))
assert_equal(y_fft.dtype, dt)
assert_equal(y_direct.dtype, dt)
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:15,
示例20: test_rank1_valid
点赞 5
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_rank1_valid(self, dt):
a, b, y_r = self._setup_rank1(dt)
y = correlate(a, b, 'valid')
assert_array_almost_equal(y, y_r[1:4])
assert_equal(y.dtype, dt)
# See gh-5897
y = correlate(b, a, 'valid')
assert_array_almost_equal(y, y_r[1:4][::-1])
assert_equal(y.dtype, dt)
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:12,
示例21: test_rank1_same
点赞 5
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_rank1_same(self, dt):
a, b, y_r = self._setup_rank1(dt)
y = correlate(a, b, 'same')
assert_array_almost_equal(y, y_r[:-1])
assert_equal(y.dtype, dt)
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:7,
示例22: test_rank1_full
点赞 5
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_rank1_full(self, dt):
a, b, y_r = self._setup_rank1(dt)
y = correlate(a, b, 'full')
assert_array_almost_equal(y, y_r)
assert_equal(y.dtype, dt)
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:7,
示例23: test_rank3_same
点赞 5
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_rank3_same(self, dt):
a, b, y_r = self._setup_rank3(dt)
y = correlate(a, b, "same")
assert_array_almost_equal(y, y_r[0:-1, 1:-1, 1:-2])
assert_equal(y.dtype, dt)
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:7,
示例24: test_rank3_all
点赞 5
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_rank3_all(self, dt):
a, b, y_r = self._setup_rank3(dt)
y = correlate(a, b)
assert_array_almost_equal(y, y_r)
assert_equal(y.dtype, dt)
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:7,
示例25: test_invalid_shapes
点赞 5
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_invalid_shapes(self):
# By "invalid," we mean that no one
# array has dimensions that are all at
# least as large as the corresponding
# dimensions of the other array. This
# setup should throw a ValueError.
a = np.arange(1, 7).reshape((2, 3))
b = np.arange(-6, 0).reshape((3, 2))
assert_raises(ValueError, correlate, *(a, b), **{'mode': 'valid'})
assert_raises(ValueError, correlate, *(b, a), **{'mode': 'valid'})
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:13,
示例26: test_invalid_params
点赞 5
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_invalid_params(self):
a = [3, 4, 5]
b = [1, 2, 3]
assert_raises(ValueError, correlate, a, b, mode='spam')
assert_raises(ValueError, correlate, a, b, mode='eggs', method='fft')
assert_raises(ValueError, correlate, a, b, mode='ham', method='direct')
assert_raises(ValueError, correlate, a, b, mode='full', method='bacon')
assert_raises(ValueError, correlate, a, b, mode='same', method='bacon')
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:10,
示例27: test_mismatched_dims
点赞 5
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import correlate [as 别名]
def test_mismatched_dims(self):
# Input arrays should have the same number of dimensions
assert_raises(ValueError, correlate, [1], 2, method='direct')
assert_raises(ValueError, correlate, 1, [2], method='direct')
assert_raises(ValueError, correlate, [1], 2, method='fft')
assert_raises(ValueError, correlate, 1, [2], method='fft')
assert_raises(ValueError, correlate, [1], [[2]])
assert_raises(ValueError, correlate, [3], 2)
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:10,
注:本文中的scipy.signal.correlate方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。