Every Future has a Founding

Signals and samples

Sampling and the sample rate, gain, delay and addition, the unit impulse and the response to it, the feedback echo, and the sine wave as a test signal.

7 minutes read

1327 words

Contents11

A sound is a pressure that rises and falls in time. A computer cannot hold a curve, only numbers, so it keeps the pressure at regular instants and nothing in between. That list of numbers is a digital signal, and everything an audio program does is arithmetic on the list.

Assumed knowledge

Arithmetic. The sine and cosine of an angle, which the section on sine waves needs and angles and polar form builds up from a right triangle.

Ground covered

What sampling is and what the sample rate means. How one sample is named. Gain, delay and addition, which are the three operations every audio process is built from. The unit impulse, and why the response to it describes a whole class of rules. Delay with feedback, which is the smallest echo. A sine wave as a test signal, and how its angle advances from one sample to the next. Blocks.

A reader who can write down the output of y[n]=x[n]+0.5y[n3]y[n] = x[n] + 0.5\,y[n-3] for an input that is 1 once and 0 ever after can skip the page.

Sampling

A microphone turns pressure into a voltage that varies continuously in time. Call that voltage xc(t)x_c(t) . Sampling reads it at the instants 0, 1/fs, 2/fs, 0,\ 1/f_s,\ 2/f_s,\ \dots and keeps only the readings.

x[n]=xc ⁣(nfs),n=0,1,2,(1) x[n] = x_c\!\left(\frac{n}{f_s}\right), \qquad n = 0, 1, 2, \dots \tag{1}

The number fsf_s is the sample rate, the count of readings per second. Compact discs use 4410044\,100 . Audio software uses 4800048\,000 or a multiple of it. At 4800048\,000 one sample lasts 20.820.8 microseconds, and a second of sound is 4800048\,000 numbers for each channel.

A wave has to be read at least twice per cycle to be told apart from a slower one. The highest frequency a sampled signal can carry is therefore half the sample rate. At fs=48000f_s = 48\,000 that limit is 2400024\,000 hertz, above the top of human hearing.1

Naming samples

The square brackets in x[n]x[n] mark a sequence. Here xx is the whole signal, nn is an integer, and x[n]x[n] is one number of the list. A negative nn refers to time before the recording started, and every such sample is taken to be zero.

Stereo sound is two sequences, xL[n]x_L[n] and xR[n]x_R[n] , one for each ear.

Three operations

Almost everything done to an audio signal is built from three rules. Gain multiplies every sample by the same number.

y[n]=gx[n](2) y[n] = g\,x[n] \tag{2}

At g=0.5g = 0.5 the sound is half as large, and at g=0g = 0 it is gone. Delay shifts the signal later by a whole number of samples.

y[n]=x[nD](3) y[n] = x[n - D] \tag{3}

What was at sample nDn - D is now at sample nn . A delay of DD samples lasts D/fsD / f_s seconds, so 960960 samples at 4800048\,000 is 2020 milliseconds. Addition mixes two signals sample by sample.

y[n]=x[n]+z[n](4) y[n] = x[n] + z[n] \tag{4}

A rule built only from these three, with gg and DD fixed, is linear and time-invariant. Linear means that doubling the input doubles the output, and that the output for a sum of two inputs is the sum of the two outputs. Time-invariant means that delaying the input only delays the output. Multiplying two signals together breaks linearity, and so does letting gg depend on how loud the signal is. Letting gg change over time breaks time invariance. Both are done in practice, and both are handled by treating the rule as linear over short stretches.

The unit impulse

The simplest signal of all is a single 1 at sample zero.

δ[n]={1n=00otherwise(5) \delta[n] = \begin{cases} 1 & n = 0 \\ 0 & \text{otherwise} \end{cases} \tag{5}

Any signal is a sum of scaled, delayed impulses, one per sample.

x[n]=kx[k]δ[nk](6) x[n] = \sum_{k} x[k]\,\delta[n - k] \tag{6}

Equation (6) holds for every signal, because the term at kk contributes x[k]x[k] at sample kk and nothing at any other sample.

The impulse response

Feed a linear, time-invariant rule the impulse and record what comes out. That output, written h[n]h[n] , is the rule’s impulse response.

Now feed the same rule an arbitrary signal xx . By equation (6) that signal is a sum of scaled, delayed impulses. By linearity the output is the same sum of scaled, delayed copies of hh .

y[n]=kx[k]h[nk]=kh[k]x[nk](7) y[n] = \sum_{k} x[k]\,h[n - k] = \sum_{k} h[k]\,x[n - k] \tag{7}

The impulse response therefore describes the rule completely. The sum in equation (7) is called convolution.2 A room is such a rule to a good approximation. Its impulse response is the sound of one clap in it. The sound of an orchestra in that hall is the convolution of the orchestra with that clap. A reverb effect is a device whose impulse response resembles a room’s.

Delay with feedback

Put a delay and a gain in a loop, so that the output is fed back to the input.

y[n]=x[n]+gy[nD](8) y[n] = x[n] + g\,y[n - D] \tag{8}

The impulse comes out at once, then again DD samples later multiplied by gg , then again after 2D2D multiplied by g2g^2 .

h[n]={gkn=kD, k=0,1,2,0otherwise(9) h[n] = \begin{cases} g^{k} & n = kD,\ k = 0, 1, 2, \dots \\ 0 & \text{otherwise} \end{cases} \tag{9}

This is an echo that repeats every DD samples and fades by the factor gg each time. It fades only when g<1|g| < 1 . At g=1g = 1 it repeats for ever, and at g>1|g| > 1 it grows without limit. Decibels and exponential decay says how long the fade takes. A reverb is a handful of these loops, cross-connected so that their echoes overlap into something too dense to hear as repeats.

Sine waves

The other basic test signal is the sine wave.

x[n]=sin ⁣(2πfnfs+θ0)(10) x[n] = \sin\!\left( \frac{2\pi f\, n}{f_s} + \theta_0 \right) \tag{10}

Here ff is the frequency in hertz, which is cycles per second, and θ0\theta_0 is the starting angle, called the phase. Between one sample and the next the angle inside the sine grows by a fixed amount.

Δθ=2πffs(11) \Delta\theta = \frac{2\pi f}{f_s} \tag{11}

A full turn of 2π2\pi is spread over the fs/ff_s / f samples that one cycle occupies. A program that needs a sine wave keeps the current angle and adds Δθ\Delta\theta once per sample. It subtracts 2π2\pi whenever the angle passes it, and takes the sine. The angle is a point going round the unit circle at ff turns per second.

Sine waves matter because a linear, time-invariant rule cannot change the shape of one. Feed it a sine of frequency ff and out comes a sine of the same frequency, at a different size and shifted in time. The ratio of output size to input size, read as a function of ff , is the rule’s magnitude response. One-pole filters, shelves and all-passes shows how to read that ratio off the rule itself.

Blocks

A host program does not hand an effect one sample at a time. It hands over a block of some hundreds or thousands of samples, waits for the block back, and hands over the next. A rule written per sample, like every equation on this page, is unaffected. The effect keeps its memory across the boundary, meaning the delayed samples and the running sums. A block is therefore a loop over samples and nothing more.

Further reading

Sampling, its conditions and its failures.3

Why half the sample rate is the limit.1

The class of rules this page describes, and the sum that describes them.4 2


  1. Nyquist-Shannon sampling theorem. Wikipedia. Retrieved 5 September 2026. https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem (opens in a new tab)  ↩︎ ↩︎

  2. Convolution. Wikipedia. Retrieved 5 September 2026. https://en.wikipedia.org/wiki/Convolution (opens in a new tab)  ↩︎ ↩︎

  3. Sampling (signal processing). Wikipedia. Retrieved 5 September 2026. https://en.wikipedia.org/wiki/Sampling_(signal_processing) (opens in a new tab)  ↩︎

  4. Linear time-invariant system. Wikipedia. Retrieved 5 September 2026. https://en.wikipedia.org/wiki/Linear_time-invariant_system (opens in a new tab)  ↩︎

Tags