# FFT in p5.js p5.sound

How is FFT done in p5.sound…
i need fft Algorithm of p5.FFT .please…

1 Like

did you find

1 Like

No…There is no fft algorithm written there …
I want fft algorithm used in there…

correct, because they (p5.js) not do it, just send the array to…
more digging:

have fun!

1 Like

I wrote a dft function specifically to process some strain gauge signals. See if this can help you. Do note that the size of four[x][] will determine the sliding window and also the max k value that will be calculated

``````
//Sliding DFT function that calculates fourier transform
//works with even and uneven windows
void sliding_dft(float time[], float signal[], float[][] fourier) {
//Make the dimensions of fourier array same as time
for (int i = 0; i < fourier.length; i++) {
fourier[i] = expand(fourier[i], time.length);
}

//Create max_k and n
int max_k = fourier.length;
int n = max_k * 2;

//Create RE and IM arrays
float[][] RE = new float[max_k][fourier.length];
float[][] IM = new float[max_k][fourier.length];
float[][] AMP = new float[max_k][fourier.length];

int w_back = n/2;
int w_up = n/2;
println("w_back= " + w_back);
println("w_up= " + w_up);

for (int i = w_back; i < time.length - w_up; i++) {
for (int k = 0; k < max_k; k++) {
for (int j = 0; j < n; j++) {
RE[k][i] += signal[i - w_back + j] * cos((-TWO_PI * float(k) * float(j))/ float(n));
IM[k][i] += signal[i - w_back + j] * sin((-TWO_PI * float(k) * float(j))/ float(n));
}
fourier[k][i] = sqrt(pow(RE[k][i],2) + pow(IM[k][i],2));
AMP[k][i] = (2 * fourier[k][i])/n;
}
}
}
``````
2 Likes