gpt4 book ai didi

processing - 使用 Minim 在 Processing 中获取频率

转载 作者:行者123 更新时间:2023-12-04 05:50:12 26 4
gpt4 key购买 nike

我尝试使用处理从麦克风获取频率。我混合了文档中的两个示例,但“最高”并不是真正的赫兹(a 是 440 赫兹)。
你知道如何拥有比这更好的东西吗?

import ddf.minim.*;
import ddf.minim.analysis.*;

Minim minim;
AudioInput in;
FFT fft;
int highest=0;

void setup()
{
size(1024, 200, P2D);

minim = new Minim(this);
minim.debugOn();

in = minim.getLineIn(Minim.MONO, 4096, 44100);
fft = new FFT(in.left.size(), 44100);
}

void draw()
{


background(0);
stroke(255);

fft.forward(in.left);
highest=0;
for (int n = 0; n < fft.specSize(); n++) {
// draw the line for frequency band n, scaling it by 4 so we can see it a bit better
line(n/4, height, n/4, height - fft.getBand(n)*4);

//find frequency with highest amplitude
if (fft.getBand(n)>fft.getBand(highest))
highest=n;
}
println(highest);

//println(fft.getFreq(110));
// draw the waveforms
for (int i = 0; i < in.bufferSize() - 1; i++)
{
line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50);
line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50);
}
}


void stop()
{
// always close Minim audio classes when you are done with them
in.close();
minim.stop();

super.stop();
}

最佳答案

您需要进行一些转换,具体取决于您想要获得的内容:

The spectrum does not represent individual frequencies, but actually represents frequency bands centered on particular frequencies. The center frequency of each band is usually expressed as a fraction of the sampling rate of the time domain signal and is equal to the index of the frequency band divided by the total number of bands. The total number of frequency bands is usually equal to the length of the time domain signal, but access is only provided to frequency bands with indices less than half the length, because they correspond to frequencies below the Nyquist frequency. In other words, given a signal of length N, there will be N/2 frequency bands in the spectrum.

As an example, if you construct an FFT with a timeSize of 1024 and and a sampleRate of 44100 Hz, then the spectrum will contain values for frequencies below 22010 Hz, which is the Nyquist frequency (half the sample rate). If you ask for the value of band number 5, this will correspond to a frequency band centered on 5/1024 * 44100 = 0.0048828125 * 44100 = 215 Hz. The width of that frequency band is equal to 2/1024, expressed as a fraction of the total bandwidth of the spectrum. The total bandwith of the spectrum is equal to the Nyquist frequency, which in this case is 22100, so the bandwidth is equal to about 50 Hz. It is not necessary for you to remember all of these relationships, though it is good to be aware of them. The getFreq allows you to query the spectrum with a frequency in Hz and the method getBandWidth will return the bandwidth in Hz of each frequency band in the spectrum.



来自 Minim Manual, FFT section .

关于processing - 使用 Minim 在 Processing 中获取频率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10156296/

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