We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
ESS's FFT averages (Read 3876 times)
ESS's FFT averages
Mar 15th, 2007, 6:44pm
 
Can ESS's FFT be configured to use log-sized averaging bins?  Or has anyone already coded their own, accumulating the raw spectrum[] results?

For example, with the "inputFFT" example, 110Hz/220Hz/440Hz tones all trigger within the first bin, a 1KHz tone triggers within the second bin, and a 10Khz tone within about the 14th bin.

So clearly these are linear sized bins, but who needs 16 bands above 10KHz?!  I'd rather have (for example) 4 bands per octave, logarithmically spaced.  So 4 bands from 110-220Hz, 4 bands from 220-440, 4 bands from 440-880, etc.

Seems common enough that I thought I'd check before reinventing the wheel.
Re: ESS's FFT averages
Reply #1 - Mar 19th, 2007, 6:09pm
 
Never mind, DIY, in case anyone else wants something similar, feel free to borrom from:
http://www.davebollinger.com/works/p5/fftoctana/
Re: ESS's FFT averages
Reply #2 - Mar 19th, 2007, 7:57pm
 
Cool, I may work that into the FFT class for the audio library I'm working on, it it's OK with you.
Re: ESS's FFT averages
Reply #3 - Mar 20th, 2007, 3:22pm
 
Sure.  Smiley
Re: ESS's FFT averages
Reply #4 - Mar 21st, 2007, 8:58pm
 
Great work Dave!  This method provides a more natural connection between the frequency bin response and the harmonic/melodic construction of most music.  

I've been ignoring all but the first 1/4 of the bins, (thru 5khz - it seems most of the interesting stuff is in that range) and getting decent results, but as you mentioned its not too helpful to have 100-400 hz all trigger the same bin, etc.

Anyway I gotta plug your code into some of my projects and see how it looks! Thanks.

Re: ESS's FFT averages
Reply #5 - Mar 22nd, 2007, 1:48am
 
I've summed up this averaging stuff in a blog post. Hopefully it's not too obtuse: http://code.compartmental.net/2007/03/21/fft-averages/

Let me know if I've got anything horribly wrong.
Re: ESS's FFT averages
Reply #6 - Mar 22nd, 2007, 5:10pm
 
ddf wrote on Mar 22nd, 2007, 1:48am:
Let me know if I've got anything horribly wrong.


Looks fine to me.  Hee hee, I hope you're not looking to me for technical proof-reading, I know just barely enough to make me dangerous.  Cheesy

You've given it a much more rigorous treatment than I was interested in doing - like the width of the first band and exact center frequencies and etc, issues where I just said: "aww, close enough, I can see the kick now, weehaw!".

I would agree that it's appropriate to use 10 octaves (as in demo) rather than 12 (as in text) since probably only weapons engineers are interested in frequencies below 20Hz.

You could go nuts and look up exact ISO standard center frequencies, though it probably won't matter much for typical p5 uses.

Another area you could research is spectrum[0].  Isn't that the dc offset  And if so, might it be more appropriate to exclude it from averaging
Re: ESS's FFT averages
Reply #7 - Mar 22nd, 2007, 9:28pm
 
Yes, spectrum[0] is DC offset, but according to the book I reference in the first paragraph it is supposedly always zero, which I suppose pulls the first average down a bit. Haven't checked it myself to be sure.
Re: ESS's FFT averages
Reply #8 - Sep 14th, 2008, 2:23pm
 
Hi! This is probably a very simple problem (or two problems rather), but I'm a complete beginner with Processing and ESS, and we are trying to make a project to visualise microphone data. Using the FFT code that Dave kindly provided (thank you so much!), we've ran into two issues:

1. Replacing the Audiochannel in the pde with an audioinput produces no visualisation of the sound, but also throws no errors.

At the moment the code looks like this, with the only changes being changes from references to the audio channel to the new audioinput, myInput:

import krister.Ess.*;

AudioInput myInput;
FFT fft;
FFTOctaveAnalyzer oct;
int bufferSize = 1024;
int samplingRate = 44100;

void setup() {
 // init p5
 size(320,240);
 frameRate(30);
 noStroke();
 // init ess
 Ess.start(this);
 
// create a new AudioInput
 myInput=new AudioInput();
 
 // init fft
 fft = new FFT(bufferSize*2);
 fft.limits();
 fft.damp(0.5f);
 // init averages
 oct = new FFTOctaveAnalyzer(fft, samplingRate, 2);
 // common things you might want to "tweak" (see code for further comments)
 oct.peakHoldTime = 15; // hold longer
 oct.peakDecayRate = 0.95f; // decay slower
 oct.linearEQIntercept = 0.9f; // reduced gain at lowest frequency
 oct.linearEQSlope = 0.01f; // increasing gain at higher frequencies
}

void draw() {
 // update the fft and averages
 fft.getSpectrum(myInput);
 oct.calculate();
 // figure out screen size stuff
 float margin = 16f;
 float xspan = floor((width - margin * 2f) / (float)(oct.nAverages));
 float yspan = height - margin * 2f;
 // draw all bands:
 background(0);
 for (int i=0; i<oct.nAverages; i++) {
   // draw the average
   float x1 = margin + (float)(i) * xspan;
   float y2 = height - margin;
   fill(color(128,240,32));
   rect(x1, y2, xspan-1, -oct.averages[i]*yspan);
   // draw the peak
   y2 = height - margin - oct.peaks[i] * yspan;
   if (oct.peakHoldTimes[i] > 0)
     fill(color(64,128,192)); // peak color
   else
     fill(color(48,96,144)); // decay color
   rect(x1, y2, xspan-1, -2);
 }
}

public void stop() {
 Ess.stop();
 super.stop();
}

Can anyone see what I'm doing wrong?


Our other problem is that in a seperate experiment when we replace the AIF file in the data folder with one of our own, it plays back 'slowly' (stretched out and lower pitch). We are using AIF files exported in Quicktime as 16 bit Stereo 44100khz files. Trying to use a WAV produces the same result, whereas trying to use an mp3 doesn't even work - Processing says it can't find the mp3.

I'm sure that because we are beginners we are getting something very wrong with our fundamental knowledge of how ESS or Processing works. If anyone could help us that would be great! Thank you!

Re: ESS's FFT averages
Reply #9 - Nov 3rd, 2008, 8:17am
 
I hope you found it by now, but in case you did not find the answer to your first question:

in the draw(){ .... }
you have to add:
 myInput.start();

Good continuation
Page Index Toggle Pages: 1