matlab中的互相关不使用内置函数?
有人能告诉我如何在 MATLAB 中进行两个语音信号(每个 40,000 个样本)的互相关而不使用内置函数 xcorr
和相关系数吗?
提前致谢。
can someone tell how to do the cross-correlation of two speech signals (each of 40,000 samples) in MATLAB without using the built-in function xcorr
and the correlation coefficient?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
fft
进行互相关。两个向量的互相关只是它们各自的傅里叶变换的乘积,其中一个变换是共轭的。示例:
比较结果:
You can do cross-correlations using
fft
. The cross-correlation of two vectors is simply the product of their respective Fourier transforms, with one of the transforms conjugated.Example:
Compare results:
如果有充分的理由不能使用内置函数,则可以使用卷积代替。互相关只是没有反转的卷积,因此要“撤消”相关积分的反转,您可以首先对其中一个信号应用额外的反转(这将在卷积中抵消)。
If there some good reason why you can't use the inbuilt, you can use a convolution instead. Cross-correlation is simply a convolution without the reversing, so to 'undo' the reversing of the correlation integral you can first apply an additional reverse to one of your signals (which will cancel out in the convolution).
嗯,尤达给出了一个很好的答案,但我想我还是提到这一点以防万一。回到离散互相关的定义,您可以在不使用(太多)内置 Matlab 函数的情况下计算它(这应该是 Matlab 使用
xcorr
所做的事情)。当然,仍然有改进的空间,因为我没有尝试对此进行矢量化:它与 xcorr 函数的结果匹配。
更新:忘了提及,在我看来,Matlab 不是进行大型数据集实时互相关的合适工具,我宁愿用 C 或其他编译语言进行尝试。
Well yoda gave a good answer but I thought I mention this anyway just in case. Coming back to the definition of the discrete cross correlation you can compute it without using (too much) builtin Matlab functions (which should be what Matlab do with
xcorr
). Of course there is still room for improvment as I did not try to vectorize this:Which match the result of the
xcorr
function.UPDATE: forgot to mention that in my opinion Matlab is not the appropriate tool for doing real time cross correlation of large data sets, I would rather try it in C or other compiled languages.