xxxxxxxxxx
// the fast fourier transform (FFT)
// jean-baptiste joseph fourier
// fourier theorem:
// a periodic signal may be expressed
// as the sum of a series of sine waves,
// each of which has a specific
// amplitude and phase.
var themic; // this is the audio input
var thefft; // this is an FFT object
var x = 0;
var ystep = 0;
function setup() {
createCanvas(windowWidth, windowHeight);
background(0);
themic = new p5.AudioIn(); // listen to the mic
themic.start();
thefft = new p5.FFT();
thefft.setInput(themic); // listen to the microphone
}
function draw() {
//background(0);
stroke(255, 100);
let thespectrum = thefft.analyze();
for(let i = 0;i<thespectrum.length;i++)
{
let x = sqrt(i/thespectrum.length) * width; // exponential frequency spacing
let y = height - thespectrum[i]*1;
point(x, y - ystep);
}
ystep++;
if(ystep>height)
{
background(0);
ystep = 0;
}
}