Applied Physics · Signal Processing

Digital Signal Processing

Digital signal processing (DSP) is what happens to a sound once it becomes numbers. Your phone measures the microphone's wave tens of thousands of times a second, rounds each measurement and stores it. Then arithmetic does the editing: removing hum, shaping the tone, shrinking the file. Wi-Fi, MRI scanners and voice assistants run on the same ideas.

Big question: how can a list of numbers hold a sound, and once a sound is numbers, how do you clean up a bad recording?

Start with the maths: the Fourier Series & Transform lesson shows why every sound is a sum of sine waves and how the FFT finds them. This lesson takes that idea and asks what engineers do with it.

By the end you can…

  1. Read a spectrum to locate the parts of a sound: notes, hum and hiss.
  2. Explain how the sample rate limits which frequencies a recording can hold, and recognise aliasing.
  3. Explain how bit depth sets the noise level of a recording.
  4. Choose filters to repair a recording and predict what each one will do to the sound.

Quick recap: your test sound

A quick reminder from the Fourier lesson. The waveform (time domain) and the spectrum (frequency domain) are two views of the same sound. The waveform is the smoothie, and the spectrum is its recipe of harmonics. Design a test sound here. You'll digitise it, filter it and measure it in the steps below.

Recipes:
Time domain · waveform2 cycles
Frequency domain · spectrumthe recipe
220 Hz
Painted portrait of French mathematician Jean-Baptiste Joseph Fourier in academic regalia
Jean-Baptiste Joseph Fourier (1768–1830). Fourier discovered that complex waveforms can be decomposed into an infinite sum of simple sine and cosine components. Modern digital audio, spectrograms, and Fast Fourier Transforms (FFT) rely directly on this decomposition to convert between time and frequency domains. Wikimedia Commons · Public domain.

Want to know why a square wave needs only odd harmonics, or how the FFT finds a recipe? Those are covered in the Fourier lesson's epicycle builder and frequency detector.

Going digital, part 1: how often? (sample rate)

An analog-to-digital converter can't store a smooth wave. It measures the wave's height at regular instants, called samples, and keeps only those numbers. The dots are the samples. The orange line is the slowest wave that passes through all of them, which is what the computer "thinks" it recorded.

Try:
One second of signalgrey = real · dots = samples · orange = what the computer sees
Camera view1 frame per sample
Predict firstKeep the sample rate at 20. At what signal frequency will the orange line first stop matching the grey wave?

Just above 10 Hz, which is half the sample rate. That cutoff is the Nyquist frequency. You need more than two samples per cycle to capture a wave. Anything faster gets "folded" back and shows up as a lower, fake frequency, called an alias. Film cameras take about 24 frames per second, which is why wagon wheels and helicopter blades in movies can seem to spin backward.

ExplainOnce a sound has been aliased, why can't software fix it afterward?

Set the signal to 17 Hz, then to 3 Hz. The dots land in exactly the same places, so the stored numbers are identical. Nothing in the file says which wave they came from. That's why recorders filter out everything above the Nyquist frequency before sampling, using an "anti-aliasing filter". It's much easier to prevent aliasing than to undo it.

Why CDs use 44,100 samples per second: human hearing tops out near 20,000 Hz. Twice that is 40,000, plus a little extra room for the anti-aliasing filter, which gives 44.1 kHz.

Claude Elwood Shannon working with early computing apparatus at Bell Telephone Laboratories
Claude Shannon (1916–2001) at Bell Labs. Known as the father of information theory, Shannon mathematically proved the foundational sampling theorem: any bandlimited continuous signal can be perfectly reconstructed without error from discrete samples taken at a rate of at least twice its highest frequency component (\(f_s \ge 2B\)). Tekniska museet / Wikimedia Commons · CC BY 2.0.
Diagram showing high-frequency continuous wave sampled below Nyquist rate producing a lower frequency alias wave
Signal Aliasing and the Nyquist Cutoff. When continuous signals (blue) are sampled too infrequently (\(f_s < 2f\)), the discrete sample points inadvertently trace out an entirely different, false low-frequency wave (red alias). Analog anti-aliasing low-pass filters prevent this irreversible distortion before digital conversion. Wikimedia Commons · CC0 / Public domain.

Worked Example: Nyquist Sampling Rate & Foldover Aliasing

The Nyquist-Shannon Sampling Theorem guarantees that a continuous analog signal can be perfectly converted to digital and rebuilt without error, provided the sampling rate \(f_s\) exceeds twice the highest frequency \(f_{\text{max}}\) in the signal: \(f_s > 2 f_{\text{max}}\). If higher frequencies enter the converter, they reflect back across the Nyquist frequency (\(f_N = f_s / 2\)) as audible, distorted alias frequencies.

Sample Problem: An audio recording system operates at the standard CD rate of \(f_s = 44,100\text{ Hz}\) (\(44.1\text{ kHz}\)). An electric guitar pickup produces an intentional musical harmonic at \(f_{\text{music}} = 12\text{ kHz}\), but simultaneously picks up electromagnetic interference from a nearby switching power supply at \(f_{\text{noise}} = 27\text{ kHz}\).

  1. Calculate the Nyquist frequency \(f_N\) for this system.
  2. Determine whether the \(12\text{ kHz}\) guitar harmonic is sampled correctly.
  3. Calculate the foldover alias frequency \(f_{\text{alias}}\) that will appear in the recorded digital file if no anti-aliasing filter is used.
  4. Explain why digital equalization (EQ) applied inside the computer after recording cannot remove the noise without damaging the music.

Step 1: Calculate the Nyquist limit.

The Nyquist frequency is half the sampling frequency:
\(f_N = \frac{f_s}{2} = \frac{44,100\text{ Hz}}{2} = 22,050\text{ Hz} = 22.05\text{ kHz}\).

Step 2: Check the music harmonic.

Because \(f_{\text{music}} = 12\text{ kHz} < 22.05\text{ kHz}\), it is strictly below the Nyquist limit. The ADC collects \(\frac{44.1}{12} \approx 3.675\) samples per cycle, capturing the wave cleanly.

Step 3: Calculate the alias frequency for the noise.

Because \(f_{\text{noise}} = 27\text{ kHz} > 22.05\text{ kHz}\), it exceeds the Nyquist limit. When sampled, it reflects across \(f_s\):
\(f_{\text{alias}} = |f_{\text{noise}} - f_s| = |27,000\text{ Hz} - 44,100\text{ Hz}| = 17,100\text{ Hz} = 17.1\text{ kHz}\).
Although the original 27 kHz noise was ultrasonic and inaudible to human ears, the digital converter folds it down to 17.1 kHz—an audible, harsh high-frequency squeal!

Step 4: Why anti-aliasing must be analog before sampling.

Once sampled, the stored numbers for a 17.1 kHz alias and a genuine 17.1 kHz sound are 100% identical; no software algorithm can distinguish them. Therefore, audio hardware must place an analog low-pass filter before the ADC to eliminate all frequencies above 22.05 kHz prior to digital conversion.

CheckWhat sampling frequency would be required to record the 27 kHz noise as a true signal without aliasing?

The sampling frequency must exceed twice the signal frequency: \(f_s > 2 \times 27\text{ kHz} = 54\text{ kHz}\). Studio professional recording formats commonly use \(f_s = 96\text{ kHz}\) or \(192\text{ kHz}\) specifically to provide plenty of headroom above audible bandwidth.

Going digital, part 2: how precisely? (bit depth)

Each sample is stored as a whole number made of a fixed number of bits. With b bits there are 2b possible levels, so every measurement is rounded to the nearest level. This rounding is called quantization. The rounding errors (orange, bottom strip) add a rough, jittery wobble to the signal. You hear it as hiss, called quantization noise.

Try:
Test sound, 24 samples per cyclegrey = real · cyan = stored numbers · orange = rounding error (×4)
16 bits
Levels65,536
Smallest step0.003% of range
Signal-to-noise≈ 98 dB
1 min of stereo at 44.1 kHz10.6 MB
Predict firstPlay the test sound and slide from 16 bits down to 3. Will the pitch change?

No. Pitch depends on when the samples happen, and the sample rate hasn't changed. Rounding only changes how precisely each sample is stored. Fewer bits mean bigger rounding errors, and you hear them as hiss and a crunchy, buzzy edge. The signal-to-noise readout shows how far that noise sits below the music, in dB: each bit you add pushes the noise about 6 dB quieter.

CompareSample rate and bit depth are both "quality" settings. Which one fixes which problem?

The sample rate sets the highest frequency you can record, so too low a rate causes aliasing and lost treble. The bit depth sets the noise floor, so too few bits cause hiss and crunch. They're independent. An 8-bit game console could play high notes perfectly well, but it always sounded gritty.

Why 16 bits for CDs? 65,536 levels put the noise about 96 dB below the loudest sound, roughly the gap between a silent room and a rock concert. Studios record at 24 bits so there's room to spare while they edit.

Filters, part 1: the equalizer

Once a sound is numbers, a digital filter can turn individual frequencies up or down. It does this with nothing more than multiplying and adding samples. An equalizer (EQ) is a row of such filters, one per band, each set in decibels. The curve shows the total effect: above the line is louder, below is quieter. The small coloured ticks mark your test sound's harmonics.

Presets:
EQ frequency response±12 dB · log frequency
Predict firstSet the test sound to 220 Hz and choose "Old telephone". Which harmonics get quieter, and why does the sound get thinner?

The telephone curve cuts everything below about 300 Hz. Your 220 Hz fundamental lands in that dip, so it drops a lot, while the harmonics near 1 kHz get boosted. You still hear the same pitch, because your brain works out the missing fundamental from the spacing of the harmonics. But the sound loses its body. Real phone lines pass only about 300–3,400 Hz, which is why voices sound "tinny".

Filters, part 2: rescue a ruined recording

Someone recorded a melody next to a buzzing power adapter in a room with a noisy fan. The spectrum shows three things mixed together: the melody's harmonics (cyan), electrical hum at 60 Hz and its multiples (red), and hiss spread across the high frequencies (orange). An EQ can't remove these cleanly, so this step uses three new filter types.

High-pass

Lets frequencies above the cutoff pass. Cuts everything below it.

Low-pass

Lets frequencies below the cutoff pass. Cuts everything above it.

Notch

Deletes one narrow frequency and leaves the rest almost untouched.

Spectrum of the recordingfaint = before · bright = after · yellow = your filters
off
off
Hum removed0 dBgoal ≥ 15 dB
Hiss removed0 dBgoal ≥ 9 dB
Melody lost0 dBgoal ≤ 1.5 dB

Laptop speakers can barely play 60 Hz, so the hum is easier to hear on headphones. You'll still hear its 120 Hz and 180 Hz buzz either way.

Hint 1I turned on the notch filter, but the hum score barely moved. Why?

Look at the red spikes. Hum isn't a single frequency: it's 60 Hz plus harmonics at 120 and 180 Hz. The notch removes only the first one. Which filter type can remove everything below a chosen frequency?

Hint 2Where exactly should the cutoffs go?

Put each cutoff in a gap between what you want to keep and what you want to remove. The lowest melody spike is at 392 Hz and the highest hum spike is at 180 Hz, so the high-pass belongs between them. The melody stops near 2 kHz and the hiss starts above it. Filters don't cut like a cliff, they slope, so leave some space either side.

ThinkWhy can't filtering ever remove the hiss completely?

Real hiss is spread across all frequencies, including the ones the melody uses. A filter can't separate two things that share a frequency. Removing that last bit takes smarter DSP, such as the noise reduction in phone calls, which estimates the noise and subtracts it.

Live lab: the whole chain on real sound

This is a real FFT, running about 60 times a second. It uses your Step 3 bit depth and your Step 4 EQ settings, applied to either the test sound or your microphone. While Step 5 is playing, it shows that recording instead. The microphone isn't played back through the speakers, so it won't cause feedback.

Not listening. The preview below is drawn from your test-sound recipe.
Time domain (waveform)≈ 25 ms · auto-zoom
Frequency domain (spectrum)log scale

Try this

  • Test sound at 3 bits. Watch new spikes and a raised floor appear across the spectrum. That's quantization noise.
  • Step 5, "Hear original" then "Hear filtered". The red hum spikes and the orange hiss should drop while the melody's spikes stay put.
  • Microphone, then the "Old telephone" EQ. Talk and watch the low and high ends disappear. Your voice should sound like a phone call.
  • Microphone at 4 bits. Speak quietly, then loudly. Quiet sounds suffer most, because they use only a few of the levels.

Check for understanding

Six quick questions

Pick an answer to see why it's right or wrong.

The converter in your pocket

Every phone has an analog-to-digital converter (ADC) behind the microphone. It measures a voltage 48,000 times a second and turns each measurement into a 16- or 24-bit number. A digital-to-analog converter (DAC) does the reverse for your headphones.

Nyquist (1928) and Shannon (1949)

Harry Nyquist and Claude Shannon showed that sampling at more than twice a signal's highest frequency loses nothing: the original wave can be rebuilt exactly. Every digital audio, video and radio system is designed around that limit.

A filter is a little recipe

Each filter in this lesson is a "biquad". It works out every new output sample from the last two inputs and the last two outputs, each multiplied by a fixed number. Changing those five numbers turns the same code into a high-pass, low-pass, notch or EQ band.

Where DSP hides in your day

MP3 and streaming audio discard sounds you can't hear. Noise-cancelling headphones produce an "anti-wave". Phones filter out background noise on calls, Wi-Fi untangles radio echoes, and MRI scanners build pictures from frequencies.

Exit ticket

Explain it in your own words

  1. Two settings decide how faithful a digital recording is: the sample rate and the bit depth. For each one, explain what goes wrong if it is set too low.
  2. A podcast voice sits between 100 and 5,000 Hz. The recording has hum at 60 Hz (plus 120 and 180 Hz) and fan hiss above 7,000 Hz. Design a filter chain: which filters, where would you put each cutoff, and what might you lose?
  3. Music on retro 8-bit game consoles sounds crunchy. Would raising the sample rate fix that, or adding more bits? Explain why.