Skip to content

Commit

Permalink
add comments back
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Jul 24, 2024
1 parent abff21c commit d47e4e1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions system/micd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
SAMPLE_BUFFER = 4096 # (approx 100ms)

def precompute_a_weighting():
# Calculate the A-weighting filter
# https://en.wikipedia.org/wiki/A-weighting
freqs = np.fft.fftfreq(FFT_SAMPLES, d=1 / SAMPLE_RATE)
A = 12194 ** 2 * freqs ** 4 / ((freqs ** 2 + 20.6 ** 2) * (freqs ** 2 + 12194 ** 2) * np.sqrt((freqs ** 2 + 107.7 ** 2) * (freqs ** 2 + 737.9 ** 2)))
return A / np.max(A)
Expand All @@ -33,6 +35,8 @@ def calculate_spl(measurements):
def apply_a_weighting(measurements: np.ndarray) -> np.ndarray:
# Generate a Hanning window of the same length as the audio measurements
measurements_windowed = measurements * np.hanning(len(measurements))

# Apply the A-weighting filter to the signal
weighted = np.abs(np.fft.ifft(np.fft.fft(measurements_windowed) * A_WEIGHTING))
return weighted

Expand Down

0 comments on commit d47e4e1

Please sign in to comment.