Oversampling, ILO tri

Discussion in 'Building With Reaktor' started by Laureano Lopez, Mar 25, 2021.

  1. Vadim @ NI

    Vadim @ NI NI Team NI Team

    Messages:
    278
    Try x/(x+1) and x/(-x+1) instead ;) Actually these are the two hyperbolas that x/(|x|+1) defines (and, depending on the derivation, the latter is actually obtained as a shorthand notation for joining the two together).
    E.g.
    int x/(x+1) = int (x+1-1)/(x+1) = int [1 - 1/(x+1)] = x - ln(x+1) forall x>=0 (this is where |x|=x).
     
    • Like Like x 2
  2. Paule

    Paule NI Product Owner

    Messages:
    7,325
    The tests on iOS do not bring any acoustic advantage.
     
  3. colB

    colB NI Product Owner

    Messages:
    3,823
    I suppose it makes sense in some way, but still a bit strange.
     
  4. Kubrak

    Kubrak NI Product Owner

    Messages:
    750
    And, what about to use library service? In my country, libraries are forced to be closed. So, they are allowed to let readers to access stuff online..... They have IEEE in paper, I guess they will have it online as well. ;-)
    So, maybe something like it might work in your country....
    But I agree, asking $33 for an article is almost crime.....
     
    • Like Like x 1
  5. Laureano Lopez

    Laureano Lopez NI Product Owner

    Messages:
    408
    Hadn't thought of that, I'll check it! Surely there must be one library in the country with a IEEE subscription :)

    I added a new set with a more relaxed transition band. The passband corner at 3/7 SR was too strict -all filters are -3 dB at Nyquist, so if I move the corner as low as SR/3 I'm still 0.01 dB away from flat up to 18k@44100. It also has a more reasonable group delay and makes the whole thing more orthogonal, with 3 levels of quality for each stage. The old set is still there in a separate group.
     
    • Like Like x 2
  6. Laureano Lopez

    Laureano Lopez NI Product Owner

    Messages:
    408
    This is kind of a small breakthrough for me, so I'll ramble a bit.

    As I said somewhere, I've been looking for an efficient way of antialiasing level detection. A level detector is basically squaring, a lowpass and a square root. Squaring doubles the bandwidth -it generates frequencies up to SR, so it should be done at x2 oversampling to avoid aliasing. Now, there's a lot of KVR fanfiction about this -that a non oversampled compressor infects your music with cosmic aliasing from the stars and gives you cancer. This is bs. There are two points where a compressor can alias -the squaring, and later when the signal is multiplied by the sidechain. The latter is irrelevant -the sidechain is very lowpassed, so it can barely alias. For level detection, both the squaring and the lowpass need to be oversampled. If we oversample just the squaring, the downsampler takes the peaks down. We need a fairly flat filter both in frequency and phase, that's not outrageously expensive. It mainly needs to cut the very high stuff close to SR, which folds down close to DC -the rest will be lowered by the lowpass anyway.

    ILO doesn't work for this -the squaring is easy, the lowpass is not. Also, it takes down the top end too much, so it lowers transients. Symmetric half-band FIR filters are not very good either. They're amplitude-complementary, so we need a high order to get a decent flatness. Also, there's a delay line for upsampling and two for downsampling, so even for low order they're not cheap.

    These allpass thingies are power-complementary, so they have a very flat amplitude in the passband for a fairly low order. Sadly, they have a very not flat group delay. Back to happiness, they can be made flatter, by taking one branch to be a pure delay. These are usually called "quasi linear phase" half-band filters. We need to find the sweet spot between order and cutoff. For a given order, a higher cutoff gives a wider passband, but with larger ripples, and a higher max at SR/2. I tried a bunch of combinations. Higher orders are generally better, until the max group delay becomes too high. Higher cutoffs are better for transient-heavy stuff, but worse for the rest -with a quiet top end, passband flatness is more relevant. I picked the sweet spot at 4th order and a SR/3 cutoff. It has total latency of 7 samples.

    The optimal FIR half-band for the same latency and cutoff has less attenuation, larger passband ripples and a more recessed top end -its only virtue is the flat group delay. It's outperformed in most tests, except for very hard transients, where the group delay flatness near SR/2 becomes relevant. It's also less efficient, even when it uses less math ops.

    What's the effect of this? The antialiased detector gives higher peaks. It makes sense -it's finding peaks between samples, so it's a poor man's true peak detector. In my application (the multiband thing that's like my gardening project), it gives higher levels for the top band -not much difference for the rest, as expected. It also makes little difference for RMS detection. That's pretty much what "aliasing" means here -missing intersample peaks.

    Some pictures just for the colors (?). These are the amplitude responses of the allpass and FIR filters. On the right it's just the passband.
    amplitude.png
    These are the normalized group delays for some of the order/cutoff combinations I tried. Green is my pick.
    gdelay.png
    These are impulse responses. Green is the original impulse, red is the FIR, white is the allpass, blue is the non-linear-phase allpass of the same order and cutoff. You can see the last one smears too much, it loses the height of the peak. The white one is close to symmetric, and the red one seems ok, but those quickly decaying wiggles mean we have lost some top end.
    impulse.png
     

    Attached Files:

    Last edited: Apr 4, 2021
    • Like Like x 1
    • Informative Informative x 1
  7. ANDREW221231

    ANDREW221231 NI Product Owner

    Messages:
    784

    now i'm just thinking back at all the audio signals i've squared without even giving this a thought. of course, i knew this at some level, like in the context of multiplication as a ring modulator, but never once thought about how it might screw up level detection too
     
  8. Laureano Lopez

    Laureano Lopez NI Product Owner

    Messages:
    408
    It mainly matters when there's a high amount of energy in the top end -that is, for transients. I don't like when people who make expensive boutique plugins explain it in terms of aliasing -it doesn't have the audible effect associated with it. It's just an imprecision in level detection.
     
  9. Vadim @ NI

    Vadim @ NI NI Team NI Team

    Messages:
    278
    Laureano Lopez Not sure if it has been mentioned, or whether it's practical in the given context, but you might want to take a look at Lanczos filters (don't ask me, I don't know anything about them ;) ).
     
    • Like Like x 1
  10. Laureano Lopez

    Laureano Lopez NI Product Owner

    Messages:
    408
    I tried the Lanczos filter back when I was testing windows in general. It doesn't have a zero at pi, but a little scaling fixes that. It seems to work very well with images, but I think it's not particularly good in this context. Of all the windows I tried, I'd go with Kaiser.
    a.png b.png
    Blue: the allpass based, orange: Lanczos, green: Kaiser, red: equirippled. All for the same latency.

    Lanczos has a faster roll-off, but less attenuation in the stopband, and larger ripples in the passband than Kaiser.
     
  11. Vadim @ NI

    Vadim @ NI NI Team NI Team

    Messages:
    278
    Do you care about ripples in time or frequency domain? I thought, since you want to do level metering, you'd care about time-domain ripples. But then I'm not sure what is your second graph either.
     
  12. Laureano Lopez

    Laureano Lopez NI Product Owner

    Messages:
    408
    They're both in frequency domain, the second one is a zoom on the passband. In general, more top end makes for louder ringing, so the modified Lanczos rings more than the Kaiser. There are other properties I'm not considering much, like continuity, which seems to be relevant for images. In my case, what matters more is the height of the impulse response, and the passband flatness (the context is multiband, so passband ripples alter the relation between band levels). The height of the IR seems to depend mainly on good preservation of the passband + high rejection of the stopband. This is all maximized in the IIR implementation, but there the phase response comes into play too. The version I picked seems to work better than equirippled and Kaiser FIRs on most of the samples I used for testing.

    What actually sold me though was the performance. I'm using this in a C++ context, with heavy SSE/AVX vectorization. The IIR still needs a delay, but only of 3-4 samples, so I can implement it with just two stores and two loads for both mono an stereo. The FIR needs a 7-sample delay, plus an additional 4-sample for downsampling, and I can't fit 14 floats in a single AVX operation, so there's additional overhead for stereo. The amount of math ops is about the same, but the CPU hates the memory overhead. What happens in Reaktor is curious though -the IIR uses quite more math ops (I don't have fused muladds here) and only 3 latches less, but it's still faster. It may have something to do with depth -the IIR has shorter paths from in to out, which may benefit pipelining.
     
    Last edited: Apr 25, 2021
  13. Studiowaves

    Studiowaves NI Product Owner

    Messages:
    587
    You guys are beyond genius.