How to check FFT results in iphone?

I made an FFT audio file using OouraFFTl. How to check if Sampled is correct or incorrect. Which makes the best and easiest way to test it. This is my code.

MyAudioFile  *audioFile = [[MyAudioFile alloc]init];
OSStatus result = [audioFile open:var ofType:@"wav"];
int numFrequencies=16384;
int kNumFFTWindows=10;

OouraFFT *myFFT = [[OouraFFT alloc] initForSignalsOfLength:numFrequencies*2    andNumWindows:kNumFFTWindows];
for(long i=0; i<myFFT.dataLength; i++)
 {
myFFT.inputData[i] = (double)audioFile.audioData[i];
} 
 [myFFT calculateWelchPeriodogramWithNewSignalSegment];
NSLog(@"the spectrum data 1 is  %f ",myFFT.spectrumData[1]);
NSLog(@"the spectrum data 2 is  %f",myFFT.spectrumData[2]);
NSLog(@"the spectrum data 8192 is  %f ",myFFT.spectrumData[8192]);

I created a class MyAudioFile containing

    -(OSStatus)open:(NSString *)fileName ofType:(NSString *)fileType{
OSStatus result = -1;

 CFStringRef filePath=fileName;

  CFURLRef audioFileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,      (CFStringRef)filePath, kCFURLPOSIXPathStyle, false);
 //open audio file
 result = AudioFileOpenURL (audioFileURL, kAudioFileReadPermission, 0, &mAudioFile);
 if (result == noErr) {
 //get  format info
 UInt32 size = sizeof(mASBD);

result = AudioFileGetProperty(mAudioFile, kAudioFilePropertyDataFormat, &size, &mASBD);

UInt32 dataSize = sizeof packetCount;
result = AudioFileGetProperty(mAudioFile, kAudioFilePropertyAudioDataPacketCount, &dataSize, &packetCount);
NSLog([NSString stringWithFormat:@"File Opened, packet Count: %d", packetCount]);

UInt32 packetsRead = packetCount;
UInt32 numBytesRead = -1;
if (packetCount > 0) { 
    //allocate  buffer
    audioData = (SInt16*)malloc( 2 *packetCount);
    //read the packets
    result = AudioFileReadPackets (mAudioFile, false, &numBytesRead, NULL, 0, &packetsRead,  audioData); 
    NSLog([NSString stringWithFormat:@"Read %d  bytes,  %d packets", numBytesRead, packetsRead]);
}
}
  else
  NSLog([NSString stringWithFormat:@"Could not open file: %@", filePath]);


CFRelease (audioFileURL);     
return result;
 }
+3
source share
3 answers

You need to scale the output of the FFT. I am not familiar with your programming language, but in Python you would use something like plot(abs(fft(a))). For silent input, the output must have all zeros. To enter a sine wave, you should see two peaks:

alt text

. FFT, ( ), , .

, . , , 0. "", .

+3

- . , .

+1

- , iFFT ( ) . . - RMS.

:

x n. X=FFT(x), y=iFFT(X). y n. , x y,

RMS_x=sqrt(x[0]*x[0] + x[1]*x[1] + ... + x[n]*x[n])
RMS_y=sqrt(y[0]*y[0] + y[1]*y[1] + ... + y[n]*y[n])

, ,

Error=abs(RMS_x - RMS_y)

, FFT/iFFT.

+1

Source: https://habr.com/ru/post/1771884/


All Articles