0

I am trying to get db values from .wav file python using this formula:
dbs = [20 * np.log10(np.sqrt(np.mean(chunk ** 2))) for chunk in chunks]
The issue I am facing is I am getting NaN values in dbs list because of negative values coming from np.mean(chunk**2).
How can I resole this issue?

6
  • The logarithm of a negative number is undefined, and the nan is because of this. you can map negative values of np.mean(chunk ** 2) to 1 so its log10 will be 0. Commented Jan 4, 2022 at 8:00
  • isn't that np.mean(chunk ** 2) return positive? because we are squaring. Commented Jan 4, 2022 at 9:50
  • Oh actually you are right, but I was confused with your statement where you say: The issue I am facing is I am getting NaN values in dbs list because of negative values coming from np.mean(chunk**2). Commented Jan 4, 2022 at 9:54
  • the Issue is I am getting nan values from formula(dbs) because np.mean(chunk**2) returning negative numbers I am trying to find why it's returning negative values and how to resolve it. Commented Jan 4, 2022 at 10:38
  • 1
    yes. it working now. Commented Jan 6, 2022 at 0:23

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.