jit.fft / FFT for spectrogram help

ndivuyo's icon

Hi all,

In the past I made a spectrogram using a method like the "sonograph" maxpatch example (which is sending audio signal from a buffer~ through an FFT and then recording those values into another buffer~)

This worked fine and I made my spectrogram. However, now I want to do the same thing, but not in real time, so I am using jit.fft (and also trying VB's external vb.FFTWbuf~).
They seem to work, but the values are just so different from the "sonograph" example approach, I can't make heads or tails on how to use what I end up with haha.

So my question is, how can I relate the data from my new approach, to the data from my old approach.?
-My old approach yielded me (in my own words) with amplitude peaks for the various frequency bins of each sample from the buffer. Those were easy to work with.
-New approach, I'm not sure what exactly I have.... with VB's object I get the magnitude in one half of the buffer, and the phase in the other have. I'm not sure what exactly the magnitude represents, and if I have to use it with the phase values to get what I want. With the jit.fft, I am only seeing magnitude values, pretty much what I get out of VB's first half. Can't seem to find the phase values though....

I attached some pictures of the 3 different buffers of FFT data. All are from the same audio source

First picture is from my first approach, the "sonograph" example (I only use the values in the first channel to draw the spectrogram)
Second is from my jit.fft (I zoom in a lot so you can see)
Third is from VB's object.

Any advice or direction I'd really appreciate! Thanks all!

ndivuyo's icon

Sorry, they were too big, here they are:

specFFTPix.zip
zip
volker böhm's icon

hi
"with VB’s object I get the magnitude in one half of the buffer, and the phase in the other have. I’m not sure what exactly the magnitude represents"
magnitudes represent what you described as "amplitude peaks for the various frequency bins".
"With the jit.fft, I am only seeing magnitude values, pretty much what I get out of VB’s first half. Can’t seem to find the phase values though…"
jit.fft doesn't give you magnitudes per se, but the real and imaginary parts of the spectrum.
without seeing your patch, i doubt anyone can tell what's going on. there are just too many things that can go wrong when working with ffts.

ndivuyo's icon

Hey, thanks for the response VB!
You're right, at the bottom is my patch. Sorry for sloppiness, just working things out.

So does that mean the magnitude I get from [vb.FFTWbuf~] is the amplitude peaks for the frequency bins for the ENTIRE buffer?
If so, then how could I get the amplitude peaks for the frequency bins of EVERY sample throughout the buffer via jitter? So I can draw a spectrogram.

That is the data I got from recording the FFT in the way the "sonograph" example did (signal->FFT->cartopol->record~). (Which is the first picture in my above attachment).

Max Patch
Copy patch and select New From Clipboard in Max.

Thanks again for any advice! I am trying to learn how this process works with jitter.

ndivuyo's icon

Sorry, I didn't give any instructions in the patch. Just drop an audio file into the dropfile object.

volker böhm's icon

So does that mean the magnitude I get from [vb.FFTWbuf~] is the amplitude peaks for the frequency bins for the ENTIRE buffer?

yes. and this is basically the same for jit.fft, too.
jit.fft relies on fft-sizes which are a power of 2, as opposed to vb.FFTWbuf~, which can calculate ffts of arbitrary size.
that's why the magnitude spectra in your example are similar but not identical.

If so, then how could I get the amplitude peaks for the frequency bins of EVERY sample throughout the buffer via jitter? So I can draw a spectrogram.

calculating the spectra ("amplitude peaks") of single samples doesn't make a lot of sense in this context. you get as many frequency domain samples back as you put time domain samples in - and how many "amplitude peaks" can be located in one sample?
i think you are looking for something called an STFT (short time/term fourier transform) - that is a sequence of spectra of consecutive little snippets of your time domain input signal (buffer based or realtime).
the example in this thread might help:https://cycling74.com/forums/spectrogram-that-behaves-like-waveformgets-data-from-buffer-instead-of-signs

ndivuyo's icon

Thanks again for the response!

Ok, you cleared up some aspects of FFT I was pondering myself, thanks for that!!

Yes that is what I am looking for, and actually I found that thread some days ago and used your example as the basis for the jitter section of my above patch.
So then I would run a loop through the entire audio buffer section by section performing a STFT on each section and then compile all of those STFT into one big buffer right?
If I am understanding correctly..

volker böhm's icon

So then I would run a loop through the entire audio buffer section by section performing a STFT on each section

yes, that's what the patch is doing.

...and then compile all of those STFT into one big buffer right?

yes. only the quoted patch stores the magnitude spectra in one big jitter matrix, not in a buffer.

ndivuyo's icon

Thanks so much VB!!
I think I got it to work, maybe you can double check for me?
I used the windowing method that you used in the link you provided, I think I am implementing it right?
I am using an uzi to do section by section with an 1024 FFT size for each section. Then I compile all the sections into a larger buffer.

Max Patch
Copy patch and select New From Clipboard in Max.

If I am doing this correctly, then maybe people will benefit from this VB inspired patch.

volker böhm's icon

the windowing looks ok to me, but please note, that the sections you feed into jit.fft should actually overlap, at least by 50 %.
that's why in my patch there is a hopsize of 512 samples.
your indexing for writing the spectra into the buffer seems a bit odd, but i don't have time to look into this carefully.
if in doubt you can check with the patch that i posted in the other thread.
all the best,
vb

ndivuyo's icon

Thanks! Ok yea I think I see what you are saying about overlapping. I ended up just skipping sections to render the image, it looks great.
be well