栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

互相关是否滞后?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

互相关是否滞后?

首先看一些例子。假设我们已经在单元测试课上了。

# Autocorrelation.y1 = [1, 1, 0, 0, 1, -1, -1]corr, lag = cross_corr(y1, y1)self.assertEqual(lag, 0)y1 = [1, 1, 0 ,1, -1, -1]y2 = [1, 0, 1, 0, 0, 2]corr, lag = cross_corr(y1, y2)self.assertEqual(lag, -2)

这是我的代码。

import numpy as npdef cross_corr(y1, y2):  """Calculates the cross correlation and lags without normalization.  The definition of the discrete cross-correlation is in:  https://www.mathworks.com/help/matlab/ref/xcorr.html  Args:    y1, y2: Should have the same length.  Returns:    max_corr: Maximum correlation without normalization.    lag: The lag in terms of the index.  """  if len(y1) != len(y2):    raise ValueError('The lengths of the inputs should be the same.')  y1_auto_corr = np.dot(y1, y1) / len(y1)  y2_auto_corr = np.dot(y2, y2) / len(y1)  corr = np.correlate(y1, y2, mode='same')  # The unbiased sample size is N - lag.  unbiased_sample_size = np.correlate(      np.ones(len(y1)), np.ones(len(y1)), mode='same')  corr = corr / unbiased_sample_size / np.sqrt(y1_auto_corr * y2_auto_corr)  shift = len(y1) // 2  max_corr = np.max(corr)  argmax_corr = np.argmax(corr)  return max_corr, argmax_corr - shift


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/668140.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号