Displaying and Analyzing the Audio Waveform
Waveform Viewer
Plot the time-domain waveform of an audio signal and compute its amplitude, energy and zero-crossing count, illustrating the effect of sampling.
Educational content in the form of a scientific draft that needs expert review before being adopted as an academic reference. No experimental result that was not actually run is shown here.
Prerequisites
- Python with numpy and optionally matplotlib
- Basic understanding of sampling
Tools
- audio-visualizer
- audio-recorder
- resampling
Implementation Steps
- Generate a sinusoidal signal with a known frequency or load a clip
- Compute the peak amplitude and the RMS value
- Compute the zero-crossing rate
- Resample the signal at a lower rate and compare the shape
- Observe aliasing when the Nyquist frequency is exceeded
- Document what was observed
Code
import numpy as np
sr = 8000
t = np.arange(sr) / sr
x = 0.5 * np.sin(2 * np.pi * 440 * t)
rms = np.sqrt(np.mean(x ** 2))
zcr = np.mean(np.abs(np.diff(np.sign(x))) > 0)
print('peak', x.max(), 'rms', round(rms, 4), 'zcr', round(zcr, 4))
# For a 440 Hz signal: expected number of zero crossings ≈ 2*440 per secondExpected Results
The RMS is expected to approach $A/\sqrt{2}$ for a sinusoidal signal of amplitude $A$, and the zero-crossing rate to approximate $2f/f_s$.
These are educational expectations and not experimental results actually measured.
Project Tests
- Compare the computed RMS with the theoretical value
- Change the frequency and confirm the zero-crossing rate changes proportionally
- Reduce the sampling rate below twice the frequency and verify that aliasing appears
Algorithms
Experiments
Audio processing in the experiments takes place inside your browser. Audio, texts, and conversations are not saved on the server. Privacy Policy
