This is a really interesting discussion to follow along.
On a quick look the ZOH approach will add a gradual rolloff to the signal (I iwould magine consistent with an FIR of equal values in the new sampling rate of N although wikipedia says - "a 3.9224 dB loss at the Nyquist frequency, corresponding to a gain of sinc(1/2) = 2/π” but constructing FIRs gives different results according to their length… (https://en.wikipedia.org/wiki/Zero-order_hold)
On 9 Apr 2025, at 13:09, Miller Puckette via Pd-list pd-list@lists.iem.at wrote:
after noticing that you get really strange results if you upsample a signal with zero-padding and then try to use it as the frequency of an oscillator... the oscillator's frequency drops by the upsampling factor. Another wa to say the same thing: the DC gain of a zero-padding upsampler is 1/N where N is the sampling factor.
I *think* but I am not 100% sure that this is one of these weird areas where gain stuff happens with DSP processes that get compensated by engineers but are not in the literature. In testing if I take some noise and zero out every other sample then not only do I mirror the spectrum but I also get a gain loss of -6dB (to my mind this is equivalent to zero-stuffing a signal of half the sample rate, so there seems to be a gain factor in this transformation). Therefore I think when you zero stuff you get a gain loss across the whole spectrum of 1/N and not just at DC.
You could correct this by multiplying the zero-padded signal by N but then what of someone tries to downsample it again...
It depends what happens in-between. If you are drop sampling and don’t filter then you will get the gain factor, but only if you are aligned for sampling (which if your counts start at the same time and always run together they will be, but this seems like a weak guarantee) - otherwise you could ALSO get all zeros, which is even worse. I think after filtering in the higher sample rate you’d get the right result, because the DC level in the higher sample rate is now correct, and the filtering would spread the energy so as to give the right number over the period. I’ve also done some rough tests on this that seem to confer (if I zero every second sample on a DC signal and then filter the output stabilises at a number half of the original)
I could be off on some of this stuff, because I am very practically oriented on these matters, and I don’t have a direct mathematical explanation to hand, but I think the testing I’ve done makes sense - happy to be corrected…
Alex
it then gets multiplied by N unless the downsampler averages all the N samples... and then we're back to something that resembles the ZOH filtering effect on the way back down.
If I weren't able to specify a choice of upsampling methods, an alternative would be to make a special ugen that filters its input but only looks at 1/N samples.
cheers Miller
On 4/9/25 1:07 PM, Christof Ressi wrote:
Hi,
I have made a PoC for adding upsampling and reblocking support to SuperCollider: https://github.com/supercollider/supercollider/pull/6702
One thing I have been thinking about is the default upsampling method. Currently, I'm using zero-order-hold (ZOH), aka "sample and hold", which is also the default for Pd's [inlet~]. The other practical alternative would be zero-padding. Letting the users choose the method is not a real option, so I need to settle on a good default.
Generally, upsampling is done by zero-padding + low pass filtering.
ZOH is basically a low-quality low-pass filter. It's like a FIR filter that consists of a series of 1s and the frequency response is that of a Sinc function. AFAICT, it introduces high frequency noise, but I'm wondering how relevant that is when the output runs through an antialiasing filter anyway.
Zero-padding without low pass filtering results in repetitions of the original spectrum above the original Nyquist frequency. (It's like multiplying the signal with an impulse train, which results in the spectrum being convolved by an impulse train, resulting in a regular repetition.) I think that an *unfiltered*//zero-padded signal can lead to strange result. For example, a slowly moving ramp would almost look like an impulse train.
In my understanding, a zero-padded signal *must* be filtered, while an unfiltered ZOH signal may be acceptable for many use cases. Is this correct? @Miller: Is this maybe also the reason why Pd 0.44 has switched from "pad" to "hold" as the default upsample method in [inlet~]?
Zero-padding has the advantage that low pass filtering can fully restore the original signal, which apparently is not the case for a ZOH signal. On the other hand, it's always possible to zero-pad the input signal after the fact.
At the moment I'm tending to keep ZOH as the default upsampling method, but I would be curious about other people's opinions.
Christof
pd-list@lists.iem.at - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/pd-list@lists.iem.at/message/YTQLO35UO4...
To unsubscribe send an email to pd-list-leave@lists.iem.at mailto:pd-list-leave@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/