使用 FFT 和加速框架了解自相关 - iPhone

发布于 2024-12-12 02:36:38 字数 1568 浏览 0 评论 0原文

我一直在尝试使用 Apple 提供的 vDSP 库(Accelerate 框架)在 iPhone 上实现自相关算法。

到目前为止,我按照苹果的 auriotouch 示例创建了一个音频单元,但我想使用加速框架来执行自相关,而不是 auriotouch 示例代码中的旧实现。

IORemote 音频单元通过我的 renderCallBack 方法进行路由,如下所示:

{
    AudioGraphController *controller = (AudioGraphController *) inRefCon;

    // Remove DC component
for(UInt32 i = 0; i < ioData->mNumberBuffers; ++i)
    controller.dcFilter[i].InplaceFilter((SInt32*)(ioData->mBuffers[i].mData),         inNumberFrames, 1);

    OSStatus result = AudioUnitRender(controller.inputUnit, ioActionFlags, inTimeStamp, 1,     inNumberFrames, ioData);

    if (result) { printf("InputRenderCallback: error %d\n", (int)result); return result; }

    controller.manager->ProcessAudioData(inNumberFrames, ioData);

    return noErr;
}

根据本文中的 c++ 代码片段,来自麦克风的输入数据被发送到执行自相关的 ProcessAudioData 方法: com/questions/3398753/using-the-apple-fft-and-accelerate-framework">使用 Apple FFT 和加速框架

但是我在理解上遇到了一些困难显示数据数组中的信息。

当我尝试访问所有信息时,我得到的都是 nan,我唯一了解该信息的时候是当我像这样转换 displaydata 数组时:

SInt16* buf = (SInt16 *)displayData;

计算自相关的步骤如下: - 将实际输入(ioData->mBuffers[0].mData)拆分为偶数和奇数输入。 - 执行 FFT(前向) - 取 FFT 生成值的绝对平方。 - 进行 IFFT(向后/逆) - 将复数分割转换为实数分割。

有人可以给我一些关于如何解释显示数据数组中的信息的指示/建议吗?当我检查这样的显示数据时,它们似乎都是相同的值,尽管它们确实根据麦克风输入而变化。

麦克风的输入预计是带有原始信号的一些回声的信号,自相关的目标是确定自相关峰值处的滞后,以便我可以确定回声相对于原始信号的偏移。

我应该首先创建信号的回声版本(有一些偏移)并在 FFT 值的乘法中使用它吗?

我很感激任何意见,如果你能指导我更清楚地解释这一点的信息,因为我对 vDSP 技术相当陌生,尤其是在 iPhone 上。我确实有卷积和傅立叶变换方面的数学经验,但是苹果的就地包装让我猜测在哪里可以找到我期望从这个计算中获得的信息。

I have been trying to implement an autocorrelation algorithm on the iPhone using the vDSP libraries supplied by Apple (Accelerate framework).

So far i created an audio unit following the auriotouch example of apple, but i want to use the accelerate framework for performing the autocorrelation instead of the older implementation in the example code of auriotouch.

The IORemote audio unit is routed trough my renderCallBack method like so:

{
    AudioGraphController *controller = (AudioGraphController *) inRefCon;

    // Remove DC component
for(UInt32 i = 0; i < ioData->mNumberBuffers; ++i)
    controller.dcFilter[i].InplaceFilter((SInt32*)(ioData->mBuffers[i].mData),         inNumberFrames, 1);

    OSStatus result = AudioUnitRender(controller.inputUnit, ioActionFlags, inTimeStamp, 1,     inNumberFrames, ioData);

    if (result) { printf("InputRenderCallback: error %d\n", (int)result); return result; }

    controller.manager->ProcessAudioData(inNumberFrames, ioData);

    return noErr;
}

The input data from the microphone is sent to a ProcessAudioData method which performs the autocorrelation, according the the c++ snippet in this post: Using the Apple FFT and Accelerate Framework

However i have some trouble understanding the information in the displaydata array.

When i try to access the information all i get is nan, the only time i get an idea of the information is when i cast the displaydata array like so:

SInt16* buf = (SInt16 *)displayData;

The steps to compute the autocorrelation i follow these steps:
- Split the real input (ioData->mBuffers[0].mData) to even and odd inputs.
- Perform a FFT (forward)
- Take the absolute square of the values generated by the FFT.
- Take the IFFT (backward/inverse)
- Convert the complex split to real.

Could someone give me some pointers/advice as how to interpret the information in the displaydata array, also when i do examine display data like this they seem to be all the same values, altho they do vary depending on the mic input.

The input of the microphone is expected to be a signal with some echoes of the original signal, the goal of the autocorrelation is to determine the lag where the autocorrelation peaks, so that i can determine the offset of the echo to the original signal.

Should i create a echoed version of the signal first (with some offset) and use that in the to multiple the values of the FFT?

I appreciate any input, also if you can guide me to information which explains this more clearly, since i fairly new with vDSP techniques especially on the iPhone. I do have mathematical experience with convolution and fourier transforms, but the in place packing of Apple is having me guessing where i can find the information i expect to get from this calculation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半衾梦 2024-12-19 02:36:38

检查您调用的每个例程(vDSP 等)的数据类型,并确保提供正确的 C 数据类型。使用调试器检查每个子例程的输入,在获得 NaN 结果之前开始并向后工作,以确保输入数据正确(类型和小数位数等)。您还可以将数据复制到以下缓冲区:出于调试目的,其格式更符合您的喜好,这样即使就地计算,您也可以看到之前/之后的结果。

另请注意,inNumberFrames 可能与您想要自相关的向量的长度无关,具体取决于您想要的结果信息。您可能需要额外的向量缓冲区。

Check the data types for each of the routines (vDSP, etc.) you call and make sure you are providing the correct C data type. Use the debugger to check the input to each subroutine, starting just before you get the NaN result and working backward, to make sure the input data is correct (type and scale, etc.) You can also copy the data to/from buffers that are formatted more to your liking for debug purposes, and so that you can see before/after results even for in-place calculations.

Also note that inNumberFrames may not be related to the length of the vector you want to autocorrelate, depending on what result information you want. You may need extra vector buffers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文