# Encounter 0 when calculating log power spectrum

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?

• What simulation software you use? – Oliver Aug 3 '15 at 7:18
• It is the function spectrum from the library called Essentia that I used to calculate the magnitude spectrum. – Fred Aug 3 '15 at 7:22
• If you want to avoid -inf in your answer, please add a very small value, say 1*e-20, to the zero coefficients. – Oliver Aug 3 '15 at 7:25
• 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. – Fred Aug 3 '15 at 7:29
• 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? – Oliver Aug 3 '15 at 8:00

• 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? – Fred Aug 4 '15 at 5:02
• 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()$. – robert bristow-johnson Sep 2 '15 at 20:04