gpt4 book ai didi

iphone - 使用 Accelerate 框架进行 FFT 时如何设置缓冲区?

转载 作者:行者123 更新时间:2023-12-03 16:10:23 26 4
gpt4 key购买 nike

我正在使用 Accelerate 框架来执行快速傅立叶变换 (FFT),并试图找到一种方法来创建一个长度为 1024 的缓冲区供其使用。我可以访问平均峰值和我想要对其进行 FFT 的信号峰值。

有人可以帮助我或给我一些提示吗?

最佳答案

Apple 在其 vDSP Programming Guide 中提供了一些如何设置 FFT 的示例。 。您还应该查看vDSP Examples示例应用程序。对于 Mac,此代码也应该直接转换到 iOS。

我最近需要对 64 整数输入波形进行简单的 FFT,为此我使用了以下代码:

static FFTSetupD fft_weights;
static DSPDoubleSplitComplex input;
static double *magnitudes;

+ (void)initialize
{
/* Setup weights (twiddle factors) */
fft_weights = vDSP_create_fftsetupD(6, kFFTRadix2);

/* Allocate memory to store split-complex input and output data */
input.realp = (double *)malloc(64 * sizeof(double));
input.imagp = (double *)malloc(64 * sizeof(double));
magnitudes = (double *)malloc(64 * sizeof(double));
}

- (CGFloat)performAcceleratedFastFourierTransformAndReturnMaximumAmplitudeForArray:(NSUInteger *)waveformArray;
{
for (NSUInteger currentInputSampleIndex = 0; currentInputSampleIndex < 64; currentInputSampleIndex++)
{
input.realp[currentInputSampleIndex] = (double)waveformArray[currentInputSampleIndex];
input.imagp[currentInputSampleIndex] = 0.0f;
}

/* 1D in-place complex FFT */
vDSP_fft_zipD(fft_weights, &input, 1, 6, FFT_FORWARD);

input.realp[0] = 0.0;
input.imagp[0] = 0.0;

// Get magnitudes
vDSP_zvmagsD(&input, 1, magnitudes, 1, 64);

// Extract the maximum value and its index
double fftMax = 0.0;
vDSP_maxmgvD(magnitudes, 1, &fftMax, 64);

return sqrt(fftMax);
}

如您所见,我仅使用此 FFT 中的实际值来设置输入缓冲区,执行 FFT,然后读出幅度。

关于iphone - 使用 Accelerate 框架进行 FFT 时如何设置缓冲区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4804119/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com