Change HopSize to improve the resolution of a Spectorgram

Hi, I’m new learning to use juce and I don’t know how to change the hopsize of a fft to improve the resolution of a spectorgram, is there someone who can help me in this??

So you want to perform successive FFTs on overlapping time signal snippets, do I get you right?

The juce FFT class only performs on FFT per call on the given buffer of input samples. To perform overlapping FFTs, you would need an extra FIFO holding your sample history and feeding each new FFT calculation with the right snippet of your input samples. This means something like the hop size is no property of the FFT itself but of the surrounding implementation that you have to build on your own.

Have you already made yourself familiar with the straightforward way of computing successive FFTs without overlap as described in this tutorial?

I am familiar with the simple calculation of the FFT but now I need to show the FFT in a spectogram like this, but I need to improve the resolution of the spectogram, but I don’t know how to improve it, I thought it was changing the hopsize of the FFT

Which resolutions do you want to increase? Frequency or time? Thanks to Heisenberg you can’t do both :wink:

1 Like

Do you actually mean the hop size (the tutorial code doesn’t implement a way of changing that) or the FFT size/order? If you want better frequency resolution, increase the FFT order from the 10 in the tutorial to some higher number. Order 10 would result in a FFT size of 1024, which is quite small. 11 would give you 2048, 12 gives you 4096 etc.

And what exactly do you mean by “Hop Size”?

I know this term when it comes to fourier analysis with overlapping input signal blocks, where the hop size denotes the offset of input samples between two successive FFT computations. So if you mean the same by hop size I already gave the answer above: As we talk about hop size between two successive FFT computations, the hop size is no property of the FFT itself but of how samples from your FFT input FIFO are read.

Or do you mean something else? A straightforward way to increase the frequency resolution is obviously to increase the FFT order, however you decrease the time resolution this way if you do it like its done in the tutorial you linked (where hop size equals a whole FFT input block).

Got a little class here which helps to do all that nasty overlap buffering and windowing stuff.

Per default, it uses a Hann-window, but you can use any window you want, and use different hopsizes. There’s also a small demo project included, which might help understand how to use that class :slight_smile:

Edit: Haven’t tested it with JUCE 5.4.4, but I am pretty sure the ProcessContextNonReplacing assertion might fire here:

void process (const dsp::ProcessContextReplacing<float> &context)
        dsp::ProcessContextNonReplacing<float> replacingContext (context.getInputBlock(), context.getOutputBlock());
        process (replacingContext);

So better to use the nonReplacing process call :wink: