Is slower sampling doing the same thng as bit reduction?

Started by Mark Hammer, March 27, 2021, 03:00:54 PM

Previous topic - Next topic

Mark Hammer

As noted in another thread, I put together the circuit titled "analog bit crusher" and "Horndog" on the Madbean site.  It's a fairly simple circuit with an input and output buffer, linked by a FET.  The FET, in turn, is turned on and off by a high-frequency clock.  In effect, it is pretty much identical to a sample and hold, although S&H units clock MUCH slower, and the signal they sample is noise, rather than a guitar input.  But the principle is the same: short snapshots of an input are taken every time the FET gate is turned on and held by a cap.

In theory, bit reduction CAN vary the rate at which sampling occurs, but is termed bit reduction because it varies the resolution of the sample.  The unit described above ONLY varies the sampling rate, and does not change the resolution of the sample obtained.  The sampled voltage is the sampled voltage, without being rounded up or down to the next quantized value, as dictated by the bit resolution.  And as I've found, turn the sample rate up to an ultrasonic frequency, and one is hard-pressed to tell it apart from straight bypass.

But it's a little like ring modulation in some ways.  If you modulate an audio signal in some way at audio frequencies, it *sounds* like a ring moduator, even though technically it isn't.  Modulate a tremolo, phaser, flanger, chorus, vibrato, etc at, say, 100hz, and it WILL sound like a ring modulator, and do all the usual RM phenomena like producing an audible descending note when you try to bend UP.

Which leads me to the question: if "all" one does is sample an audio signal at a low enough rate, is the audible result the same as bit reduction?  Is it actually different but only easily confused with bit reduction?  Is a "stairstep" (produced by sampling slowly enough that the signal has "moved on" before the next sample is taken) = a stairstep = a stairstep?


Eb7+9

Quote from: Mark Hammer on March 27, 2021, 03:00:54 PM

it is pretty much identical to a sample and hold ...


when I came up with my first "Aliasing" circuit in 2005 I referred to it as Audio Rate Sampling, or simply Under Sampling - obviously alluding the Nyquist's theorem in communication theory ...

https://www.youtube.com/watch?v=Z6gbEH0vZ74

http://www.lynx.net/~jc/nyquistAliaser.html


someone thought Bit Crusher rolled off the tongue better, and it stuck here and there ... these days several pedal makers correctly use the name Aliaser

I always wondered tho ...
did anybody ever build a working variable depth A/D/A converter ... ??!

Mark Hammer

Quote from: Eb7+9 on March 27, 2021, 04:06:02 PM
I always wondered tho ...
did anybody ever build a working variable depth A/D/A converter ... ??!
Do you mean commercially or someone here on the forum?  The EHX Mainframe, for example, provides both variable sample rate AND "bit-reduction" (i.e., variable resolution) from 24 to 1-bit resolution.

I haven't explored the medium very far.  Does bit-reduction, while holding sample-rate constant, produce the same sorts of audible quasi-sideband products that sub-optimal sample rate does?

anotherjim

Bit reduction is different and largely results in harsh distortion. The lowest bit/bits can often be disabled without any big effect. Bits in the middle of the word are more effective. Scrambling the bit order can result in just noise. Leaving the lowest bits intact can retain some intelligibility.

There is a crossover with Nyquist aliasing. If some bits are disabled, then the data value may not change which could have the same effect of a slow sampling rate that will also miss out those values.


Mark Hammer

My understanding was that bit reduction did not involve removing anything other than the most significant bits.  So nothing is "taken" from the signal.  Athough I gather that even when the device allows for reducing the resolution, it's likely in "even" steps.  I.E., I'm assuming that one can't set the device to 17-bit, 13-bit, or 5-bit resolution.  Or is it simpler to reduce resolution, bit by bit, than I imagine?

Digital Larry

#5
Aliasing will fold the spectrum around the (sampling frequency)/2, generally introducing tones which are not harmonically related to the original signal.  In this way it sort of resembles ring modulation.

Reducing the bit resolution adds what is generally referred to as "quantization noise".  In fact all A/D conversion is subject to quantization noise, it's just a matter of how obvious it is.  I can't describe it any simpler so I'll just cop out and provide the technical article.

https://www.sciencedirect.com/topics/engineering/quantization-noise

that one is taking about images.  I think this one is more general purpose.

https://classes.engineering.wustl.edu/ese488/Lectures/Lecture5a_QNoise.pdf

Edited to add the ever important divide by two to get the Nyquist frequency from the sampling frequency.
Edited again to add the comment about ring modulation.
Digital Larry
Want to quickly design your own effects patches for the Spin FV-1 DSP chip?
https://github.com/HolyCityAudio/SpinCAD-Designer

Eb7+9

Quote from: Digital Larry on March 27, 2021, 09:55:01 PM

Aliasing will fold the spectrum around the sampling frequency, generally introducing tones which are not harmonically related to the original signal.

Reducing the bit resolution adds what is generally referred to as "quantization noise".  In fact all A/D conversion is subject to quantization noise, it's just a matter of how obvious it is.  I can't describe it any simpler so I'll just cop out and provide the technical article.


exactly, I never imagined that adding quantization noise to a signal would be hip in any way ... but all it takes is a crafty producer to show the opposite to be true // why I'm asking

anotherjim

I think if you had a system of ADC -> data latch -> DAC you could mess with everything. The bits are yours to toy with and varying sample-rate is a natural addition. It's obvious to say it's a job for a cheap MCU, but thru-hole DIP converters with parallel data bus are still available such as the ADC08xx range. The ADC doesn't need anything clever to get a conversion since it's a ladder comparator "flash" converter.

I have a notion the effects are far more useful on audio with full content. Some while ago I circuit-bent an attic-find TR505 drum machine. It's digital so what's to bend? Well, all its sounds are in an 8bit ROM and the playback rate is set by a ceramic resonator, so I added switches to disable some bits and hacked the resonator frequency. The result can be pretty extreme and unique.


Digital Larry

Quote from: Mark Hammer on March 27, 2021, 09:42:48 PM
My understanding was that bit reduction did not involve removing anything other than the most significant bits.  So nothing is "taken" from the signal.  Athough I gather that even when the device allows for reducing the resolution, it's likely in "even" steps.  I.E., I'm assuming that one can't set the device to 17-bit, 13-bit, or 5-bit resolution.  Or is it simpler to reduce resolution, bit by bit, than I imagine?
Correction, bit reduction usually removes the least significant bits.  You can of course do anything you like with audio bits, but it rapidly loses any resemblance to the original.

The is generally done by doing a bitwise AND with a mask value.

e.g.

audio (binary)

10110011 AND with mask 11111100
gives
1011000

You can see that no matter what the value of the lowest two bits, the following input values generate the same output value.

10110000
10110001
10110010
10110011

SpinCAD's "bit reduction" block lets you quantize signals from 1 to 16 bits.  The FV-1 doesn't distinguish audio from control signals, so you can quantize audio or control voltages equivalently.  The registers are 24 bits wide.

SpinCAD's "Aliaser" block has two modes, a "smooth" and a "raw" mode.  I think the "smooth" mode ramps between adjacent samples while the "raw" mode holds that value constant until the next time we sample the input.  I did not develop the basic algorithms for either one of these.

Also note that there are certain things you can do to signals inside a DSP which will create aliasing.  For example, if you take a sine wave and simply clip off the top half of it in your DSP code, you will have created aliasing.  If you dig into DSP code for synthesizer oscillators you will find reference to things like "sawtooth" and "band limited sawtooth".  Generating a sawtooth waveform directly will also result in aliasing because certain sample to sample level jumps, while mathematically possible, cannot be achieved within the Nyquist bandwidth.  Band limited signals look smoother than their raw counterparts.  How exactly this is done is outside of my experience.  This is one of the main challenges facing designers of amp modeling algorithms.  You can clip things harshly all day long with a transistor and you will not create aliasing.
Digital Larry
Want to quickly design your own effects patches for the Spin FV-1 DSP chip?
https://github.com/HolyCityAudio/SpinCAD-Designer

iainpunk

we all know how bit rate reduction sounds, its demoed on the internet enough
if you want to hear the sound of voltage level quantitation, versus clean:
https://soundcloud.com/iain-schmaloer/stair-transfer-shape
here i use a digital transfer function program, called "Fruity Wave Shaper" where you can literally draw the transfer function, its my favorite plugin to use in any DAW
the transfer graph looks like this:


it sounds interesting, but not as musical as Nyquist Distortion, it doesn't have that ring/bell sound we know and love and it sounds kinda bad tbh.

cheers, Iain
friendly reminder: all holes are positive and have negative weight, despite not being there.

cheers

ElectricDruid

Sample rate reduction and bit depth reduction aren't the same thing at all. The simplest way to think about it is that one is to do with the time resolution of the resulting signal (the "horizontal" dimension) whereas the other is to do with the amplitude resolution of the signal (the "vertical" dimension).

Reducing the sample rate causes aliasing to become apparent. This is harmonically unrelated to the signal, since the effect is that higher harmonics (or even very high fundamentals) that are above half the sample rate (the "nyquist limit") will "bounce off" and come back *down* into the audio. The sound of a bright ramp wave being swept upwards is the classic test for aliasing because the sound of the aliased harmonics sweeping down as the pitch sweeps up is so obvious and distinctive. For sounds that are static in pitch, aliasing gives other apparently-random unrelated enharmonics, which is why it sounds a bit like ring mod.

Reducing the bit depth is completely different. Essentially you're replacing your waveform with a version of made out of little stair steps. Imagine building a copy of your signal with square waves. The big difference from aliasing is that this is harmonic distortion. It's crunchy, but it's related to the pitch you put in, which aliasing isn't necessarily.
There's no reason why you need to stick to even numbers of bits. You can have any number from whatever your maximum bit depth is down to one. Of course, you can't do half-bits or quarter-bits, so a bit depth control is always a limited set of options not a continuous value (Integers from 16-bit down to 1-bit, for example). This is unlike the sample rate which can be continuous - you could go smoothly from 500Hz to 50KHz.


iainpunk

QuoteOf course, you can't do half-bits or quarter-bits,
there are some VST's that have non-integer voltage level options, but this just makes the outer stair-steps less tall in the graph
friendly reminder: all holes are positive and have negative weight, despite not being there.

cheers

Mark Hammer

Irrefutable, Tom.
BUT...one also gets stairsteps when the sample rate is "too slow" to follow a smooth change in AC voltage, and turns it into a series of slightly discontinuous snapshots

I guess the reason why I asked the question in the first place was because I was curious about whether there was anything qualitatively and audibly different about the resulting "stairsteps", as opposed to what is conceptually and/or mathematically true of them.

Rob Strand

You don't even need a digital system to get aliasing.   Think about BBD chips and switched cap filters.  They are continuous in that there are no discrete amplitude levels but they are sampled so they suffer from aliasing.
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

fryingpan

#14
Quote from: Mark Hammer on March 29, 2021, 07:02:45 PM
Irrefutable, Tom.
BUT...one also gets stairsteps when the sample rate is "too slow" to follow a smooth change in AC voltage, and turns it into a series of slightly discontinuous snapshots

I guess the reason why I asked the question in the first place was because I was curious about whether there was anything qualitatively and audibly different about the resulting "stairsteps", as opposed to what is conceptually and/or mathematically true of them.
If you take a bandlimited ramp (which, look closely enough, is actually kinda "curvy") and you downsample it, yes, you're going to get "stairsteps". Except that you don't. See, mathematically speaking, any sampled signal is a train of impulses. There is no continuous line going from one sample to the next, what you see when you do that is simply linear interpolation, which is not what happens mathematically (or practically, usually). From a maths point of view, that train of impulses is, spectrally, a periodic copy of the original spectrum, with a copy from -fs/2 to +fs/2 every k*fs. That is the reason you get aliasing distortion when you sample a signal without filtering out all components over fs/2. Imagine a double triangle with two coincident vertexes (something like |\/| ) and copy it infinite times across the spectrum. If you don't "shorten" those triangles when you downsample, you're going to get parts of the "left triangle" (which is really a "copy" of the real signal - not a copy, really, but an integral part of the signal) overlaid over the right triangle. So in essence, you're not really getting any stairsteps when you downsample (well, you do if you hold the sampled voltage, but that's really a crude form of interpolation which doesn't change things much), you're simply spacing those impulses about further apart, and if you don't filter the original signal before you downsample (remember when I said that the bandlimited ramp is rather curvy? Well, that's what happens to a signal when you filter out any of its components: you change its shape!) that train of further spaced apart impulses is going to result in harsh enharmonic components just towards the treble side, if you're lucky enough, of the spectrum (treble = harsh).

Mark Hammer

So, a gedanken experiment.  What happens if we tack a glide/slewing stage on the output of either a bit reducer or an aliaser/undersampler?  The steps are effectively smoothed out, or transformed into tiny ramps.  What would THAT sound like?

fryingpan

Quote from: Mark Hammer on March 29, 2021, 08:22:42 PM
So, a gedanken experiment.  What happens if we tack a glide/slewing stage on the output of either a bit reducer or an aliaser/undersampler?  The steps are effectively smoothed out, or transformed into tiny ramps.  What would THAT sound like?
That would sound like linear interpolation. There are equations and stuff which tell you what it would look like mathematically, and if you know what that means, you can sort of get what it would sound like. Basically, it would sound smoother than sampling and holding (because it presents fewer discontinuities) but still distorted. I haven't gone through this stuff for a long while though so I'll let others be more exhaustive.

ElectricDruid

Quote from: Mark Hammer on March 29, 2021, 07:02:45 PM
I guess the reason why I asked the question in the first place was because I was curious about whether there was anything qualitatively and audibly different about the resulting "stairsteps", as opposed to what is conceptually and/or mathematically true of them.

Yes, they might look similar on the scope (both just "steppy waveforms"), but they definitely sound different. Bitcrush is crunchy but to my ears sounds ok (after all, we mostly like harmonic distortion) whereas aliasing is usually an enharmonic ugly racket.

Rob's BBD example is good, because that gives us a way to think about what happens with sampling without confusing the issue by also introducing quantisation. It is purely the horizontal dimension that gets scrambled (noise notwithstanding).

garcho

I wonder how much difference would be audible comparing a pair of bit crusher and aliaser with perfectly set up "staircases" (theoretically, obviously difficult) and fed  white or pink noise vs pure waveforms, like sine. Of course most sound sources are somewhere between the two, it might be interesting to hear how each deals with the extremes and harmonics, or lack of. It might not be very interesting too, I suppose. :)
  • SUPPORTER
"...and weird on top!"

Mark Hammer

Let me just say this has been an interesting and informative thread.  Thanks to contributors.

One thing that I suspect bit-reduction may or need NOT result in is audible clock whine and that form of aliasing.  Of course that assumes the sampling is at a high-enough frequency that any aliasing is out of "the danger zone".