0
$\begingroup$

In this paper they preprocess an audio file with a STFT and then apply two equations to the computed matrix.

enter image description here

enter image description here

I tried implementing all of it in python and used librosa for the STFT. The issue I encountered is, that the matrix includes a lot of low values or zeros. By the 2. equations including log those values get transformed to nan latest in the second step. As soon as there are nans involved all future aggregations I want to compute doesn't work.

Here is an example of the magnitude spectrum, cent spectrum(EQ1) and cent scale(EQ2): enter image description here

What is the best way to solve such a problem? Do I have to transform the matrix I get from librosa further?

$\endgroup$
2
  • 1
    $\begingroup$ Add a very small value to $X[k]$ before taking the $\log$. Something like $1e^{-8}$ $\endgroup$
    – Jdip
    Jul 3, 2023 at 12:53
  • $\begingroup$ @Jdip I'm wondering, is this a common problem? $\endgroup$
    – Rocket
    Jul 3, 2023 at 13:12

1 Answer 1

1
$\begingroup$

The equation isn't entirely correct. Normally you would define the level as

$$L[k] = 20 \cdot \log_{10}\frac{|X[k]|}{X_{ref}}$$

where $X_{ref}$ is a suitable reference. Could be 1V (for dBV) 20$\mu$ Pa (for dBSPL), 1mW (for dBm), etc. Which reference to use depends on your application your setup and what information is available.

This definition can become a problem when $X[k] = 0$. In this case the level is $-\infty$ (not, NaN which is just a programming artifact). Whether this is a problem or not depends on what you want to do with the data.

If you don't want to deal with $-\infty$ you define the maximum dynamic range and add a small offset to your data. For example, if you want to limit your range to, say, 100dB you can do something like

$$L[k] = 20 \cdot \log_{10}\frac{|X[k]|+10^{5}\cdot \max\{|X[k]|\}}{X_{ref}}$$

I'm wondering, is this a common problem

Yes. Not so much with real physical data as this rarely contains values that are exactly zero but if often happens with mathematical models. A simple example is a first order highpass filter which has a gain of 0 at 0Hz (i.e. $X[0] = 0$)

$\endgroup$
3
  • $\begingroup$ I want to implement the whole algorithmn of that paper. Basically it converts the cent scale into 6 different vectors which right now mostly consists of nans. My knowledge in signal processing is limited so I'm not sure if that is what the authors intended. $\endgroup$
    – Rocket
    Jul 4, 2023 at 16:59
  • $\begingroup$ The main question I have is: Is it normal for a fft to output very small values? $\endgroup$
    – Rocket
    Jul 4, 2023 at 17:08
  • 1
    $\begingroup$ @Rocket: It really depends on the nature of your signals,. For some class of signals its normal, for other's it isn't. $\endgroup$
    – Hilmar
    Jul 5, 2023 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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