Digital Audio Waveforms
Digital Sound, Waveforms, and the Discrete Fourier Transform
1. How Sound Becomes Digital Data
Sound begins as pressure variations in the air. When a person speaks:
The vocal folds vibrate.
The mouth and tongue shape the airflow.
These movements create pressure waves with different frequencies.
The waves travel through the air and reach a microphone.
The microphone membrane vibrates in response.
A coil and magnet convert the mechanical vibration into a proportional electrical voltage.
The computer measures that voltage many times per second.
The measured values are stored as digital audio samples in a WAV file.
A recorded sound is therefore represented as a sequence of numbers. Each number approximates the air pressure or microphone voltage at one instant in time.
A digital audio signal is a time-ordered sequence of sampled measurements of a continuously varying physical signal.
2. Reading the WAV File Format
A WAV file stores audio data in a structured binary format. It is organized into named chunks, or sections.
File identification
The first part of the file should contain identifiers corresponding to:
RIFFWAVE
If these identifiers are absent, the file is probably not a valid RIFF/WAV file or is being interpreted incorrectly.
Chunks and lookup tables
After the initial identifiers, the file contains a sequence of chunks. Each chunk includes:
A name identifying the type of data it contains.
A size indicating how many bytes belong to that chunk.
The chunk’s actual contents.
A parser can loop through the file and build a lookup table containing:
The name of each chunk.
Its location in the file.
The parser can then jump directly to a chunk of interest instead of reading the entire file sequentially every time.
Important chunks
Two chunks are especially important for basic audio processing:
Format chunk
The format chunk contains metadata describing how the audio is encoded. Typical values include:
Whether the file is mono or stereo.
The sample rate, measured in samples per second.
The number of bits per sample.
The representation used for each sample.
The number of audio channels.
Data chunk
The data chunk contains the actual audio sample bytes.
The format metadata must be read before interpreting the data. For example, the parser needs to know whether each sample occupies 8, 16, 24, or 32 bits.
3. Converting Audio Bytes into Floating-Point Samples
The raw audio data consists of bytes, but signal-processing code is easier to write using normalized floating-point values.
Reading individual samples
The parser repeatedly:
Reads the number of bytes specified by the format chunk.
Interprets those bytes as one audio sample.
Converts the sample to a numerical value.
Normalizes it into a convenient range.
For signed audio formats, a sample usually represents a value between a negative and positive maximum. Normalization maps that range approximately to:
A value near 1 represents a large positive signal, a value near −1 represents a large negative signal, and a value near 0 represents little or no displacement from the central level.
Normalization
If the largest representable magnitude is M, a raw sample x can be normalized approximately as:
The normalization factor depends on the sample’s bit depth and encoding.
For a signed sample using b bits, the positive maximum is commonly related to:
The exact treatment can depend on the WAV encoding convention.
Handling different bit depths
A parser must handle several possible sample formats:
8-bit samples.
16-bit samples.
24-bit samples.
32-bit samples.
Mono or multiple-channel data.
A 24-bit sample is slightly inconvenient because most programming languages do not provide a native 24-bit integer type. It must therefore be assembled manually from three bytes.
The parser must also correctly handle negative values. This generally requires sign extension or equivalent bit manipulation so that a negative 24-bit value is not mistakenly interpreted as a large positive number.
Signal object
After conversion, the audio can be represented by a signal object containing:
An array of normalized samples.
The sample rate.
This representation is much easier to use for drawing, playback, analysis, and modification.
4. Sampling and Visualizing a Waveform
A waveform plot displays the relationship between a signal’s value and time.
Axes
The horizontal axis represents time.
The vertical axis represents the measured signal value, which is proportional to microphone voltage or air pressure.
Each sample is a single measurement at one point in time.
Sample count and duration
If a signal contains N samples recorded at a sample rate of fs samples per second, its duration is:
For example, a file containing slightly fewer than 40,000 samples recorded at 48,000 samples per second lasts approximately:
A four-second audio clip sampled at 48,000 samples per second contains:
samples.
Points and lines
A waveform can be drawn in two common ways:
Points: Each sample is represented separately.
Connected lines: Consecutive samples are connected to create a continuous-looking path.
A line-based visualization is easier to view at normal scales, but the points reveal that the digital signal is fundamentally discrete.
A digital waveform is not stored as a continuous curve. It is stored as individual samples taken at regularly spaced times.
5. Playing Digital Audio
To play a WAV file, an audio system repeatedly requests a block of samples.
A typical playback process is:
The audio system requests an empty block of a particular size.
The program copies the next samples from the stored signal into the block.
The block is sent to the sound card.
The sound card converts the digital values back into electrical signals.
Speakers or headphones vibrate according to those values.
The vibrations create pressure waves that are heard as sound.
The process continues until all samples have been consumed.
The size of the requested block affects how often the program must provide data. Smaller blocks can reduce latency but may require more frequent processing.
6. Simulating Sound Waves in a Fluid
A fluid simulation can approximate how pressure waves travel through air.
Adapting a water simulation to air
A fluid simulation designed for water may include properties that are inappropriate for air. To make it behave more like air, the simulation can be adjusted by:
Turning off gravity.
Reducing the target or rest density.
Disabling or reducing viscosity.
Water-like viscosity causes excessive resistance and smoothness, whereas air supports rapidly traveling pressure waves.
Visualizing density
Instead of drawing individual particles, the simulation can visualize fluid density.
Density at a location is estimated by counting or summing the influence of nearby particles, usually with a smoothing function:
Fluid density is a smoothed estimate of how much particle mass is present near a given location.
Regions of high density correspond approximately to high pressure, while regions of low density correspond to low pressure.
A computational shader or cell-based function can calculate the density at every location in a texture and assign a color based on that value.
Speaker membrane
A rectangular obstacle in the fluid can represent a simplified speaker membrane. The obstacle is moved back and forth according to the audio waveform:
The current simulation time is determined.
The corresponding audio sample is found.
The sample value is used to offset the membrane’s position.
The membrane compresses and expands nearby fluid.
Pressure waves propagate through the simulated medium.
Because audio samples are discrete, directly using each sample could make the membrane jump. Linear interpolation between neighboring samples produces smoother motion.
If the desired sample position is between samples xi and xi+1, interpolation can be written as:
where 0≤α≤1 represents the fractional position between the two samples.
Simulated microphone
A simulated microphone can measure the density at a chosen location. A pressure-like value can be computed by subtracting the rest density:
where:
ρ is the current local density.
ρ0 is the rest density.
p is a pressure-related signal.
The difference can be multiplied by an arbitrary scaling constant to make the resulting values suitable for recording.
Why the first simulation failed
The first recording attempt produced almost no recognizable sound because the simulation was far too slow relative to the audio signal.
A four-second clip at 48,000 samples per second contains 192,000 samples, but the simulation performed only about 1,200 steps. It therefore captured only a tiny number of pressure measurements.
This mismatch caused severe information loss.
Slowing down the input
The simulation was run in extreme slow motion so that the fluid had enough time to respond to the membrane’s movement.
With a moderate slowdown, the result contained faintly recognizable speech.
With a much greater slowdown, the output became clearer.
The final result still contained crackling but reproduced the spoken words surprisingly well.
The simulation demonstrates that a physical medium must be updated sufficiently quickly, or the relationship between the source signal and the measured response is lost.
7. Saving and Modifying WAV Files
Once WAV files can be read, they can also be modified and written back to disk.
Reversing a signal
Reversing audio is accomplished by reversing the order of the samples:
Playing the reversed samples makes the sound run backward.
Changing speed and pitch
A simple way to alter playback speed is to change the sample rate stored in the output file without changing the samples.
Declaring a lower sample rate makes the file play more slowly.
Declaring a higher sample rate makes it play more quickly.
This also changes pitch because the same waveform is stretched or compressed in time.
If the playback speed is multiplied by a factor r, the frequencies are also multiplied by approximately r:
Thus, slowing a signal lowers its pitch, while speeding it up raises its pitch.
8. Generating Synthetic Signals
Real speech contains many interacting frequencies and is difficult to analyze initially. A simpler approach is to generate a pure sinusoidal signal.
Given:
A frequency f.
A sample rate fs.
A duration T.
The number of samples is:
For each sample, the current time is calculated and used to determine an angle:
The sample value can then be generated with:
or equivalently:
The choice between sine and cosine only changes the phase.
Frequency
Frequency is the number of complete cycles per second. Its unit is the hertz:
A 1 Hz signal completes one oscillation per second. A 150 Hz signal completes 150 oscillations per second.
Radians and 2π
Sine and cosine can be understood using a point moving around a unit circle.
One complete turn covers an angle of 2π radians.
One radian corresponds to traveling a distance equal to the circle’s radius along its circumference.
Multiplying time by 2πf causes the point to complete f turns every second.
The constant commonly written as τ is equivalent to:
Therefore:
also describes the phase angle of a sinusoid.
9. Amplitude, Phase, and Combined Waves
A more general sinusoid includes amplitude and phase:
where:
A is the amplitude.
f is the frequency.
ϕ is the phase.
t is time.
Amplitude
Amplitude controls the strength or size of the wave.
Increasing amplitude makes the waveform taller.
Decreasing amplitude makes it shorter.
In audio, amplitude is related to perceived loudness, although human loudness perception is not perfectly linear.
Phase
Phase shifts the wave horizontally in time.
Changing phase alters where the cycle begins.
It does not change the frequency.
It does not change the amplitude.
Superposition
A complex signal can be created by adding several sinusoidal components:
Each component contributes its own:
Frequency.
Amplitude.
Phase.
The resulting waveform may look complex even though it is composed of simple waves.
This principle is called superposition. It is central to Fourier analysis because Fourier methods attempt to reverse this process: they decompose a complicated signal into its sinusoidal components.
10. Sound Pressure, Compressions, and Rarefactions
A waveform can represent air pressure at a fixed point over time.
A compression is a region where air molecules are more tightly packed than usual.
A rarefaction is a region where air molecules are more spread out than usual.
Peaks in the pressure waveform correspond approximately to compressions.
Troughs correspond approximately to rarefactions.
A pure sinusoidal pressure signal represents regularly repeating compressions and rarefactions.
A 1 Hz signal is far below the normal human hearing range. Audible signals generally contain frequencies from approximately 20 Hz to 20,000 Hz, although the exact limits vary by person and conditions.
11. Visualizing the Discrete Fourier Transform
The discrete Fourier transform, or DFT, analyzes a finite sequence of samples to estimate the frequencies, amplitudes, and phases that compose the signal.
A useful geometric visualization involves rotating the sample values around a circle.
Test points and sample points
For each input sample:
A test point is placed on a unit circle.
The point is rotated through an angle associated with a candidate frequency.
The sample value scales the point’s distance from the origin.
The resulting point is called a sample point.
The average of all sample points is calculated.
For a candidate angular position θn, the sample point can be represented conceptually as:
where xn is the input sample and the complex exponential represents rotation.
The sample points form patterns depending on how well the test frequency matches a component in the signal.
Matching frequency
If the test frequency matches a frequency contained in the signal:
The sample points reinforce one another.
Their average moves away from the origin.
The distance from the origin indicates the strength of that frequency.
The direction from the origin indicates its phase.
If the test frequency does not match:
The sample points tend to spread around the circle.
Their contributions cancel.
Their average remains near zero.
The sample center is computed by averaging the sample points:
The amplitude information is related to the magnitude:
The phase is related to the angle:
Frequency, amplitude, and phase in the visualization
Changing the signal parameters produces predictable geometric effects:
Amplitude: Expands or contracts the circle traced by sample points.
Phase: Rotates or changes the starting orientation of the pattern.
Frequency: Changes how many times the signal cycles while the test point rotates around the circle.
If the test point rotates at the same frequency as the signal, the pattern becomes a coherent offset circle. If the frequencies differ, the points generally cancel around the origin.
12. Why Other Frequencies Cancel Out
Suppose a signal contains several frequencies, but the DFT is testing one particular frequency.
The matching component creates a coherent offset pattern. The nonmatching components create patterns distributed symmetrically around the circle.
Because the nonmatching patterns are approximately balanced:
Their average contribution is therefore near zero. The sample center is primarily determined by the component whose frequency matches the test frequency.
This allows the DFT to isolate individual frequency components even when they are mixed together in the original waveform.
Extracting amplitude
The distance of the sample center from the origin indicates the strength of the matching component. In the visualization, that distance often corresponds to half the actual amplitude, so the amplitude may require multiplication by 2:
This factor accounts for the positive- and negative-frequency components in the complex representation.
Extracting phase
The angle of the sample center gives the phase of the matching wave:
Thus, the DFT provides more than a list of frequencies. It can also recover the amplitude and phase associated with each frequency.
13. Frequency Spectra
Instead of examining one test frequency at a time, the amplitudes can be plotted across many candidate frequencies.
A graph of amplitude against frequency is called a frequency spectrum.
Peaks in the spectrum indicate frequencies that contribute strongly to the signal. For a signal containing components at 3, 5, and 9 Hz, the spectrum should show large peaks near those frequencies.
The spectrum can also reveal:
The dominant frequencies.
The relative strength of each component.
Weak frequency components.
Noise and unwanted background signals.
Non-integer frequencies and spectral leakage
If a signal’s frequency does not align with the available frequency bins, its sample points do not form a perfectly repeating pattern over the observation interval.
Instead, energy spreads into nearby bins. This is called spectral leakage.
For example, a component at 7.5 Hz may produce:
A broad peak around 7.5 Hz.
Smaller peaks at nearby frequencies.
Apparent energy in bins that do not correspond to actual components.
Spectral leakage occurs because the DFT analyzes a finite time window and implicitly treats that window as periodic. If the signal does not complete an integer number of cycles within the window, the beginning and end do not connect smoothly.
Fractional frequencies
Testing only integer frequencies is insufficient for signals containing components such as 7.5 Hz.
One approach is to choose a frequency resolution, such as 0.1 Hz, and test:
A resolution of 0.1 Hz allows frequencies to be examined in increments of one-tenth of a hertz. However, simply testing more candidate frequencies does not eliminate leakage; it only provides a finer grid on which to observe it.
14. Frequency Resolution
Frequency resolution is determined primarily by the duration of the sampled signal.
If the signal is observed for duration T, the natural frequency spacing is:
Equivalently, if there are N samples at sample rate fs:
Since N=fsT, these expressions are equivalent.
Examples
A one-second recording has a natural resolution of 1 Hz.
A two-second recording has a resolution of 0.5 Hz.
A ten-second recording has a resolution of 0.1 Hz.
A 1.5 Hz signal does not align with one-second frequency bins, but it does align with the bins of a two-second recording because:
A 1.4 Hz signal aligns with the bins of a ten-second recording because:
Increasing the sample rate increases the highest frequency that can be represented, but increasing the recording duration improves frequency resolution.
These are different properties:
Sample rate: Controls the maximum detectable frequency.
Recording duration: Controls the spacing between detectable frequencies.
15. Implementing a Basic DFT
A practical DFT implementation can be organized as follows.
Determine the number of frequency bins
The highest frequency that can be represented is half the sample rate, according to the Nyquist limit. The number of samples that fit into the signal duration determines the frequency spacing.
The number of positive-frequency bins is approximately:
where N is the number of samples.
Create the spectrum
An array of frequency-data objects is created. Each object stores information such as:
Frequency.
Amplitude.
Phase.
Calculate the frequency step
The spacing between bins is:
or:
Analyze each bin
For each candidate frequency:
Rotate each sample according to that frequency.
Multiply the rotation by the sample value.
Sum all resulting sample points.
Divide by the number of samples to obtain the sample center.
Compute its magnitude to obtain amplitude information.
Compute its angle to obtain phase information.
Store the results in the spectrum.
A direct DFT has approximately quadratic computational cost:
because every frequency bin examines every input sample. This becomes extremely slow for long audio files.
Special amplitude cases
The usual amplitude correction factor of 2 does not apply in two important cases:
The zero-frequency component.
The component at exactly half the sample rate.
The zero-frequency component, also called the DC component, represents a constant vertical offset rather than an oscillation. All sample points pile up instead of forming a rotating circle, so doubling is not appropriate.
The frequency at half the sample rate is the Nyquist-frequency component. It is also a special case because it does not have a distinct positive-frequency counterpart within the sampled representation.
16. Reconstructing a Signal from Its Spectrum
Once each frequency component has been estimated, the original signal can be reconstructed by adding the sinusoidal components back together:
A simple synthetic signal can be reconstructed accurately from its samples when:
The sample rate is high enough.
The frequencies align with the available bins.
The amplitudes and phases are calculated correctly.
Reconstruction can be visualized by adding the recovered waves one at a time. Low frequencies often produce the largest visible changes in the early stages, while high frequencies may contribute smaller details.
Reconstruction using selected frequencies
The spectrum can be sorted by amplitude, and only the strongest components can be retained.
Typical behavior is:
Top 5 frequencies: Mostly a low hum.
Top 50 frequencies: A more complex sound, but speech remains unclear.
Top 250 frequencies: Some speech structure becomes recognizable.
Top 750 frequencies: Speech becomes clearer.
Top 1,500 frequencies: Most words can be understood.
Top 5,000 frequencies: Speech is very clear.
Top 100,000 frequencies: The result can become nearly indistinguishable from the original.
This demonstrates that speech is not represented equally by every frequency. A relatively small number of strong components can preserve much of its intelligibility, while additional components improve clarity and restore fine details.
17. The Nyquist–Shannon Sampling Theorem
The Nyquist–Shannon sampling theorem describes how frequently a continuous signal must be sampled to preserve its information.
If the highest frequency in a signal is fmax, the sampling rate must be greater than twice that frequency:
The quantity 2fmax is called the Nyquist rate.
Example
For an 80 Hz sinusoid:
A sampling rate near 80 Hz is insufficient because it may produce samples that resemble:
A flat line.
A much lower-frequency wave.
Another incorrect waveform.
This false interpretation is called aliasing.
Aliasing
Aliasing occurs when the sample rate is too low to distinguish rapid changes in the original signal. Samples may skip over entire peaks and valleys, causing a high-frequency signal to masquerade as a lower-frequency signal.
The apparent frequency produced by aliasing is not a real component of the original signal. It is an artifact of inadequate sampling.
Phase and unlucky sampling
Sampling exactly at twice the maximum frequency is theoretically sufficient, but an unfortunate phase relationship can cause all samples to land at similar points, potentially producing a misleading flat-looking sequence.
In practice, the sampling rate is chosen above the theoretical Nyquist rate to provide a safety margin.
Audio sample rates
Humans generally hear frequencies up to approximately 20 kHz. Therefore, a minimum theoretical sample rate would be slightly above:
Common audio sample rates include:
44.1 kHz.
48 kHz.
These rates provide additional room for real-world filtering.
Anti-aliasing filters
Frequencies above the intended maximum should be removed before sampling. An anti-aliasing filter performs this task.
Real filters are not perfectly sharp, so the sampling rate is made higher than the absolute theoretical minimum. The extra margin allows the filter to transition gradually between retained and removed frequencies.
Important implication
The maximum frequency that needs to be tested in a DFT does not need to be hardcoded to the limit of human hearing. It is determined by the sampling rate:
This allows the same analysis method to be used for other data, including signals containing frequencies beyond human hearing.
18. Information Content of Samples
A waveform may appear visually inaccurate when it is drawn using only a few samples, but visual smoothness is not the same as information content.
According to the sampling theorem, if the signal is properly band-limited and sampled above the Nyquist rate, the samples contain enough information to reconstruct the original continuous signal exactly in theory.
Excessive sampling produces more points but not necessarily more underlying information. A higher sample rate is useful when:
The signal contains higher frequencies.
Practical filtering requires additional bandwidth.
Greater engineering tolerance is desired.
It is not necessary merely to make a plotted waveform look smoother.
19. Limitations and Practical Challenges
Several difficulties arise when applying a DFT to real audio.
Non-integer recording durations
If the recording window does not contain a whole number of cycles for a component, the beginning and end of the window do not align. This produces spectral leakage.
Longer recordings improve resolution, but they do not automatically eliminate all leakage.
Non-integer frequencies
A frequency such as 7.5 Hz may not fall directly into the bins of a one-second recording. Testing at finer frequency increments can locate it more accurately, but leakage may still spread its energy into neighboring frequencies.
Peak detection
A spectrum may contain many small bumps caused by:
Spectral leakage.
Noise.
Numerical error.
Imperfect frequency alignment.
A peak-detection procedure can attempt to identify only the primary frequency components. However, removing small peaks too aggressively may remove useful information and make reconstructed audio muffled.
Computational cost
A direct DFT repeatedly performs calculations for every combination of:
Input sample.
Candidate frequency.
For large audio files, this is computationally expensive. It may take minutes or longer to process a recording.
The fast Fourier transform, or FFT, is an optimized algorithm that computes the same type of frequency decomposition much more efficiently. It uses the structure of the DFT to reduce repeated work.
20. Main Relationships to Remember
A microphone converts air-pressure changes into an electrical signal.
An analog-to-digital system samples that signal at regular time intervals.
A WAV file stores metadata and raw sample bytes.
The sample rate determines the highest representable frequency.
The recording duration determines frequency resolution.
Amplitude controls wave strength.
Phase controls horizontal or angular offset.
Frequency controls the number of cycles per second.
Complex signals can be formed by adding sinusoidal components.
The DFT separates a signal into frequency, amplitude, and phase components.
Matching frequencies reinforce during the DFT’s circular averaging process.
Nonmatching frequencies tend to cancel.
Frequencies that do not align with available bins cause spectral leakage.
Sampling below the Nyquist rate causes aliasing.
Reconstructing a signal involves adding the recovered sinusoidal components.
The FFT provides a much faster way to perform Fourier analysis than a direct DFT.

Ask anything
We've read this whole study set, so questions about it get the best answers.