3

I have done FFT of a audio file using OouraFFTl.How to check whether the Sampled output is right or wrong.Whats the better and easy way to check 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 have created MyAudioFile class which contains

 -(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 Answers 3

3

You need to plot the magnitude of the output of the FFT. I'm not familiar with your programming language, but in Python you would use something like plot(abs(fft(a))). For a silent input, the output should be all zeros. For a sine wave input, you should see two spikes:

alt text

For a real signal, the spikes will be symmetrical from left to right. If you're doing a real FFT, though (which is more computationally efficient) you'll only get the left half of the plot as your output, since it ignores the redundant mirror image.

If the frequency is higher, the spikes will be closer to the center. If the frequency is perfectly in sync with the chunk size, the spike will only be one point wide and everything else will be very close to 0. Otherwise it will have a tapering "skirt" like above.

Sign up to request clarification or add additional context in comments.

Comments

1

The easy way to check FFT is take FFT of sinusoidal signal. The output should be all zeros except dozen of non-zero values.

Comments

1

The most common way is to take FFT and then to transform your resulted frequency spectrum with iFFT (inverse Fast Fourier Transform) back to the time-domain. Then you have to compare your input time-signal with the resulted time-signal. The easiest way to make comparison is to calculate a difference between both RMSs.

Example:

It is given a time-signal x of length n. Find X=FFT(x), then find y=iFFT(X). y will be of the same length n. Then, in order to compare x with y, calculate

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]) 

and finally,

Error=abs(RMS_x - RMS_y) 

The less is this error, the better is the quality of FFT/iFFT.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.