How is FFT done in p5.sound…
i need fft Algorithm of p5.FFT .please…
1 Like
did you find
already?
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:
https://webaudio.github.io/web-audio-api/#current-frequency-data
…
https://github.com/WebKit/webkit/blob/89c28d471fae35f1788a0f857067896a10af8974/Source/WebCore/platform/audio/FFTFrame.h
https://github.com/WebKit/webkit/blob/89c28d471fae35f1788a0f857067896a10af8974/Source/WebCore/platform/audio/FFTFrame.cpp
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[0].length];
float[][] IM = new float[max_k][fourier[0].length];
float[][] AMP = new float[max_k][fourier[0].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