TransferFunctions.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:PyPeVoc 作者: goiosunsw 项目源码 文件源码
def maxdelwind(source, target, rate=1, start_time=0., delta_time=1.,
               sample_duration=.5):
    '''
    delay, times = maxdelwid(...)

    Calculates a time-varying delay function from source (x)
    to target (y) at intervals delta_time.

    Parameters:
    * source: source signal (reuqired)
    * target: target signal (required)
    * rate:   sampling rate
    * start_time: starting time for tfe calculations
    * delta_time: distance between calculations
    * sample_duration: length of signals used in tfe estimates
                       (longer than window_duration, used in averaging)
    Returns:
    * delay: max delay array
    * times: times corresponding to delay estimates (array size M)
    '''

    # convert time to samples
    sample_start = int(start_time*rate)
    sample_delta = int(delta_time*rate)
    sample_len = int(sample_duration*rate)

    window = np.ones(sample_len)

    n_samples = min(len(source), len(target))
    sample_end = n_samples - sample_start - sample_len

    delay = []
    corr_strength = []
    times = []

    for block_start in np.arange(sample_start, sample_end, sample_delta):
        block_end = block_start + sample_len
        target_block = sig.detrend(target[block_start:block_end])
        source_block = sig.detrend(source[block_start:block_end])
        block_del, block_corr = block_delay(target_block, source_block,
                                            window=window)
        times.append((block_start+sample_len/2)/float(rate))
        delay.append(block_del/float(rate))
        corr_strength.append(block_corr)

    return np.array(delay), np.array(corr_strength), np.array(times)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号