本文整理匯總了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)
示例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))
示例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))
示例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
示例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
示例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)
示例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()
示例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
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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