(Minim) How to Limit Spectrum Range in FFT?

edited November 2017 in Library Questions

I have a successful FFT visualizer up and running, but I notice that with all the audio I test it with, the right half of the spectrum (roughly) is almost never being used, and it makes the thing look tacky. I am surprised to find there's not a straightforward method in the FFT object (to my awareness) for specifying the highest and lowest frequencies I'm interested in. Is there a feasible way to accomplish this? I am attempting to filter the results in other ways with no success.

Edit: I should also mention that I am getting linear averages, not accessing actual bands, and other components rely on the number of averages in an array being an exact value.



  • Answer ✓

    Some code would be nice. Or a picture.

    An mp3 probably won't have any frequencies in it above 16kHz - http://wiki.hydrogenaud.io/index.php?title=High-frequency_content_in_MP3s

    Other file types might be a bit better

  • edited November 2017

    Thank you much. What I've done for the time being is chop the right half of the spectrum off by using linAverages with double the amount of averages I actually want and just taking the first half. I've found that, even when frequencies register a small amount higher than that, it doesn't contribute anything interesting to the visual.

    My problem is pretty much solved, but I'll post some code for those trying to do something similar:

    public void initializeFFT() {
            fft = new FFT(Main.instance.audio.bufferSize(), Main.instance.audio.sampleRate());
            fft.linAverages(barCount * 2);
            fftStream = new float[barCount];
    public void updateFFT() {
            for (int a = 0; a < barCount; a++) {
                float raw = fft.getAvg(a );
                // Calculate the upper bound
                if (raw > maxAmp) {
                    maxAmp = Math.min(FFT_MAX, raw);
                    //System.out.println("New FFT Max: " + maxAmp);
                fftStream[a] = raw; // fftStream is a float[]
            // Convert the raw values into scalar values between 0 and 1
            for (int b = 0; b < barCount; b++)
                fftStream[b] = Main.norm(fftStream[b], 0, maxAmp);
Sign In or Register to comment.