You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: code math.md
+45-2Lines changed: 45 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,9 @@
1
-
The mathematics of the code are explained here for those of you who are curious or want clarification. Some of this is mentioned in the code itself, but without visual aid.
1
+
### The mathematics of the code are explained here for those of you who are curious or want clarification. Some of this is mentioned in the code itself, but without visual aid.
2
2
3
3
---
4
+
### Loudness and Brightness
4
5
5
-
Having brightness correspond to loudness is an obvious enough feature, however its implementation was a bit of a design choice. Initially, I started with straight proportionality:
6
+
Having brightness correspond to volume is an obvious enough feature, however its implementation was a bit of a design choice. Initially, I started with straight proportionality:
I encourage you to to try all methods to see which one you find to be the most pleasing. One other alternative is to raise the volume ratio to the power of 1.5 to get a slightly more linear output.
22
+
23
+
---
24
+
### "Averaging"
25
+
This program uses what is called "sequenced averages." The difference between them and a regular average is that rather than averaging all available values at once, the averages between a current value and the last computed average are computed in a sequence (this sequence influences the final result).
26
+
27
+
**Examples:**
28
+
29
+
True average of the list of integers from 0–10 inclusive: 
30
+
31
+
Sequenced average in numerical order: 
32
+
33
+
_Interestingly—although useless—if the sequence is in numerical order it follows this formula:_
Rarely will you get an ordered sequence from the sound detector, and that's where the importance of this model becomes evident:
39
+
40
+
In this sequence, there is an trend toward lower inputs (i.e. volume readings, so in the program this would reflect a decreasing noise level). The sequenced average properly reflects this trend, whereas if we did a proper mathematical average it would still read as 5. The difference here is a little too nuanced to be of importance, so I'll demonstrate with some actual data:
41
+
42
+
<table>
43
+
<tr><td><center>All volumes were read out simultaneously during the same song. Some quiet was left at the end to demonstrate the difference between true and sequenced averages.</td></tr>
44
+
<tr><th><center>Volume Readings, Straight from Sound Detector</center></th></tr>
It's pretty evident which method is more responsive to the sound level. The most notable failure of the true average is when the song ends and it's silent. If we relied on the true average to to tell us what was going on in the environment, we'd still think it was plenty noisy, whereas the sequenced average reflects the silence almost immediately—which is the point.
55
+
56
+
The reason the true average fails is because of the culmination of data. It is an average after all, so after a long time reading values even large fluctuations in volume have little impact. This problem would only exaggerate the longer you left the visualizer on, which is obviously not in our best interest since we want to be able to leave the visualizer unattended.
57
+
58
+
Case in point, the sequenced average is the objectively superior method to get an "average" idea of the sound level (unless you like vapid, unresponsive visualization.)
0 commit comments