2
$\begingroup$

To convert power spectrum to a log-scaled one, how to define log10(X(k)) if X(k)=0 for some k?

For sake of illustration, I brief my process as follows which is a convention one:

  1. Calculate the magnitude spectrum X(k) of the time-domain signal x(n) by X(k) = abs(fft(x(n))).

  2. Convert the magnitude spectrum or power spectrum to db by 20*log10(X(k)) or 10*log10(X(k)**2), respectively.

My problem arises when there is X(k)=0 when computing log10(X(k)) which is either not defined or -inf. How to deal with this?

$\endgroup$
6
  • $\begingroup$ What simulation software you use? $\endgroup$
    – Oliver
    Commented Aug 3, 2015 at 7:18
  • $\begingroup$ It is the function spectrum from the library called Essentia that I used to calculate the magnitude spectrum. $\endgroup$
    – Fred
    Commented Aug 3, 2015 at 7:22
  • $\begingroup$ If you want to avoid -inf in your answer, please add a very small value, say 1*e-20, to the zero coefficients. $\endgroup$
    – Oliver
    Commented Aug 3, 2015 at 7:25
  • 1
    $\begingroup$ Thanks, it seems like a doable solution. But does the literature solve the problem this way? Because taking log of X(k) is essential in the field of signal processing, e.g, MFCC. $\endgroup$
    – Fred
    Commented Aug 3, 2015 at 7:29
  • $\begingroup$ The literature does not solve the problem this way. BTW, it is not a problem I guess, you just display the log power spectrum with - infinity. May I know for what reason you want to avoid -infinity? $\endgroup$
    – Oliver
    Commented Aug 3, 2015 at 8:00

1 Answer 1

2
$\begingroup$

Typically, one's data has some sort of noise floor (-96 dB, etc.). So one common way to deal with the FFT bins that are zero (or tiny) is to replace anything below the noise floor with the noise floor level, since any value below that value is most likely not useful data. Doing this before taking the log() function may provide some computational efficiency.

$\endgroup$
3
  • $\begingroup$ Thank you. So simply adding 1e-12 to the bins, i.e., log10(X(k)+1e-12) as suggested by @Oliver, is what you meant? $\endgroup$
    – Fred
    Commented Aug 4, 2015 at 5:02
  • $\begingroup$ Depends. Is 1e-12 around the noise floor of you data? If not, perhaps a much larger value might do. Around -96 dB is closer to 1e-5 ; but it depends on the scaling of your data and FFT as well as the S/N. $\endgroup$
    – hotpaw2
    Commented Aug 4, 2015 at 5:57
  • $\begingroup$ rather than replace, i would simply add a small number like $10^{\frac{-120}{10}}$ to the square magnitude or power spectrum. add it to all bins before the $\log()$. $\endgroup$ Commented Sep 2, 2015 at 20:04

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.