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.
IndexProgramming Questions & HelpSound,  Music Libraries › MINIM: Changing FFT "bin" size and respo
Page Index Toggle Pages: 1
MINIM: Changing FFT "bin" size and respo (Read 1501 times)
MINIM: Changing FFT "bin" size and respo
Oct 11th, 2007, 10:07am
 


Hey Guys, the minim reference is extremely thin. I've isolated  the appropriate FFT functions so that I can have different frequencies triggering different things, but how do I change the FFT scale? Is the only way to do it by changing the buffer size of the audio file loaded into the processing sketch?? I really only need 64 "bins" on the FFT, but by changing the buffer to 128 it really effects the quality of the audio.

Also, what is the syntax for changing the responsiveness of the FFT analysis?

Sorry if these are beginner questions, but I am... well... a beginner.

Re: MINIM: Changing FFT "bin" size and r
Reply #1 - Oct 11th, 2007, 10:54am
 
get your FFT buffer and divide it into the number of bins you need. you can even average the bins by the number of freqs it has. for a scaling just use some multiplier yourself. or normalize the fft if your problem is the higher frequencies.
Re: MINIM: Changing FFT "bin" size and r
Reply #2 - Oct 11th, 2007, 12:37pm
 
minim reference is fine, if you've downloaded the package containing the docs.

see examples/minim/FFT/LogarithmicAverages for an example of the above (in my experience the linear averages drop off far too steeply to be useful, the first couple of bands are ok, the rest are largely zero. the log averages are flatter)
Re: MINIM: Changing FFT "bin" size and r
Reply #3 - Oct 12th, 2007, 10:35am
 
ok, modified one of the minim examples to use linein rather than the given sample. prints 3 different representations of the incoming sound.

this produces 30 samples which is easily modified by changing the following two lines
 fftLin.linAverages(30);
 fftLog.logAverages(22, 3);
the latter of which i don't really understand but change the 3 to a 4 produces 40 samples.

/**
 * This sketch demonstrates the difference between linearly spaced averages and logarithmically spaced averages
 * (averages that are grouped by octave). It also draw the full spectrum so you can see how each set of averages
 * compares to it.
 * <p>
 * From top to bottom:
 * <ul>
 *  <li>The full spectrum.</li>
 *  <li>The spectrum grouped into 30 linearly spaced averages.</li>
 *  <li>The spectrum grouped logarithmically into 10 octaves, each split into 3 bands.</li>
 * </ul>
 *
 */

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

AudioInput jingle;
FFT fftLin;
FFT fftLog;
float height3;
float height23;

void setup()
{
 size(512, 300);
 height3 = height/3;
 height23 = 2*height/3;
 // always start Minim before you do anything with it
 Minim.start(this);
 // get LineIn
 jingle = Minim.getLineIn(Minim.STEREO);
 // create an FFT object that has a time-domain buffer the same size as jingle's sample buffer
 // note that this needs to be a power of two
 // and that it means the size of the spectrum will be 512.
 // see the online tutorial for more info.
 fftLin = new FFT(jingle.bufferSize(), jingle.sampleRate());
 // calculate the averages by grouping frequency bands linearly. use 30 averages.
 fftLin.linAverages(30);
 fftLog = new FFT(jingle.bufferSize(), jingle.sampleRate());
 // calculate averages based on a miminum octave width of 22 Hz
 // split each octave into three bands
 // this should result in 30 averages
 fftLog.logAverages(22, 3);
 rectMode(CORNERS);
}

void draw()
{
 background(0);
 // perform a forward FFT on the samples in jingle's mix buffer
 // note that if jingle were a MONO file, this would be the same as using jingle.left or jingle.right
 fftLin.forward(jingle.mix);
 
 stroke(255);
 noFill();
 // TOP - draw the full spectrum
 for(int i = 0; i < fftLin.specSize(); i++)
 {
   line(i, height3, i, height3 - fftLin.getBand(i)*2);
 }
 
 noStroke();
 fill(255);
 // MIDDLE - draw the linear averages
 int w = int(width/fftLin.avgSize());
 for(int i = 0; i < fftLin.avgSize(); i++)
 {
   // draw a rectangle for each average, multiply the value by 5 so we can see it better
   rect(i*w, height23, i*w + w, height23 - fftLin.getAvg(i)*5);
 }
 
 // BOTTOM - draw the logarithmic averages
 fftLog.forward(jingle.mix);
 w = int(width/fftLog.avgSize());
 for(int i = 0; i < fftLog.avgSize(); i++)
 {
   // draw a rectangle for each average
   rect(i*w, height, i*w + w, height - fftLog.getAvg(i));
 }
}

void stop()
{
 // always close Minim audio classes when you are done with them
 jingle.close();
 super.stop();
}
Re: MINIM: Changing FFT "bin" size and r
Reply #4 - Oct 15th, 2007, 1:42am
 
I do apologize about my utter failure to finish the manual. As mentioned, the Javadocs are very complete, but the whole point of writing the manual was because I don't expect most people to read the Javadocs. I will work on motivating myself to finish it.

As mentioned by koogs, you can set the number of averages that the FFT calculates. This is essentially the same thing as using a buffer size that is the same as the number of bins you want.
Page Index Toggle Pages: 1