iphone - OouraFFT 的输出有时正确,但有时完全错误。为什么?

标签 iphone algorithm fft

我正在使用 Ooura FFT 计算 1024 个样本窗口中加速度计数据的 FFT。该代码工作正常,但由于某种原因它会产生非常奇怪的输出,即幅度为 10^200 量级的连续频谱。

代码如下:

 OouraFFT *myFFT=[[OouraFFT alloc] initForSignalsOfLength:1024 NumWindows:10]; //       had to allocate it

 UIAcceleration *tempAccel = nil;


 double *input=(double *)malloc(1024 * sizeof(double));
 double *frequency=(double *)malloc(1024*sizeof(double));

 if (input)

 {

 //NSLog(@"%d",[array count]);
 for (int u=0; u<[array count]; u++)
 {
  tempAccel = (UIAcceleration *)[array objectAtIndex:u];
  input[u]=tempAccel.z;
  //NSLog(@"%g",input[u]);
 }

 }

 myFFT.inputData=input; // specifies input data to myFFT


 [myFFT calculateWelchPeriodogramWithNewSignalSegment]; // calculates FFT


 for (int i=0;i<myFFT.dataLength;i++) // loop to copy output of myFFT, length of spectrumData is half of input data, so copy twice
 {

  if (i<myFFT.numFrequencies)
  {
   frequency[i]=myFFT.spectrumData[i]; // 
  }
  else 

  {
   frequency[i]=myFFT.spectrumData[myFFT.dataLength-i]; // copy twice
  }

 }





 for (int i=0;i<[array count];i++)

 {
  TransformedAcceleration *NewAcceleration=[[TransformedAcceleration alloc]init];  
  tempAccel=(UIAcceleration*)[array objectAtIndex:i];

  NewAcceleration.timestamp=tempAccel.timestamp;
  NewAcceleration.x=tempAccel.x;
  NewAcceleration.y=tempAccel.z;
  NewAcceleration.z=frequency[i];
  [newcurrentarray addObject:NewAcceleration]; // this does not work

  //[self replaceAcceleration:NewAcceleration];
  //[NewAcceleration release];
  [NewAcceleration release];
 }

 TransformedAcceleration *a=nil;//[[TransformedAcceleration alloc]init]; // object containing fft of x,y,z accelerations


 for(int i=0; i<[newcurrentarray count]; i++)
 {
  a=(TransformedAcceleration *)[newcurrentarray objectAtIndex:i];
  //NSLog(@"%d,%@",i,[a printAcceleration]);
  fprintf(fp,[[a printAcceleration] UTF8String]);  //this is going wrong somewhow
 }

 fclose(fp);

 [array release];
 [myFFT release];
 //[array removeAllObjects];

 [newcurrentarray release];

 free(input);
 free(frequency);

最佳答案

您需要调用输入和输出数组。这是我代码中的一个错误,无法修复,因为这个库已被 Apple 的新 Accelerate 框架淘汰。

关于iphone - OouraFFT 的输出有时正确,但有时完全错误。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2463669/

相关文章:

ios - 尝试创建一个 Xcode Objective-C 函数来记录我的 UIView 内容的视频捕获并保存到手机

ios - iOS 中的手电筒闪光灯

java - 在图中构建随机哈密顿路径

C++、count_if 和 equals

c - 在 C 中使用 FFTW 求解泊松方程时失去径向对称性

c++ - 递归fft计算的段错误

ios - Xcode 看不到 segue

iphone - 如何在 Objective-C 中创建一个 json 字符串?

c++ - 3点之间的角度?

iphone - 使用苹果的 auriotouch 示例计算频率