0

I am currently working on a project for my 2nd year. I am supposed to code in java a tuner. I have chosen to do a guitar tuner.

After looking around on the internet, I found a java code to do a FFT. I changed it a bit, understood it and have tested it. I know it works fine (i made a graph of it and looked at the different peaks using simple sines functions).

I am now trying to find the fundamental frequency. From what I understand, this frequency is given by the first peak.

I would thus like to create a method that finds for instance the first 5 peaks of my FFT and gives them to me with their indexes.

I first did a simple method where I compared two by two each point of my spectrogram and when the sign changed that's where I knew there was a peak. This method works great with ideal signals (without any noise). However it becomes completely useless if I add noise.

I am really bad in java (I actually started with this project and basically the simple function I described above is my master piece.... just so you get an idea of my level).

Can anyone help me? I would really appreciate it! :) Thanks in advance!

Have a great day!

fireangel

4

1 回答 1

0

我想说你最好的选择是将所有值作为一个数组读取,然后遍历它们并使用某种滚动平均值“平滑”它们。

之后,您将拥有更平滑的曲线。使用这条曲线找到你的峰值,然后回到你的原始数据并使用峰值索引来找到那里的实际峰值。

伪代码:

// Your raw data
int[] data = getData();

// This is an array to hold your 'smoothed' data
int[] newData = new int[data.length]; 

// Iterate over your data, smooth it, and read it into your smoothed array
for (i <  data.length) {
    newData[i] = (data[i-2] + data[i-1] + data[i] + data[i+1] + data[i+2]) / 5;
}

// Use your existing peak finding function on your smoothed data, and get 
// another array of the indexes your peaks occur.
int[] peakIndexes = yourPeakFindingFunction(newData);

// Create an array to hold your final values.
int[] peakValues = new int[peakIndexes.length];

// Iterate over your peak indexes and get the original data's value at that location.
for(i < peakIndexes.length) {
    peadValues[i] = data[peakIndexes[i]];
}

非常基本且非常蛮力,但它应该让你走上正确的任务轨道。

您需要使用算法来平滑数据,使其具有代表性,并在平滑数据指示的位置找到实际峰值(因为它不准确)。

于 2012-05-04T18:03:47.713 回答