3
$\begingroup$

I'm really tripping about this point! I try to reason with you and explain what's my trouble. Consider a scenario with Sample Rate 44100hz and a LFO square wave that will modulate some internal parameter of my plugin.

Its clear that if I generate that signal using this function:

if (mPhase <= mPI) {
    value = 1.0;
}
else {
    value = -1.0;
}

mPhase += mPhaseIncrement;
while (mPhase >= mTwoPI) {
   mPhase -= mTwoPI;
}   

once it reaches my D/A converter, the interpolation would make a signal that will contains alias (the more I pitch up foundamental, the more alias I got).

That's normal: I don't have sufficient samples to represent all partials of the signal I'd like to represent. Clear.

But, why this is true also on LFO?

I mean: once I create my digital square (that, until it interpolate, it's really just 1/-1), the target param would be modulated really as a "real" square wave.

Why it should modulate the knob in a way that contains "alias"? The knob won't move as the signal being generated after the interpolation (with ripples and not linear movement). It really moves linear as a square wave: -1, 1, -1, 1. No "alias".

I hope you got what I mean? I can't see visually the "alias" introduced by LFO (by square wave, in this case) modulating a knob.

Note: I know that using an LFO with the code above at a frequency lower than 20hz produce "un-noticeable" alias for audio/human hearing. But for the reason I question, it shouldn't produce alias at all.

$\endgroup$
2
$\begingroup$

TLDR; The LFO should not be anti-aliased. The final signal, after applying the modulation, should be alias free. In practice, you either ignore this or approximate the latter.

Details:

The correct (although not necessarily always practical) way to think about this is to think of the whole signal processing/synthesis chain as a continuous time process, and then apply an anti-aliasing filter in the end, before discretizing.

So say, for example, that you're modulating the amplitude of an audio oscillator with a square LFO, i.e. $x(t) = (1 + 0.5 v_\mathrm{LFO}(t))v_\mathrm{osc}(t)$, where $v_\mathrm{LFO}$ is the output of the LFO with amplitude $1$ and $v_\mathrm{osc}$ is the output of the oscillator, and assume that the audio oscillator is perfectly anti-aliased. Now, the x(t) will have discontinuous edges at transitions of the LFO, which will generate an infinite number of frequency components, which will alias. However, if you had done the modulation in the continuous time domain and then sampled with appropriate anti-aliasing filters, the transition edges would be smoothed and the signal as a whole would be band-limited.

Another effect is that the spectral components of the LFO itself will be aliased, which may or may not have audible significance. This can be seen for example by the fact that if the period of the LFO is not an integer number of samples, the lengths of the sequences of $1$'s and $-1$'s will vary (by one sample) depending on which side of a sample instant the transition happens to land on on which cycle.

As a further extreme example, say you're modulating the amplitude of a constant DC offset. In this case the output will be that of the LFO itself, and if you bring it to audio frequencies you will certainly hear aliasing if the LFO isn't anti-aliased.

On the other hand, it is not correct to apply an anti-aliased LFO to an anti-aliased oscillator, since modulation is a non-linear effect: ideally you should apply a continuous time LFO to a continuous time oscillator, and anti-alias (i.e. sample with bandlimiting) the result. However, smoothing the LFO transitions a little may restrict the bandwidth of the frequencies produced by the modulation, thus partially remedying the extra aliasing. You should not use a sharp anti-alias filter though, since its step response ripple could cause unwanted modulation, but rather a filter which has a good phase response (simple one-pole or a higher order Bessel).

As far as I know, there is no general method to remove aliasing in a system with modulation, and if there were, it would certainly depend on the specific modulation and what is being modulated (frequency vs. amplitude, oscillator vs. filter, and so on). However, oversampling is a straightforward if computationally costly method which can be used to reduce all aliasing in the audio band, including that caused by modulation.

Finally, as you say, if the LFO is well below audio frequency, it is quite unlikely that any of this will be audible. However, you should be careful in that also modulation depth will have and effect: if you're for example modulating the frequency of an oscillator, even with a low frequency, but such a large modulation depth that the change in the frequency is appreciable over a period of the oscillator, you may get audible effects (at least in principle, I have not made experiments nor do I have a reference to cite).

Addendum:

Why do we care about the continuous time model on a discrete system, when working with audio?

(I'm of course assuming here you mean by plug-in a VST or some other audio processing plugin).

Consider what is your end goal here: to produce a sound to be heard by a person. That is inevitably a continuous time (CT) process. What you have control over is the stream of samples sent to the DAC, which is where the signal is transformed from discrete to continuous time.

In other words, you are actually in the business of producing continuous time signals, and the discrete time (DT) representation is simply a tool to reach that end goal. This is what I mean by talking about discontinuities: they are discontinuities in the imaginary CT signal, samples of which form your DT signal.

The easiest way then to reason about the output CT signal implied by your DT signal is to form the DT signal by properly sampling a mathematically formed CT signal. For example with a sawtooth oscillator, you take an ideal mathematical ramp, you bandlimit it and sample it (by whatever method you like, such as BLIP, BLEP, oversampling etc), and then the sampling theorem will tell you that the output of the DAC will be that same bandlimited sawtooth. If you had instead thought of the sawtooth as a DT process and simply formed a naive discrete ramp, you would have been gravely disappointed, as you would have gotten the nasty sound of an aliased sawtooth, because the DT process you used happens to be equivalent to the naive sampling of a CT non-bandlimited sawtooth. I.e. your ears agree with the conclusions you get from thinking of the DT signal as a sampling of a CT signal!

Note that the above applies just as well to all parts of the synthesis/processing chain, which includes the modulators such as LFO's. The only difference is that the bandlimiting must take place (conceptually, this is often not doable in practice) as the final step in an imaginary processing chain (including all modulation etc etc) which happens in CT, the result of which you then sample to form your DT signal.

To take your S&H example: in a CT world, the S&H clock could well sample its input between the samples, and the resulting discontinuous transition would then happen also between the audio samples. If you model your synthesis chain in CT and then bandlimit the whole system, first of all the CT discontinuous transition in the output signal will be slightly smoothed by the anti-alias filter. Further, the sub-sample position of the transition will be reflected in the exact shape of the anti-aliased edge.

Again, whether all of this makes a difference you can actually hear depends on the circumstances, but the point is that a naively sampled LFO does not give you an ideal modulation, but neither does applying modulation from an anti-aliased LFO.

$\endgroup$
  • $\begingroup$ But with every kind of digital (hence discrete) signal I introduce discontinuity. Whats the purpose of an anti alias lfo if at the end acts as a s&h modulation? :) $\endgroup$ – markzzz Oct 28 '16 at 21:49
  • $\begingroup$ @paizza If you insist of thinking about this in discrete time, then there is no concept of aliasing. What aliases to what, since there are only frequencies between 0 and $F_s/2$? I added a rather lengthy explanation of why, for audio purposes, you should however always think of an underlying continuous time process, which you then sample (i.e. evaluate the continuous time formula at sampling instants) as your discrete time signal. It is in this (imaginary underlying) continuous time sense that I speak of discontinuities. I also slightly edited other parts of the answer. $\endgroup$ – Timo Oct 29 '16 at 13:25
  • $\begingroup$ @paizza and the short answer is: you indeed don't anti-alias the LFO. You consider the process of the LFO modulating an oscillator/filter/whatever in continuous time, and then you anti-alias the resulting continuous time signal before sampling. Unfortunately, this is rarely practical and approximations usually need to be used. $\endgroup$ – Timo Oct 29 '16 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.