gpt4 book ai didi

iphone - 如何在iphone中查看FFT结果?

转载 作者:行者123 更新时间:2023-12-03 19:40:28 25 4
gpt4 key购买 nike

我已经使用 OouraFFTl 对音频文件进行了 FFT。如何检查采样输出是否正确或错误。有什么更好、更简单的方法来检查它。这是我的代码。

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

我创建了 MyAudioFile 类,其中包含

    -(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;
}

最佳答案

您需要绘制 FFT 输出的幅度。我不熟悉您的编程语言,但在 Python 中您会使用诸如 plot(abs(fft(a))) 之类的东西。对于静默输入,输出应全为零。对于正弦波输入,您应该看到两个尖峰:

alt text

对于真实信号,尖峰从左到右对称。如果您正在执行 real FFT ,但是(计算效率更高)您只会得到图的左半部分作为输出,因为它忽略了冗余镜像。

如果频率较高,尖峰将更靠近中心。如果the frequency is perfectly in sync with the chunk size ,尖峰将只有一个点宽,其他一切都将非常接近 0。否则它将有一个像上面一样逐渐变细的“裙子”。

关于iphone - 如何在iphone中查看FFT结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4040918/

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