A slightly embarrasing audio line level question

Building your first 6502-based project? We'll help you get started here.
barnacle
Posts: 1831
Joined: 19 Jan 2004
Location: Potsdam, DE
Contact:

Re: A slightly embarrasing audio line level question

Post by barnacle »

The Nyquist limit is trickier than it looks.

The theory is that you can represent any signal by sampling *at least* twice as fast as the highest component in signal; so if you have a *pure* sine wave you can theoretically sample it a twice its frequency and recreate it with suitable filter afterwards. The problem is, you'll actually get a DC signal since you'll be sampling the same point(s) on the waveform every second sample... amuse yourself with a picture to see why. Not what you're looking for.

So, you need to apply something at rather more than 2* the sample rate. For nominally 20kHz audio, 44.1kHz is a standard sampling frequency[1].

However: you also need to be absolutely certain that there are no frequency components above [EDIT: HALF] the sampling frequency; you need a 'brick wall' filter with a filter function in the 10s of dB per octave. Otherwise, you will get what is referred to as 'aliasing'. If you sample (to keep the maths easy) at 10kHz, and your input frequency is a sine at 4kHz, you'll get out what you expected (depending on the quality of your reconstruction filter). If you feed it 5KHz, as above, you'll get DC. If you feed it 6kHz, you'll get... 4kHz output. The frequency is reflected around the Nyquist frequency and it goes all the way back down to 0Hz by the time you get to the sampling frequency. If you go above the sampling frequency, you'll get the signal starting to rise again. It's not intuitive though it's obvious once you start to think about it.

Hence the need for the brick wall filter. Once the alias signal is into the sampled signal there is *no way* to remove it; you must stop it getting in.

There are some clever tricks which can be done to relax the filter requirements; the simplest is to sample a lot more frequently than twice Nyquist; you'll find other tricks if you search for audio sampling on the web. But the take home here is: if you want a 16k bandwidth, you need (in general) a sample of at least rather more than 32k; you'd probably consider 40kHz, and you will need to pay attention to the anti-aliasing filter at the front end. Switched capacitor filters are convenient to make multi-pole filters and can be automatically adjusted to your sampling frequency by driving them from the same clock (multiple).

Neil

Edit: I used sampling frequency as a limit above when I meant half the sampling frequency.

[1] It's historical. The president of Sony wanted to be able to get all of a Beethoven symphony on a CD. Given the error correction and data rate that gave a certain amount of data for the music; the rest is just dividing by 79 minutes. Conveniently, the same data rate provided a very similar mechanism for storing digital audio as a digital PAL frequency signal on uMatic video cassettes...
Last edited by barnacle on Sun Apr 30, 2023 10:16 am, edited 1 time in total.
User avatar
AndrewP
Posts: 368
Joined: 30 Aug 2021
Location: South Africa

Re: A slightly embarrasing audio line level question

Post by AndrewP »

barnacle wrote:
The Nyquist limit is trickier than it looks.
Thanks! That's the clearest description of the Nyquist limit I've read.
GARTHWILSON wrote:
And speaking of the sampling frequency: The maximum audio frequency you can get with a 16kHz sampling is below 8kHz (the Nyquist frequency), which is a lot better than many people think, but if you don't have some sort of output anti-alias filtering, the images above 8kHz resulting from aliasing could have some strange effects. For example, frequency content at 5kHz would also show up at 11kHz, frequency content at 6kHz would also show up at 10kHz, etc.. It's hardly a concern at the lower frequencies though, for a couple of reasons. The wikipedia article has an audio demo at https://en.wikipedia.org/wiki/Aliasing#Audio_example .
Almost certainly helped by the wikipedia links / pictures Garth posted previously but it's the first time I've gone, 'well that makes sense'.
barnacle
Posts: 1831
Joined: 19 Jan 2004
Location: Potsdam, DE
Contact:

Re: A slightly embarrasing audio line level question

Post by barnacle »

A minor clarification with Garth's description: you *must* have the anti-aliasing filter on the *input*. Once it's on the sampled signal, it's in the frequency band you're trying to replay and there is absolutely no way of getting rid of it.

However, you still need an output filter, again, brick wall at half the sampling frequency. As with all filters you need to decide which is more important to you: phase response, frequency response, ripple... in the analogue domain there is no such thing as a perfect filter.

Neil
Post Reply