spectrogram: Be able to choose the DFT size #650

Open
opened 2025-10-14 16:01:27 +00:00 by martinwguy · 0 comments
martinwguy commented 2025-10-14 16:01:27 +00:00 (Migrated from codeberg.org)

spectrogram: Be able to choose the DFT size

Description

spectrogram chooses a DFT size of 2 * (y_size - 1), a hangover from when
the frequency axis always went from 0 to sample_rate / 2 so as to get
one output pixel per frequency bin.

Now that there is spectrogram -R to choose an arbitrary frequency range for the axis,
not to mention -L for a logarithmic axis, this choice has no foundation any more.

The DFT size determines two related things:

  • the difference between the center frequencies of adjacent DFT result bins, hence the frequency resolution
  • the number of sonic events it can discern per second, hence the time resolution of the spectrogram

It would be better if users could specify the DFT size (probably not directly - see below)
to trade off frequency resolution against time resolution.

It would also be better if the default DFT size were chosen according to the time represented by one pixel column so that all input samples are equally represented in the graph; at present, for a long piece, the DFTs are widely spaced in time so many samples
do not count at all towards the output.

Analysis

spettro, instead of talking in DFT sizes, has the happy concent of "FFT frequency"
which is the frequency difference between the centers of any two adjacent DFT output bins
and is also approximately the number of sonic events that can be determined per second.

The DFT size is then the sampling rate divided by the FFT frequency (or twice that figure).

-f is one of the few letters not currently an option to spectrogram.

Conclusion

Select a default DFT size according to the number of samples covered by each column
of the graph so that all input samples are equally represented in the output, checking
how that interacts with the resolution in the frequency domain.

Provide an "FFT frequency" option and, if it is given, choose the DFT size based on that
and the sample rate.

# spectrogram: Be able to choose the DFT size ## Description `spectrogram` chooses a DFT size of `2 * (y_size - 1)`, a hangover from when the frequency axis always went from 0 to `sample_rate / 2` so as to get one output pixel per frequency bin. Now that there is `spectrogram -R` to choose an arbitrary frequency range for the axis, not to mention `-L` for a logarithmic axis, this choice has no foundation any more. The DFT size determines two related things: * the difference between the center frequencies of adjacent DFT result bins, hence the frequency resolution * the number of sonic events it can discern per second, hence the time resolution of the spectrogram It would be better if users could specify the DFT size (probably not directly - see below) to trade off frequency resolution against time resolution. It would also be better if the default DFT size were chosen according to the time represented by one pixel column so that all input samples are equally represented in the graph; at present, for a long piece, the DFTs are widely spaced in time so many samples do not count at all towards the output. ## Analysis `spettro`, instead of talking in DFT sizes, has the happy concent of "FFT frequency" which is the frequency difference between the centers of any two adjacent DFT output bins and is also approximately the number of sonic events that can be determined per second. The DFT size is then the sampling rate divided by the FFT frequency (or twice that figure). `-f` is one of the few letters not currently an option to `spectrogram`. ## Conclusion Select a default DFT size according to the number of samples covered by each column of the graph so that all input samples are equally represented in the output, checking how that interacts with the resolution in the frequency domain. Provide an "FFT frequency" option and, if it is given, choose the DFT size based on that and the sample rate.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
martinwguy/sox_ng#650
No description provided.