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?
Asked
Active
Viewed 226 times
0

AlirezaAsadi
- 793
- 2
- 6
- 21

AncientOne
- 3
- 3
-
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. – AlirezaAsadi Jan 04 '22 at 08:00
-
isn't that np.mean(chunk ** 2) return positive? because we are squaring. – AncientOne Jan 04 '22 at 09: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).` – AlirezaAsadi Jan 04 '22 at 09: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. – AncientOne Jan 04 '22 at 10:38
-
Check for overflows. Deos this help?: https://stackoverflow.com/a/41774113/8961170 – AlirezaAsadi Jan 04 '22 at 10:46
-
1yes. it working now. – AncientOne Jan 06 '22 at 00:23