2
$\begingroup$

The spectrogram if generally defined with the squared magnitude of the fft. However, in lots of implementation, it seems that people just use the magnitude without square.

Moreover an audio signal is by convention scale between -1 and 1. This scaling often needs a supplementary step in implementations, in python language for example, which is not always do.

Finally, what are best practices to compute an audio spectrogram? - square magnitude of the fft / magnitude of the fft ? - Integer audio values / scaling (-1 to 1) audio values

EDIT

As the comments tell, these are questions without consequences if the aim is to plot an image of the spectrogram.

However, I would like to use the matrix of the spectrogram as an entry point for sound analysis and recognition. In this case, the computation process matters and I find curious that the implementations differ so often.

$\endgroup$
  • 1
    $\begingroup$ Aren't all those issues mute, given the next step is a commonly a fairly arbitrary color mapping? $\endgroup$ – hotpaw2 Nov 19 '15 at 17:36
  • $\begingroup$ @hotpaw2 Indeed, when the final goal is to plot an image, this questions can be useless. However, I want to do some process on the matrix of the spectrogram. In this case, it matters. $\endgroup$ – sandoval31 Nov 19 '15 at 22:01
  • $\begingroup$ The best practices to display a nice or informative looking spectrogram (the most common use) are likely not the same as needed for doing some other processing on the data. So you will need to specify the needs of your desired processing to get a useful answer. $\endgroup$ – hotpaw2 Nov 19 '15 at 22:25
  • $\begingroup$ In most cases the best practice is to use a logarithmic scale such as decibels (dB). In this case there is no difference between magnitude and magnitude squared. The absolute scaling is just an offset and the best choice depends on the specific application $\endgroup$ – Hilmar Nov 20 '15 at 6:44
  • $\begingroup$ Mute and moot are different. These issues are moot - irrelevant. Mute means they can't speak, which is true but moot. :) $\endgroup$ – JRE Nov 20 '15 at 11:27
1
$\begingroup$

I think, perhaps, that the statement should be reversed: that a lot of implementations "just" use the square magnitude. This is because the DFT of a real-valued signal is typically complex, so that the square magnitude is just the product of complex conjugates, e.g.:

X*(f) · X(f)

This requires less computation than the magnitude, which would follow the same algorithm, but with a subsequent square-root.

The square magnitude of a DFT is formally known as the Power Spectrum.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.