python correlate_Python numpy.correlate() 使用实例

The following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don’t like. You can also save this page to your account.

Example 1

def get_timepixel_g2( oned_count ):

n = len( oned_count )

norm = ( np.arange( n, 0, -1) *

np.array( [np.average(oned_count[i:]) for i in range( n )] ) *

np.array( [np.average(oned_count[0:n-i]) for i in range( n )] ) )

return np.correlate(oned_count, oned_count, mode = 'full')[-n:]/norm

#########################################

Example 2

def get_timepixel_g2( oned_count ):

n = len( oned_count )

norm = ( np.arange( n, 0, -1) *

np.array( [np.average(oned_count[i:]) for i in range( n )] ) *

np.array( [np.average(oned_count[0:n-i]) for i in range( n )] ) )

return np.correlate(oned_count, oned_count, mode = 'full')[-n:]/norm

#########################################

Example 3

def get_timepixel_g2( oned_count ):

n = len( oned_count )

norm = ( np.arange( n, 0, -1) *

np.array( [np.average(oned_count[i:]) for i in range( n )] ) *

np.array( [np.average(oned_count[0:n-i]) for i in range( n )] ) )

return np.correlate(oned_count, oned_count, mode = 'full')[-n:]/norm

#########################################

Example 4

def gi_correlation(self, p_gi_len, p_symbol_len, signal):

''' Mode Erkennung '''

corr_delay = p_symbol_len - p_gi_len

# Verzögertes Signal / Delay

corr_A = signal[0:p_gi_len-1];

corr_B = signal[corr_delay:len(signal)-1]

# Normierung

corr_A = corr_A / np.sqrt( np.sum(np.square(np.abs(corr_A))) )

corr_B = corr_B / np.sqrt( np.sum(np.square(np.abs(corr_B))) )

# Korrelation

erg_corr = np.correlate(corr_A,corr_B)

return erg_corr[0]

Example 5

def crosscorr(data, fb, fs, pairs=None):

"""

Parameters

----------

Returns

-------

"""

n_channels, n_samples = np.shape(data)

filtered, _, _ = analytic_signal(data, fb, fs)

r = np.zeros([n_channels, n_channels], dtype=np.float32)

for i in range(n_channels):

for ii in range(n_channels):

r[i, ii] = np.correlate(filtered[i, ], filtered[ii, ], mode='valid')

return r

Example 6

def estimate_range(tx,rx,fs,quiet=False):

"""

tx: the known, noise-free, undelayed transmit signal (bistatic radars agree beforehand on the psuedorandom sequence)

rx: the noisy, corrupted, interference, jammed signal to estimate distance from

fs: baseband sample frequency

"""

Rxy = np.correlate(tx, rx, 'full')

lags = np.arange(Rxy.size) - Rxy.size // 2

pklag = lags[Rxy.argmax()]

distest_m = -pklag / fs / 2 * c

mR = abs(Rxy) # magnitude of complex cross-correlation

if not quiet and figure is not None:

ax = figure().gca()

ax.plot(lags,mR)

ax.plot(pklag,mR[mR.argmax()], color='red', marker='*')

ax.set_title('cross-correlation of receive waveform with transmit waveform')

ax.set_ylabel('$|R_{xy}|$')

ax.set_xlabel('lags')

ax.set_xlim(pklag-100,pklag+100)

return distest_m

Example 7

def procchunk(rx, tx, P:dict):

if P['rxfn'] is not None:

rx = scipy.signal.resample_poly(rx,

P['resample'].numerator,

P['resample'].denominator)

fs = P['txfs']

# %% resamples parameters

NrxPRI = int(fs * P['pri']) # Number of RX samples per PRI (resampled)

assert NrxPRI >= tx.size,'PRI must be longer than chirp length!'

NrxChirp = rx.size // NrxPRI # number of complete PRIs received in this data

assert NrxChirp == P['Nchirp']

Rxy = 0.

for i in range(P['Nchirp']):

r = rx[i*NrxPRI:(i+1)*NrxPRI]

Rxy += np.correlate(tx, r,'same')

if P['verbose']:

plotxcor(Rxy, fs)

draw()

pause(0.1)

return Rxy

Example 8

def find_audio_period(aclip, t_min=.1, t_max=2, t_res=.01):

""" Finds the period, in seconds of an audioclip.

The beat is then given by bpm = 60/T

t_min and _tmax are bounds for the returned value, t_res

is the numerical precision

"""

chunksize = int(t_res*aclip.fps)

chunk_duration = 1.0*chunksize/aclip.fps

# v denotes the list of volumes

v = np.array([(c**2).sum() for c in

aclip.iter_chunks(chunksize)])

v = v-v.mean()

corrs = np.correlate(v, v, mode = 'full')[-len(v):]

corrs[:int(t_min/chunk_duration)]=0

corrs[int(t_max/chunk_duration):]=0

return chunk_duration*np.argmax(corrs)

Example 9

def extractMseq(cover, stego, secret_length, m, tau=1):

u"""Extract secret informations by spread spectrum using m-sequence.

@param cover : cover data (2 dimensional np.ndarray)

@param stego : stego data (2 dimension np.ndarray)

@param secret_length : length of secret information

@param m : M-Sequence

@param tau : embed shift interval

@return secret : extracted secret information

"""

cover = _image2vrctor(cover)

stego = _

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值