OGeek|极客世界-中国程序员成长平台

标题: ios - 如何使用 vDSP_conv 来模拟 MATLAB 的 xcorr 函数? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 23:55
标题: ios - 如何使用 vDSP_conv 来模拟 MATLAB 的 xcorr 函数?

我目前正在将 MATLAB 算法转换为 C,以便在 iOS 应用程序中使用它。

我一直在努力使用 MATLAB 的 xcorr 函数。这是相关的MATLAB代码。

xcr = xcorr(A,A,maxlags);

这个,根据 MA​​TLAB 文档

returns the cross-correlation sequence over the lag range [-maxlags:maxlags]. Output c has length 2*maxlags+1.

Apple Accelerate.Framework 提供了一个名为 vDSP_conv 的卷积/相关函数,但我看不到如何使用它来产生与 xcorr 相同的输出.这可能吗 ?如果是,任何人都可以帮助我。

最好的问候,

相思



Best Answer-推荐答案


要复制 MATLAB 的 xcorr 的结果,您需要在向量前后用零填充:

#include <stdio.h>

#include <Accelerate/Accelerate.h>


int main(void)
{
    #define NF  3
    #define NC  (2*NF+1)

    float A[3*NF] = {0, 0, 0, 1, 2, 3, 0, 0, 0};
    float C[NC];

    vDSP_conv(A, 1, A+NF, 1, C, 1, NC, NF);

    for (vDSP_Length i = 0; i < NC; ++i)
        printf("C[%u] = %g.\n", (unsigned) i, C[i]);

    return 0;
}

关于ios - 如何使用 vDSP_conv 来模拟 MATLAB 的 xcorr 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13803950/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4