I'm keen for someone to provide a clear and concise overview of how digital audio works. How you get from an analogue waveform, through a sampling stage, a digital to analogue converter - all the way through a programme chain back to an analogue signal again.
NOTE: Still more work to do on this in relation to reconstruction filters, but I thought it was time to post as much as I can. Improvements can be worked on later.
At the input stage is a full-range, full spectrum signal.
It should be said at the outset, that PCM digital audio does not reproduce the entire signal bandwidth. The amount of bandwidth that can be encoded is equivalent to just under half the sampling frequency (fs). Any signal that arrives at the input stage that contains frequencies that are greater than half the sampling frequency will be encoded as ‘alias’ frequencies that ‘fold’ around the “Nyquist” frequency (fs/2). This results in clearly audible artefacts in the recording, so a filter stage must be included that significantly attenuates any frequencies that are above the Nyquist frequency (fs/2). This filter is called an “Anti-Aliasing Filter” and is shown in the diagram as the [AAF] block.
The output of the [AAF] block (anti-aliasing filter) is going to be the basis upon which any audio can be decoded and the output of the processor will never be any better than what can be seen at the output of the anti-aliasing filter.
It is generally accepted practice that, in a sampling based system such as this, that the sampling frequency chosen will always be at least twice the value of the highest frequency that you need to reproduce. For instance, a system that samples audio at 48,000 samples per second can accurately reproduce frequencies below 24,000 Hz. A sampling frequency of 44,100 samples per second can accurately reproduce frequencies below 22,050 Hz. The limit of human hearing is between 16-18 kHz.
(It should be noted at this point that improvements in converter design and implementation usually employ "oversampling" so that the nyquist frequency is well north of any audible signal preventing any potential aliasing artifacts and also permitting much more subtle aliasing filters to be employed.)
Signal Sample and Hold [SaH]
The ‘sample and hold’ stage is driven by a clock pulse which will present itself to the sampling stage as a square wave with equal periods driven at the desired 'sampling frequency' (fs). Each time that the clock pulse goes from a low value to a high value, the circuit ‘samples’ the analogue signal contained at the input, and retains that signal value for the duration of the sampling clock period. When the next clock pulse comes along (low to high) a new ‘sample’ is taken.
The accuracy of the sampling clock is critical to the accuracy of the sampling process and eventual reproduction. Errors in the sampling clock result in “jitter error” or “clock jitter” which is an error signal that is embedded in the digital audio stream during the sampling process. The more accurate the clock signal, the less clock jitter appears in the digital audio signal.
All this occurs in - and remains in - the analogue domain. The resulting ‘sampled’ waveform appears deformed in a manner similar to the diagram above.
It will be of interest that the output of the “Digital to Analogue Converter” stage (output chain) is almost identical to the output of the “Sample and Hold” block in the input chain.
The process of deforming a full-range analogue waveform through the process of ‘sampling’ introduces artifacts into the signal. The behaviour of these artifacts is well understood and the design of digital audio systems takes these artifacts into account as a core part of the theory, design and construction of sampling circuits.
The easiest way to understand aliasing in the context of digital audio is to imagine the frequency ‘spectrum’ of the input audio signal laid out on an infinitely long strip of paper where the left hand side of the strip represents 0Hz (DC) and the frequency value increases as you extend the strip to the right.
The strip is transparent and you can see through all the folds of the strip right to the bottom.
Any frequency components that have values that extend past the first fold at fs/2 can be seen ‘mirrored’ onto the first ‘page’(baseband) of the spectrum between 0fs and fs/2. Any aliasing components falling between 0fs and ~18kHz are audible. \ \ The first trick with digital audio sampling is to filter the incoming audio to attenuate any audio presented at the input with a frequency above fs/2. This eliminates the unwanted aliasing components that are ‘printed through’ during sampling. This is achieved with an “anti-aliasing” filter which is explained further in the next section.
Additionally, the result of sampling also ‘prints’ the ‘wanted’ audio (contained between 0fs and fs/2) across the entire spectral range. It’s much the same as taking a folded strip, cutting out a shape and then unfolding the strip again to make a Christmas decoration.
Once again, those aliasing components can be removed using a filter, which is the core of how digital reconstruction is achieved.
In this example, a signal exists with a frequency component in the region of 19khz and 23kHz. When we sample this signal at an fs of 24kHz, we ‘fold’ these frequencies around fs/2 to create mirror-image aliasing components between 1kHz and 5kHz.
These aliasing components are now easily audible were the signal to be reconstructed.
We therefore apply a low-pass anti-aliasing filter at 12kHz to attenuate frequencies higher than 12kHz to prevent this aliasing from being audible in the baseband.
Were the same unfiltered signal to be sampled at 12kHz, the result would be somewhat worse! Everything would get aliased around fs/2 which in this case is 6kHz, so you end up with multiple aliasing components in the baseband range.
Anti-Aliasing filters [AAF]
An _Anti-Aliasing filter _is essentially a brick-wall filter that passes the entire band below fs/2, but attenuates everything above fs/2. In practise it is very difficult to implement a perfectly sharp brick-wall filter that has the linearity required for practical operation, therefore compromises must be made.
The ideal anti-aliasing filter needs to be a ‘brickwall filter’ which exhibits constant phase delay in the pass-band with a constant flat frequency response with zero response above the Nyquist frequency (fs/2). This can be achieved by a filter with a ‘normalised sinc’ impulse response.
Analogue to Digital Converter [ADC]
The sampled waveform output of the Sample and Hold block is presented to an “Analogue to Digital Converter” (ADC) stage, which is where the analogue voltage value for each ‘sample’ is converted to a digital value. The ADC stage is also driven by the sampling clock which tells the ADC that the sample available at the input is stable and ready for reading. Each time the sampling clock triggers the converter, a new digital sample value is read and presented at the block outputs.
The output of an ADC is generally presented as a serial data stream on an i2c or i2s interface which is a common interface for transmitting digital audio and dealing with the associated control signals.
ADC devices can be built to a specific ‘bit resolution’ which defines how ‘accurate’ the sample conversion operation will be. The more ‘bits’ in the conversion process, the more accurate the conversion will be.
Most ADC devices top out at 24-bits however use of 32-bit sampling techniques is now becoming more common.
Each operation of the ADC will “quantize” the incoming sample value to one of the available possible sampling values. Due to this quantization process, the stored value will never exactly represent the same value as the input voltage value.
The difference between these two values is known as ‘quantization error’. At low bit resolutions or signal levels this ‘error signal’ is audible as a grainy ‘quantization noise’. The higher the bit resolution of the converter, the lower the level of quantization noise that appears in the encoded signal.
Quantization Error is always introduced into a digital audio signal during the sample quantization process by the ADC. Quantization error can never be removed, only masked or minimised during signal reconstruction.
In this diagram, we see the difference between a 16-bit encoding and a 4-bit encoding for a sine wave. This approximates to the quantization noise that would occur when using a 4-bit ADC for audio sampling.
Digital to Analogue Converter [DAC]
A Digital to Analogue Converter is the first stage in the signal reconstruction process and works in exactly the opposite way to an Analogue to Digital Converter, in that it takes a digital audio data stream, representing audio samples and converts it to an aliased waveform similar to that which is seen at the output of a Sample and Hold block.
Each conversion action occurs on a clock trigger. When the DAC receives a clock trigger, the sample value present at the input is presented as a discrete voltage at the output pin. The receipt of regular clock trigger and sample values generate a changing (but stepped) waveform which contains aliasing components.
Reconstruction Filter [RF]
The stepped waveform (consistent with a sample-and-hold waveform deformation) present on the output pin of a DAC device is presented to a reconstruction filter in order to remove aliasing components and to reconstruct the original input waveform (after anti-aliasing).
A basic “Reconstruction Filter” is a sharp low-pass filter at fs/2, however it is worth looking in a little more detail as to how and why this works.
Ideal Reconstruction Impulse
The impulse response of an ideal reconstruction filter is the Dirac Impulse, which is a theoretical impulse defined by the following:
Basically, this means that the pulse is zero everywhere except at the origin, where it is infinite. So an ideal DAC assumes that each sample output of a DAC is a Dirac impulse of varying amplitude.
However, this is not achievable in reality and consequently an approximation must be used.
The ideal reconstruction filter needs to be a ‘brickwall filter’ which exhibits constant phase delay in the pass-band with a constant flat frequency response with zero response above the Nyquist frequency (fs/2). This can be achieved by a filter with a ‘normalised sinc’ impulse response.
A ‘normalised sinc’ function is defined for
Wave superposition is the principle that two independent waves travelling over the same medium will pass through each other without either disturbing the other in any way. This applies to the sinc impulse responses generated by a DAC and forms the basis for which an analogue wave is reconstructed.
Each of the “sinc” impulses will pass through the same electrical medium however as they do so, they will coincide to form a new wave (whilst still obeying the law of wave superposition) and will re-generate the original intended analogue waveform.