• WANTED: Happy members who like to discuss audio and other topics related to our interest. Desire to learn and share knowledge of science required as is 20 years of participation in forums (not all true). Come here to have fun, be ready to be teased and not take online life too seriously. We now measure and review equipment for free! Click here for details.

Digital filter "game"

bennetng

Major Contributor
Joined
Nov 15, 2017
Messages
1,380
Likes
1,311
Some of you probably have seen a lot of filter plots like these on DAC datasheets:
ak4499.png

pcm1794a.png


How about making these things without using specialized software like Matlab, Octave and such? They are not particularly easy to use. So many people just "see" them rather than try to figure out the meaning themselves.

As you can see, a DAC with "programmable" filters have limitations, for example, the length of filter coefficients.
es9038.png

Now assume there is a DAC chip allows users to make a custom 3-stage, 8x upsampling filter, you can mimic these things with SoX. Not as flexible as specicalized software suites, but fun and easy to begin with. I attached the script file (8xFIR.cmd) so there is no need to screen copy the text below:

sox.png


You can change the -b parameter (steepness/depth), the k parameter (cutoff frequency), but the rule is you cannot change the -n parameter (filter length) as the DAC has limited resources. There are two set of filters, short and long to play with, you can see that the -b, k and -n parameters are duplicated three times, they are different stages of the whole filter, which control different frequency regions of the filters. Put 8xFIR.cmd into the same folder as SoX, and drag impulse.wav (attached) into 8xFIR.cmd, you will get two new wave files. Open the generated files in DeltaWave and they look like this:

dw full.png

Pay attention that the top of the plot is around -66dB instead of 0dB. You can control the three different filter stages, as long as you don't completely screw up the parameters, the three stages should mainly affect region A, B and C respectively.


Now zoom in the graph to see the transition region in A more clearly, these are 44.1k filters so they are somehow "wrong" as the stopband is around 23.5k, but you are the boss, you can change the script yourself. However there is a rule: you can't change parameter -n.
dw transition.png



Zoom more into the 20-20kHz region and you can see the ripples. It is fair to say that the short filter (blue) has a passband ripple of +/- 0.002dB up to 19.3kHz (0.43764fs). For instance, the ESS "brickwall" filter is +/-0.015dB up to 0.435fs, and the "apodizing" filter is 0.075dB up to 0.409fs, according to the ES9038 datasheet. You can also see the ripple of PCM1794A and AK4499 on the screenshots above. Feel free to change the script but without changing the -n value and see how far you can go.

Apart from the attached impulse.wav, you can also drag any 44.1k audio file into the script, they will be upsampled to 352.8k with the same parameters.
dw ripple.png
 

Attachments

  • filter.zip
    518 bytes · Views: 35
OP
B

bennetng

Major Contributor
Joined
Nov 15, 2017
Messages
1,380
Likes
1,311
PS: SoX uses integer internally, as well as real DAC chips. If you send some electronic or loudness war music files to the script, SoX may show clipping warnings. It is also true on real DAC chips if they don't have enough (or any) headroom, and if users don't use digital volume controls.
 

KSTR

Major Contributor
Joined
Sep 6, 2018
Messages
1,587
Likes
3,426
Location
Berlin, Germany
PS: SoX uses integer internally, as well as real DAC chips. If you send some electronic or loudness war music files to the script, SoX may show clipping warnings. It is also true on real DAC chips if they don't have enough (or any) headroom, and if users don't use digital volume controls.
Chip makers have started to address this, for a while. One of the main differences between the AKM AK4490 and AK4493 is that the latter has more headroom for intersample overs, but even the 4490 already has some.

....will show some scope shots of the unfiltered DAC output, as well some IR's and according spectra, for the AK4490...
 

KSTR

Major Contributor
Joined
Sep 6, 2018
Messages
1,587
Likes
3,426
Location
Berlin, Germany
AK4490, direct DAC output (no analog filter), Dirac pulse/spectrum, 192kHz (so only 2x headroom for the digital filter, for this chip family). 1 grid div is 96kHz, 20dB

NOS (no digital filter):
192kHz-NOS.jpg


Slow:
192kHz-Slow.jpg


Sharp:
192kHz-Sharp.jpg

The point here is that any digital filter needs frequency room to work on, which is lacking at this sample rate for this chip. Even with the Sharp filter the first image band starts at 3fs/2 and is only 20dB down so the analog post filter really has some work to do.
The other point is that at fs/2 only a few dB of attenuation is reached... which makes sense for 44.1kHz to have nice specs, but for any higher sample rates a better filter could have been used (if on-chip resources allowed). Therefore you cannot get clean (single frequency) output down to -100dB or so anywhere near fs/2. Some insight here, and more measured curves here.

---------:--------

Intersample overs, at 44.1kHz, from a -1, 1, 1 -1 sequence (should give ~140% for the peak when correctly interpolated by the slow filter, 1 grid div is 50% here):

NOS:
44.1kHz-IS-Over-NOS.jpg


Slow:
44.1kHz-IS-Over-Slow.jpg

The peak only rises to 125% or so, but clips softly. 1 dB of headroom missing.
For the Sharp filter the situation is worse, level should reach ~170% but again clips at 125%, almost 3dB headroom missing.
 
OP
B

bennetng

Major Contributor
Joined
Nov 15, 2017
Messages
1,380
Likes
1,311
OP
B

bennetng

Major Contributor
Joined
Nov 15, 2017
Messages
1,380
Likes
1,311
Here are some analyses using @ayane 's intersample over demo track, using the short and long filters above.

Short filter with 6dB headroom (white) and without, dithered to 21 bits to simulate a real world DAC noise floor, with DeltaWave's default settings (32768, Hann).
short.png


...and long:
long.png


Script:
Code:
@echo off
pushd %~dp0
sox -V %1 -r 352800 -b 24 "%~dp1%~n1 short 0dB.flac" upsample 2 sinc -b 8 -21.4k -n 115 vol 2 upsample 2 sinc -b 8 -39k -n 23 vol 2 upsample 2 sinc -b 8 -78.5k -n 17 vol 2 dither -p 21
sox -V %1 -r 352800 -b 24 "%~dp1%~n1 long 0dB.flac" upsample 2 sinc -b 10 -21.47k -n 135 vol 2 upsample 2 sinc -b 10 -43k -n 27 vol 2 upsample 2 sinc -b 10 -82k -n 19 vol 2  dither -p 21

sox -V %1 -r 352800 -b 24 "%~dp1%~n1 short -6dB.flac" upsample 2 sinc -b 8 -21.4k -n 115 upsample 2 sinc -b 8 -39k -n 23 vol 2 upsample 2 sinc -b 8 -78.5k -n 17 vol 2 dither -p 21
sox -V %1 -r 352800 -b 24 "%~dp1%~n1 long -6dB.flac" upsample 2 sinc -b 10 -21.47k -n 135 upsample 2 sinc -b 10 -43k -n 27 vol 2 upsample 2 sinc -b 10 -82k -n 19 vol 2  dither -p 21
pause

Both the short and long filters only showed about +5dB peak for this track. The reason is that different true peak meters and real world DACs perform differently, and the reported true peak values are more or less guesswork. For example, if one uses a Chord DAC, then it is quite possible that 6dB of headroom is still not enough.
 
OP
B

bennetng

Major Contributor
Joined
Nov 15, 2017
Messages
1,380
Likes
1,311
AK4490, direct DAC output (no analog filter), Dirac pulse/spectrum, 192kHz (so only 2x headroom for the digital filter, for this chip family). 1 grid div is 96kHz, 20dB

NOS (no digital filter):
View attachment 132607

Slow:
View attachment 132608

Sharp:
View attachment 132609
The point here is that any digital filter needs frequency room to work on, which is lacking at this sample rate for this chip. Even with the Sharp filter the first image band starts at 3fs/2 and is only 20dB down so the analog post filter really has some work to do.
The other point is that at fs/2 only a few dB of attenuation is reached... which makes sense for 44.1kHz to have nice specs, but for any higher sample rates a better filter could have been used (if on-chip resources allowed). Therefore you cannot get clean (single frequency) output down to -100dB or so anywhere near fs/2. Some insight here, and more measured curves here.

---------:--------

Intersample overs, at 44.1kHz, from a -1, 1, 1 -1 sequence (should give ~140% for the peak when correctly interpolated by the slow filter, 1 grid div is 50% here):

NOS:
View attachment 132610

Slow:
View attachment 132611
The peak only rises to 125% or so, but clips softly. 1 dB of headroom missing.
For the Sharp filter the situation is worse, level should reach ~170% but again clips at 125%, almost 3dB headroom missing.
I was thinking about whether I should reply this comment or not but the simplest solution is downsample this file on the fly to 96k and the images will be cut into half, also fully Toslink compliant. Yes, I understand it is a technical illustration to demonstrate a point but perhaps a bit too harsh to the AK4490.

The ESS chips on the other hand have other issues too, for example, when playing DSD files, like this:
https://www.audiosciencereview.com/...ds/new-dac-chipset-from-akm.14391/post-454955
 

KSTR

Major Contributor
Joined
Sep 6, 2018
Messages
1,587
Likes
3,426
Location
Berlin, Germany
The reason is that different true peak meters and real world DACs perform differently, and the reported true peak values are more or less guesswork. For example, if one uses a Chord DAC, then it is quite possible that 6dB of headroom is still not enough.
Good catch. A true peak meter would need to use a very close to perfect sinc filter to catch the worst-case peaks with DACs that have good sinc and that is probably computationally prohibitive (both for the filter itself and the latency).
Then again, IS-overs are always only short transients that typically only occur with already quite broken source material and then it doesn't matter much if those peaks are neatly clipped or reproduced faithfully, perceptually. Real problem is when they are not nicely clipped as was the case in some older YAMAHA CDP's which produced nasty code wraparounds which are annoyingly audible, of course.
 
OP
B

bennetng

Major Contributor
Joined
Nov 15, 2017
Messages
1,380
Likes
1,311
Now here is a new "DSD filter game". According to Archimago's measurements his Topping DAC (AK4493) does not have very accurate DSD frequency response and very good ultrasonic noise suppression, and his Oppo UDP-205 (ES9038 Pro) showed 11 to 16dB higher noise floor (below 20kHz!) than PCM when playing DSD files. Some may suspect it is caused by the quality of PCM to DSD file converter when preparing the test signals, but it is not the case, because the rise of < 20kHz noise floor only happens on his Oppo.
https://www.audiosciencereview.com/...ds/new-dac-chipset-from-akm.14391/post-454955

mansr also showed a lot of noise when playing DSD files with his iFi Nano DAC (TI/BB chip?):
https://www.audiosciencereview.com/...es-dsd-sound-better-than-pcm.5700/post-128312

So the conclusion is that purchasing DSD files, or upsampling PCM or low rate DSD files to high rate DSD files and playing them directly on DACs may not be a good idea in many cases. However there are also cases that some published music files have the finest quality in DSD release due the fact the source is really originated from DSD, or due to different production/mastering/conversion procedures. Take a look at this website for an example:

https://dsdmaster.blogspot.com/p/blog-page.html

The website above is not selling DSD files, but software capable of converting DSD to PCM, and it provided some comparisons in DSD64 to 24/176.4k PCM with the said software (DSD Master), as well as Korg Audiogate and Weiss Saracon. I am going to use the Mahler Symphony to illustrate something as it is the most challenging track among the others.

Korg Audiogate: A lot of noise
Mahler 1st - IV - finale - 24-176.4 PCM (Audiogate).png


Weiss Saracon: the vertical lines shooting through the black region indicate the clipped portions.
Mahler 1st - IV - finale - 24-176.4 PCM (Saracon).png


DSD Master: noise level is somewhere between Korg Audiogate and Weiss Saracon, and it is clipped as well
Mahler 1st - IV - finale - 24-176.4 PCM.png


The challenging parts are to avoid clipping, and to carefully trim the ultrasonic noise without affecting the high frequency musical harmonics/transients. The clippings are caused by general assumption that there is 6dB of difference between PCM and DSD levels, so software converters generally add 6dB of volume when converting DSD files to PCM. However it is not always a safe assumption.

Download mansr's special version of SoX with DSD capabilities:
https://www.audiosciencereview.com/...ds/the-sound-quality-of-dsd.14773/post-521831

Rename the downloaded exe file to dsd.exe, and place it in the same location as the original sox.exe so that you can use the script below as a drag and drop file converter. Please refer to the first post of this thread to understand how to use the script and the meaning of the parameters. I also attached a DSD64 and DSD128 impulse files so that you can use it to check the frequency response of the filters.
Code:
@echo off
pushd %~dp0
dsd -V %1 -p rate -vb 74 176400 | sox -V -p "%~dp1%~n1 postFilter 176k SoX.flac" sinc -33k -n 63 gain 5 dither
dsd -V %1 -p rate -vb 74 176400 | sox -V -p "%~dp1%~n1 176k SoX.flac" gain 5 dither
pause
"gain 5" means 5dB of gain will be added to the converted files.

The one with post filter is suitable for DSD64 files, it generates a response like this:
sox postFilter.png

As you can see, frequency response is pretty flat up to 26kHz and stop band is about 44kHz, so it is not going to affect audible frequencies.

Another filter without post filtering looks like this with the DSD64 impulse, it is unacceptably noisy. This filter should only be used with DSD128 or above.
sox176.png

Pay attention the bottom of the screenshot shows -22dBFS reference and 512 FFT size, these settings are used to shift the values so that the top of the spectrum aligns to 0dBFS, and the use of relatively low FFT size is to avoid gathering too many samples, because DSD noise outside of the impulse will further cripple the FFT plot.

...and it is how the Mahler file looks like with post filtering and clipping prevention:
Mahler 1st - IV - finale - 2.8MHz-DSD postFilter 176k SoX.png


In fact, it is rather pointless to convert DSD64 beyond 88.2kHz. Here are the parameters to convert DSD64 files to 24/88.2k flac with similar frequency response. In the case you wish to use 96kHz for whatever reasons, just change 88200 to 96000.
Code:
dsd -V %1 -p rate -vb 74 88200 | sox -V -p "%~dp1%~n1 88k SoX.flac" gain 5 dither

For those want to play DSD files on the fly without converting to flac, please refer to this post:
https://www.audiosciencereview.com/...ds/the-sound-quality-of-dsd.14773/post-520545
The 1023 points filter I made is specifically designed for DSD64 files, and the output sample rate should be set to 88.2kHz or above. The 40kHz_641.txt filter bundled with the foobar plugin is good enough for DSD128 and above, and uses less processing power.

Also, for mathematically lossless DSD compression, Wavpack is a very good choice. It is very simple to use. Just drag a DSD file into wavpack.exe and you will get a compressed .wv file, and the file can be directly played in foobar and other Wavpack capable audio players. To get the original DSD file back, simply drag the .wv file into wvunpack.exe.

The compression speed/ratio is very good:
fileSize.PNG

Another thing worth to point out is that the more you remove the ultrasonic noise, the smaller the flac file is. The DSD noise usually show up as a triangular shape, if the noise attenuation is inadequate.
triangle.png
 

Attachments

  • dsd impulse.zip
    3.6 KB · Views: 18
Last edited:

audio2design

Major Contributor
Joined
Nov 29, 2020
Messages
1,350
Likes
1,258
Good catch. A true peak meter would need to use a very close to perfect sinc filter to catch the worst-case peaks with DACs that have good sinc and that is probably computationally prohibitive (both for the filter itself and the latency).
Then again, IS-overs are always only short transients that typically only occur with already quite broken source material and then it doesn't matter much if those peaks are neatly clipped or reproduced faithfully, perceptually. Real problem is when they are not nicely clipped as was the case in some older YAMAHA CDP's which produced nasty code wraparounds which are annoyingly audible, of course.

I was playing around with this a few years back and simply ran the same signal into two DAC channels, one digitally attenuated by 6db and then amplified in the analog domain by 6db and ran both into an analog comparator. No concerns with fidelity on the attenuated channel so simple math for attenuation. You are not going to catch small IS overs, but overall, worked like a charm.
 

KSTR

Major Contributor
Joined
Sep 6, 2018
Messages
1,587
Likes
3,426
Location
Berlin, Germany
I was playing around with this a few years back and simply ran the same signal into two DAC channels, one digitally attenuated by 6db and then amplified in the analog domain by 6db and ran both into an analog comparator. No concerns with fidelity on the attenuated channel so simple math for attenuation. You are not going to catch small IS overs, but overall, worked like a charm.
Basically you are catching the IS-Overs the DAC cannot handle. Depending on the chip and filter used, a DAC may handle 0...6dB or so of IS-Overs. It's a trade-off, as always. Headroom for IS-Overs eats Signal-to-Noise Ratio which is a front-page spec and thus seldom is sacrificed for better IS-Over behavior.
 

audio2design

Major Contributor
Joined
Nov 29, 2020
Messages
1,350
Likes
1,258
Basically you are catching the IS-Overs the DAC cannot handle. Depending on the chip and filter used, a DAC may handle 0...6dB or so of IS-Overs. It's a trade-off, as always. Headroom for IS-Overs eats Signal-to-Noise Ratio which is a front-page spec and thus seldom is sacrificed for better IS-Over behavior.

Yup, that was one of those 9pm things that finished at about 4 in the morning. Great thing is, it works for every DAC (or recording). A digital domain implementation would only tell me it is probably happening, not that it was happening and how the DAC was responding.
 

Saidera

Senior Member
Joined
Jul 18, 2020
Messages
323
Likes
217
Location
Adelaide, South Australia, Australia
I can understand why this is called filter 'game'.
 
OP
B

bennetng

Major Contributor
Joined
Nov 15, 2017
Messages
1,380
Likes
1,311
AK4490, direct DAC output (no analog filter), Dirac pulse/spectrum, 192kHz (so only 2x headroom for the digital filter, for this chip family). 1 grid div is 96kHz, 20dB

NOS (no digital filter):
View attachment 132607

Slow:
View attachment 132608

Sharp:
View attachment 132609
The point here is that any digital filter needs frequency room to work on, which is lacking at this sample rate for this chip. Even with the Sharp filter the first image band starts at 3fs/2 and is only 20dB down so the analog post filter really has some work to do.
The other point is that at fs/2 only a few dB of attenuation is reached... which makes sense for 44.1kHz to have nice specs, but for any higher sample rates a better filter could have been used (if on-chip resources allowed). Therefore you cannot get clean (single frequency) output down to -100dB or so anywhere near fs/2. Some insight here, and more measured curves here.

---------:--------

Intersample overs, at 44.1kHz, from a -1, 1, 1 -1 sequence (should give ~140% for the peak when correctly interpolated by the slow filter, 1 grid div is 50% here):

NOS:
View attachment 132610

Slow:
View attachment 132611
The peak only rises to 125% or so, but clips softly. 1 dB of headroom missing.
For the Sharp filter the situation is worse, level should reach ~170% but again clips at 125%, almost 3dB headroom missing.
Hi, I found something:
Apart from Amir's plot with 96kHz input, the last plot with 5MHz bandwidth also showed no strong imaging at around 350-400kHz as well, measured by Miska using 705.6kHz input, probably with the older AK4490 RME if you read the date of posting.

From the datasheet, both AK4490 and AK4493 support up to 768kHz, is it a driver/firmware thing about the AK4490 device you tested?
 

KSTR

Major Contributor
Joined
Sep 6, 2018
Messages
1,587
Likes
3,426
Location
Berlin, Germany
Hi, I found something:
Apart from Amir's plot with 96kHz input, the last plot with 5MHz bandwidth also showed no strong imaging at around 350-400kHz as well, measured by Miska using 705.6kHz input, probably with the older AK4490 RME if you read the date of posting.

From the datasheet, both AK4490 and AK4493 support up to 768kHz, is it a driver/firmware thing about the AK4490 device you tested?
Well they "support" it in that you can play back at this rate (352kHz and greater, that is 8x and 16x of the base 44.1Khz or 48kHz rate) ... just with no digital filter at all (except the final one of the SC DAC core on the chip). Actually, when you select NOS below 352kHz, the exact same thing happens, the digital filter and Nx upscaler in the chip is disabled and replaced with Nx ZOH (N depends on the target sample rate and is selected so the same MCLK -- the DS-Modulator and DAC core operating frequency -- is established.
And the chips are slow enough that a single sample at 768kHz does not even settle to full output voltage during that time.

Over at DIYaudio where this was discussed as well the consensus was that the AKM4490/93 catually do only upt 192kHz properly, above that they are in a half-baked NOS mode.
 
OP
B

bennetng

Major Contributor
Joined
Nov 15, 2017
Messages
1,380
Likes
1,311
Well they "support" it in that you can play back at this rate (352kHz and greater, that is 8x and 16x of the base 44.1Khz or 48kHz rate) ... just with no digital filter at all (except the final one of the SC DAC core on the chip). Actually, when you select NOS below 352kHz, the exact same thing happens, the digital filter and Nx upscaler in the chip is disabled and replaced with Nx ZOH (N depends on the target sample rate and is selected so the same MCLK -- the DS-Modulator and DAC core operating frequency -- is established.
And the chips are slow enough that a single sample at 768kHz does not even settle to full output voltage during that time.

Over at DIYaudio where this was discussed as well the consensus was that the AKM4490/93 catually do only upt 192kHz properly, above that they are in a half-baked NOS mode.
Thanks for the info. I bring up this thread again because I left some comments in Archimago's blog and he kindly tested his RME and Topping (both are AK4493) DACs to investigate some DSD issues. He wrote two very detailed reviews within a few days and I found something interesting...

Topping, focus on the DSD256 plot:
topping.png



Unlike the Topping, RME explicitly specifies whether DSD Direct is used or not, with the 50/150kHz filter settings. The higher noise floor with 150kHz filter can be explained as ADC aliasing and DAC/ADC IMD products due to DSD noise, you can also clearly see that with the 50kHz filter and "indirect" DSD, the noise floor below 20kHz clearly improved and shows the superiority of the RME over the Topping. One thing I don't understand is only the RME has a patterned spikes above 65kHz, do you know what they are?
rme.png
 

KSTR

Major Contributor
Joined
Sep 6, 2018
Messages
1,587
Likes
3,426
Location
Berlin, Germany
@bennetng,
Sorry, I cannot comment as except for some quick tests I've never used DSD modes on my RMEs, don't have any native playback material anyway.
And yes, this train of spikes is suspicious and the analog post filter doesn't do much here (situated at 120kHz or so)...
 
Top Bottom