Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: DAC question. (Read 8609 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

DAC question.

I've been thinking about how DAC's work, and this has left me with some questions i haven't been able to figure out the answer of myself. I don't have a scientific background. I thought i'd write it down here so others can benefit from the question and hopefully the answers, to straigthen things out in a way hopefully understandable to a broader audience. Besides just getting an answer.

I understand that a DAC is a device that produces a varying voltage according to the digital input that it is given, and that it is able to change this voltage n times per second, where n is the samplerate of the DAC, i can also understand that the accuracy with which the voltage can be set for each sample is determined by the bit depth as that determines the number of possibilities, and how this effectively determines the signal-to-noise ratio of the signal, because the less accurate the voltage is set, the less accurate the waveform is reconstructed and the resulting difference is noise. So far so good.

It's also easy to understand that the maximum possible frequency that can be reproduced, the so-called nyquist frequency, is exactly half the samplerate, because a wave needs at the very least a crest and a trough sampled to be a wave.

However i get the impression from reading this forum that every frequency up to the nyquist frequency can be reproduced. When i look at spectograms the Y axis is always from 0 to the nyquist frequency and when looking at noise i can see that there is sound all the way up.

What i don't get is how a 44.1KHz DAC would reproduce a sine wave at 22049Hz, or rather, how one could possibly represent such a wave digitally at said samplerate. I imagine that the sampling points would sometimes fall near the crest and trough, but later fall near the neutral points. I imagine this would be reproduced as a 22050Hz wave with a full amplitude modulation at 2Hz, and reversing in phase each time, and that this phenomenon is called aliasing, is this correct?

If so, then how can frequencies near the nyquist frequency be represented and measured in the digital signal? I know that during mastering there will often be a so called "brick wall" filter at roughly 20KHz, but even at 20KHz you only have 2.2 samples to represent each wave with, and i cannot imagine how one could accurately represent frequencies when you have so few samples at non-integer numbers to use.


I assume that there must be a flaw in my reasoning somewhere, but i can't see where, so any help would be appreciated.
Veni Vidi Vorbis.

DAC question.

Reply #1
I understand that a DAC is a device that produces a varying voltage according to the digital input that it is given, and that it is able to change this voltage n times per second, where n is the samplerate of the DAC.

The output voltage of a DAC (after the antialiasing filter) varies smoothly - it does not jump to a new value every 1/N seconds - but varies smoothly interpolating between the samples. This interpolation is called "band limited interpolation" for a good reason - it is created by the fact the signal is band limited to 1/2 the sampling rate. The stepped output you see in some places is either because measurements are taking without adequate filtering or that the filter is not working.
It's also easy to understand that the maximum possible frequency that can be reproduced, the so-called nyquist frequency, is exactly half the samplerate, because a wave needs at the very least a crest and a trough sampled to be a wave.
This assertion that you need a crest and a trough to represent a wave is at the root of your misunderstanding of how sampling works.
However i get the impression from reading this forum that every frequency up to the nyquist frequency can be reproduced.
Yes, every frequency up to the nyquist frequency can be represented perfectly at a given signal to noise ratio - defined by the bit depth of the samples.
What i don't get is how a 44.1KHz DAC would reproduce a sine wave at 22049Hz, or rather, how one could possibly represent such a wave digitally at said samplerate. I imagine that the sampling points would sometimes fall near the crest and trough, but later fall near the neutral points. I imagine this would be reproduced as a 22050Hz wave with a full amplitude modulation at 2Hz, and reversing in phase each time, and that this phenomenon is called aliasing, is this correct?
A 22049Hz sine wave will be reproduced perfectly by an ideal DAC - the picture is a little different in the real world, as perfect filters are hard to come by (that is, they don't exist). But a 22050Hz sine wave with 2Hz amplitude modulation will not be represented accurately by the samples. This is because the band of a 22050Hz sine wave with 2Hz AM stretches from 22048Hz to 22052Hz. The bit above the nyquist frequency will be aliased into the passband, causing distortion. Anti aliasing filters prevent this from happening.
If so, then how can frequencies near the nyquist frequency be represented and measured in the digital signal? I know that during mastering there will often be a so called "brick wall" filter at roughly 20KHz, but even at 20KHz you only have 2.2 samples to represent each wave with, and i cannot imagine how one could accurately represent frequencies when you have so few samples at non-integer numbers to use.
Your mental picture of what a DAC is doing is flawed. Forget, for a moment, about what happens to your 22050Hz signal (exactly at the Nyquist limit) and think about signals up to 22049Hz.

What the DAC is doing, in effect, is finding a waveform which passes through each of the sample values at the specified time of the sample. There are an infinite number of solutions to this problem - but we can narrow the space a bit. The first criterion is that the bandwidth of the "solution" must be less than half the sampling rate. This still leaves us with an infinite number of solutions. Then, we can sneak in a second assumption - the signal is at baseband (that is, includes 0Hz). Mathematical magic happens and there is only one solution (see a text book on the theory for a description of the mathematical magic).

That is - there is one and only one waveform that fits the criteria:
  • Passes through all the points in the sampled data
  • Has a bandwidth of less than or equal to N/2 (where N is the sampling frequency)
  • Includes 0Hz

Quantization blurs this picture a little bit, but doesn't change it's fundamentals. I hope my explaination clears things up for you and doesn't make it worse. If you have some time, reading a good book on the subject might be very rewarding for you.

DAC question.

Reply #2
What i don't get is how a 44.1KHz DAC would reproduce a sine wave at 22049Hz, or rather, how one could possibly represent such a wave digitally at said samplerate. I imagine that the sampling points would sometimes fall near the crest and trough, but later fall near the neutral points. I imagine this would be reproduced as a 22050Hz wave with a full amplitude modulation at 2Hz, and reversing in phase each time, and that this phenomenon is called aliasing, is this correct?

If so, then how can frequencies near the nyquist frequency be represented and measured in the digital signal? I know that during mastering there will often be a so called "brick wall" filter at roughly 20KHz, but even at 20KHz you only have 2.2 samples to represent each wave with, and i cannot imagine how one could accurately represent frequencies when you have so few samples at non-integer numbers to use.


The really simple and naive explination (and one that only applies to ideal DACs) is that the DAC is using functions derived from the sum of many sin waves to connect the points.  Since a 22049Hz tone is a sin wave, it can be generated using interpolation based in part on sin (actually it uses sin(x)/x).

DAC question.

Reply #3
Aliasing is a "feature" of the discrete digital representation of a signal. It doesn't exist in the analog world. Aliasing occurs when a digital signal is "created" and the sampling condition (Nyquist theorem) is not satisfied. For instance, ADC's and digital signal generators are prone to aliasing.

A DAC can't perform any anti-aliasing. If the digital signal is already "contaminated" there is no way to get rid of the aliasing components.

Wikipedia: Aliasing
Maxim/Dallas: ADC and DAC Glossary

DAC question.

Reply #4
Yeah, but usually oversampling+filtering is also involved in digital/analog conversion (There you have to properly apply anti-alias filters, too). At a certain point in the chain there are really "voltage stair steps" produced -- but at a higher sampling frequency (oversampled). This is like the discrete oversampled digital signal convolved with a continuous rectangle function (f(x)=1 for x=0...1, f(x)=0 else). The effect of this "filter" is negligible when oversampling factors are high. If oversampling factors are lower one should compensate for the filter's amplitude response (which is known to be a sinc curve) in the digital domain before producing the "voltage stair steps" or afterwards with an appropriate analogue filter. Now you have a continuous "voltage stair step" signal and can smoothen it via a gentle analogue lowpass filter to remove the remaining alias signals (above the nyquist frequency of the oversampled signal)

It's not like I learned this in a text book or something. So, I might be wrong when it comes do details.
(I consider myself a "softie"  -- focus on digital signal processing, no alanogue stuff)

EDIT: This topic is covered here IIRC -- presentation slides done by James D. Johnston -- AES tutorial given at the University of Miami, other places as well.

DAC question.

Reply #5
Yeah, but usually oversampling+filtering is also involved in digital/analog conversion (There you have to properly apply anti-alias filters, too). At a certain point in the chain there are really "voltage stair steps" produced -- but at a higher sampling frequency (oversampled).

Yes thats true, but the output signal of a DAC is not subject to aliasing because it is a continuous analog signal. The filter that smoothes the DAC output signal is called reconstruction filter. Without this filter the analog signal could contain frequencies above the Nyquist frequency of the digital signal, which are artifacts from the "voltage stair steps".
Wikipedia: DAC
Wikipedia: Anti-aliasing filter
Wikipedia: Reconstruction filter

(I consider myself a "softie"    -- focus on digital signal processing, no alanogue stuff.)

Me too.    But as I already said, in digital signal processing one must be very careful to prevent aliasing from happening in the first place. (the magic word is "bandlimited signal")

DAC question.

Reply #6

Yeah, but usually oversampling+filtering is also involved in digital/analog conversion (There you have to properly apply anti-alias filters, too). At a certain point in the chain there are really "voltage stair steps" produced -- but at a higher sampling frequency (oversampled).

Yes thats true, but the output signal of a DAC is not subject to aliasing because it is a continuous analog signal. The filter that smoothes the DAC output signal is called reconstruction filter. Without this filter the analog signal could contain frequencies above the Nyquist frequency of the digital signal, which are artifacts from the "voltage stair steps".
It's important, I think, to impress of non-technical people (like the OP) that the output of a DAC does not look like a set of stair steps. Sure - this stepped signal does exist when it comes out of the DAC chip, but does not exist at the output of the reconstruction filter (smack is right - I incorrectly called it an antialiasing filter above). This filter is part of the DAC and is an integral part of the process of converting PCM to analog.

DAC question.

Reply #7
... The filter that smoothes the DAC output signal is called reconstruction filter. Without this filter the analog signal could contain frequencies above the Nyquist frequency of the digital signal, which are artifacts from the "voltage stair steps".

Ok, thanks for correcting me. The term "reconstruction filter" would have been more appropriate then.

<nitpicking>
However, the sampling/reconstruction theory suggests that we convolve differently-scaled dirac pulses with our reconstruction filter's impulse response. In case of actual DACs this is achieved by the stair step thingy (dirac pulses convolved with "averaging filter") plus the analogue lowpass we talked about. So, this analogue filter itself is just part of the reconstruction filter.
</nitpicking>

Yeah ... the stair steps may look ugly ... but they are just the intermediate result of the reconstruction filtering process. The sampling/reconstruction theory still applies to actual DACs. 

DAC question.

Reply #8
What i don't get is how a 44.1KHz DAC would reproduce a sine wave at 22049Hz, or rather, how one could possibly represent such a wave digitally at said samplerate. I imagine that the sampling points would sometimes fall near the crest and trough, but later fall near the neutral points. I imagine this would be reproduced as a 22050Hz wave with a full amplitude modulation at 2Hz, and reversing in phase each time, and that this phenomenon is called aliasing, is this correct?


Actually, 'imaging' instead of "aliasing" since it takes place on output.

Look, however, at the spectrum of the signal you have. What is it? It is two lines, one at 44100/2-1 Hz and one at 44100/2+1 Hz.

This is what gives you the "beating" appearance.

Now, when you filter out the energy at 44100/2+1 Hz, you have the original left.

What you are doing is forgetting that you have an output filter that cuts off at 22050, thereby removing the 22051 signal, leaving you with the 22049 sine wave you started with.

You ask a very common, and perceptive question, one that many people are unable to get past. I think, though, that since you already see this as the sum of 2 sine waves, one at 22049 and one at 22051, you're about there. You just forgot that the antiimaging filter will remove the part at 22051.
-----
J. D. (jj) Johnston

DAC question.

Reply #9
Quote
(...) but even at 20KHz you only have 2.2 samples to represent each wave (...)

Whenever it's about frequency/time trade-offs when measuring something (measuring frequency by observing only two adjacent samples) it reminds me of the Uncertainty principle

Cheers!
Sebastian


DAC question.

Reply #11
Thanks everyone for your replies (and sorry for being so late with mine!). It's all very appreciated.

After reading it a few times cabbagerat's last paragraph is starting to make sense to me, and woodinville enlightened me further, i had not realised that the AM signal has a bandwidth itself (but i did know that AM signals do), but it's a "doh" now. Well done!

However that would also mean that for frequencies nearer to the nyquist frequency, the DAC would need more samples in order to be able find the right waveform that passes through all the points, and requires better snr to be able to do so accurately than for lower frequencies, correct? Is this why there is often a brickwall filter at ~2KHz below the nyquist?

To be honest, i'm not interested in reading a whole book on the subject, like i said i'm not an engineer but just an enthousiast who realised something was wrong with the way he imagined digital audio to work. I fear a book would overload me with very complicated things.

I don't have powerpoint installed ATM (reinstall..), but i'll have a look at the presentation linked as soon as i do.
Veni Vidi Vorbis.

DAC question.

Reply #12
However that would also mean that for frequencies nearer to the nyquist frequency, the DAC would need more samples in order to be able find the right waveform that passes through all the points, and requires better snr to be able to do so accurately than for lower frequencies, correct? Is this why there is often a brickwall filter at ~2KHz below the nyquist?
Not really. The reason that filters are set below nyquist is that their dropoff is nowhere near the "brickwall" they claim to be - in order to prevent aliasing the filter needs a bit of room.

The SNR does not change as you approach the Nyquist frequency - the noise added by the quantization process is white (equal energy in all frequencies below Nyquist).

DAC question.

Reply #13
However that would also mean that for frequencies nearer to the nyquist frequency, the DAC would need more samples in order to be able find the right waveform that passes through all the points, and requires better snr to be able to do so accurately than for lower frequencies, correct? Is this why there is often a brickwall filter at ~2KHz below the nyquist?


No.  An ideal DAC can reconstruct any signal up to the nyquist rate with equivilent SNR*.

To be honest, i'm not interested in reading a whole book on the subject, like i said i'm not an engineer but just an enthousiast who realised something was wrong with the way he imagined digital audio to work. I fear a book would overload me with very complicated things.


Unfortunately understanding this really involves working through the proofs yourself, which in turn requires reading up on a fair amount of math and fourier theory, so if thats the case, you'll probably have to just take it on faith that Nyquist was right and ignore the fact that it makes very little intuitive sense to most people.


*Dealing with SNR of DACs is a whole other issue that involves a lot of it's own assumptions.  SNR may not always be equal everywhere, but thats a different issue that depends on implementation, not so much the theory.

DAC question.

Reply #14
What i meant was, the quantitization noise that is introduced makes it harder for the dac to "fit" the waveform to the samples at higher frequencies than at lower ones, the way i imagine it. Guess i was wrong there. I can understand that SNR itself does not change with frequency.

For the rest i'll just take that leap of faith. I'm not a wise-ass, science-loathing audiophile.
Veni Vidi Vorbis.

DAC question.

Reply #15
Illustration.



Here is a digital file. This is a 20 kHz sine sampled at 44100 Hz.



There, we can see the 20 kHz sinewave, with little squares that illustrate the sampling instants. This picture was taken in Cool Edit Pro, opening the above file. Cool Edit just got the sample values, and automatically reconstructed the right sinewave from them.

Getting a waveform closer to the squares would necessarily involve frequencies above 22050 Hz. Below 22050 Hz, all we can get is a sine.

DAC question.

Reply #16
Awesome illustrations pio. The first picture is exactly how i had imagined it in my mind in my initial post, and the second exactly how i imagined it after cabbagerat's enlightening reply.

I can see now why DAC design is so complex and so much more than converting digits into volts and smoothing the output, and why it's such a critical component.

I understand that anything that isn't a sine has multiple frequency components (i imagine it as a collection of sines that lead to the actual waveform when added up). It took me a while to realise this (got there before starting this thread though), but it's helped me understand the replies here, too.
Veni Vidi Vorbis.

 

DAC question.

Reply #17
Quote
can see now why DAC design is so complex and so much more than converting digits into volts and smoothing the output, and why it's such a critical component.
yes. 
i did one question about DAC in another thread and nobody answer(is not important now) because DAC is "crucial" and have direct proportinal with the quality in the output.
i call DAC as "transform stairs to ramps" or "from stairs to ramps"(well...in my language sounds better)

regards all!

cool pictures pio!