# Remove noise introduced while converting a Delta-Sigma Modulated (DSM) signal into a pulse-code modulated (PCM) signal?

I'm writing a tool that converts a dsdiff audio file (dsd64) into a flac audio file (DSM -> PCM). The project is both a programming exercise and a signal processing exercise; I'm learning a lot from it.

Currently, I'm doing the following to compute a sample in the PCM stream

1. Select a window of the DSM sequence that corresponds to the size of the window of a low-pass (FIR) filter.
2. Replace all 0s in the DSM window with -1s
3. Convolve (multiply+sum) the elements in the DSM window with the coefficients of the (FIR) filter and rescale the result to fir into the chosen bitrate (24-bit).
4. Move the window by downsampling factor many elements (16 in my case) and apply repeat this process.

I tested the conversion using a few (arbitrarily chosen) dsdiff files (songs by the band deep purple). The conversion reproduces the signal (good) but introduces noise (bad) with the following profile (measured during the beginning of the track where there is a bit of silence in the original): I've been trying to figure out how this is being introduced, and what I need to do to remove it. From my reading of random sources online I understand that this is introduced by integrating the DSM signal, which amplifies the noise floor and maps it to a spectrum similar to the one I see in my plot.

Did I identify the problem correctly? What can I do to verify this and, ultimately, fix it?

Any help is highly appreciated.

Edit:

Added a figure showing the filter's frequency response Added the Periodogram of the first second of the DSM stream • Interesting how the color matches the band! Aren't we just seeing the expected effects of noise shaping? Given you have a 20 dB/decade noise slope, it appears you are using a simple first order Delta-Sigma. If you increase the order of the Delta-Sigma, that slope will increase allowing you to push the noise further out of the desired audio passband, and you filter out the high frequency noise with a low pass filter. Nov 24, 2020 at 3:39
• @DanBoschen It could indeed be noise shaping; why it doesn't happen at an even higher frequency and persists after filtering confuses me though. The original DSM signal (from a DSD64) is sampled at 2.82MHz, the PCM signal (shown in the plot) is sampled 16x slower at 176kHz, and the desired audio signal ranges from 20 Hz to 22.1kHz. Given these values, I had expected an FIR low-pass with a cutoff at 88.2kHz to remove most of the noise since this is 16x below Nyquist of the original DSM. Is my logic flawed? Nov 24, 2020 at 4:48
• How can you have a cutoff that is half the sampling rate? Or did you filter at 2.82MHz and then resample? Can you plot your complete spectrum at 2.82MHz rate and then the response of your filter and clarify the filtering details? Nov 24, 2020 at 12:16
• @DanBoschen The latter. I am filtering the 2.82MHz signal and then I am downsampling by a factor of 16; at least I think this is what I am doing. I will generate the plots and update my question. As I said above, this is a learning project, so I don't have a good toolchain to work with audio yet and this may take me a while to do. I will ping you after I've updated the question if that's okay. Nov 24, 2020 at 13:01
• I recommend MATLAB, Octave or Python Scipy.Signal to work out the processing relatively quickly Nov 24, 2020 at 16:04

The spectrum appears to be the noise-shaping associated with Delta-Sigma Modulation. Specifically we see that the noise increase follows a 20 dB/decade slope, indicative of a first-order delta-sigma modulator.

The high end of the noise rolls off consistent with the high frequency roll-off of the filter applied.

Below are some charts I have explaining the first-order Delta-Sigma modulator and how such noise shaping occurs, here specifically with a Delta-Sigma Digital to Analog Converter (but it could easily be a 1 bit digital output just the same). And equivalently the Delta Sigma Analog to Digital converter diagram is shown below, which will be used to develop a simple loop model for providing an understanding of how noise shaping occurs. Below is a qualitative loop model, providing an intuitive understanding of noise shaping if one has an appreciation of filtering in simple control loop models. Specifically it is showing an 1 bit A/D Converter as a gain with quantization noise added (this is a highly non-linear process, therefore the model is qualitative versus a quantitative prediction). The path through the loop from the quantization noise input ($$N_q$$) to the output follows a high pass function as shown below. Quantization noise would typically be white noise (uniform over all frequency) for a traditional data converter, while with the implementations using Delta Sigma modulation we get this resulting noise shaping resulting in significantly higher precision at a given sampling rate after the high frequency noise is filtered out. Typically higher order implementations are used, such as the 2nd order Delta Sigma shown below (and higher orders such as 5th order are commonly implemented). This provides much steeper noise shaping (much less noise in the band of interest after filtering) and also serves to significantly reduce pattern noise which would manifest as spurs in the spectrum.  • Thanks for the detailed answer! I'm still digesting it; I read about noise shaping before, but now I realize that I actually didn't really understand it as well as I thought. Your answer also made me realize that my periodogram of the DSM signal was faulty. I updated it and now I can see the shaped noise in the raw signal (updated the question). I think I will have to spend a bit more time with your answer though to see how this should be applied to my case in order to properly filter the noise, but this already gets me a good part down the road - I think. Thanks again. Nov 25, 2020 at 12:03
• Extend the range of your vertical axis about 6 decades lower and also plot your frequency axis on a log scale ans you will see the 20 dB/decade noise slope on the left side of the plot that I am referring to Nov 25, 2020 at 15:04
• the gain of the 1-bit ADC (which is essentially a comparator) and the 1-bit DAC should be combined into a single gain. in 1986, John Paulos published what that net gain is, if $x$ is the input to the comparator and $y$ is the output: $$K_\mathrm{adc} K_\mathrm{dac} = \frac{\mathrm{E}(yx)}{\mathrm{E}(x^2)} \ = \tfrac{\Delta}{2}\frac{\mathrm{E}(|x|)}{\mathrm{E}(x^2)}$$ where $\Delta$ is the step size between the two levels of the comparator (DAC) output. Nov 26, 2020 at 4:09
• and in the ΔΣ DAC, it's not "All bits = MSB" because if you're gonna do some subtracting, the quantities better be two's complement and all bits below the MSB are opposite of the MSB. it's ± Full Scale. Nov 26, 2020 at 6:11
• @Robert I was using offset binary but duly noted as it would always be 2's complement--updated to avoid that confusion, thanks. Nov 26, 2020 at 21:09