Apple ha alcuni esempi su come impostare FFT nel loro vDSP Programming Guide. Dovresti anche dare un'occhiata all'applicazione di esempio vDSP Examples. Mentre per il Mac, questo codice dovrebbe essere tradotto direttamente su iOS.
Recentemente ho bisogno di fare una semplice FFT di una forma d'onda di ingresso 64 intero, per cui ho usato il codice seguente:
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);
}
Come si può vedere, ho usato solo i valori reali in questo FFT per impostare su i buffer di input, eseguita la FFT, e quindi leggere le grandezze.
fonte
2011-01-26 16:57:47
In una delle sessioni WWDC2010 su Accelerate.Framework hanno parlato di questo. Potrei sbagliarmi ma * probabilmente * c'è un esempio a riguardo. Ad ogni modo, dovresti dare un'occhiata al riferimento Accelerate.Framework, ci sono funzioni molto utili per fare ciò che vuoi;) – nacho4d
Puoi dare un'occhiata alle risposte a [questa domanda StackOverflow] (http://stackoverflow.com/questions/ 3398753/using-the-apple-fft-and-accelerate-framework "questa domanda di overflow dello stack"). Un buon numero di buoni esempi sono forniti dall'utilizzo del framework Accelerate di Apple per generare un FFT di audio. – rcw3