Is there any benefits on making LFO alias free?

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

I'm implementing a very basic LFO oscillator on my plugin, with code such as:

Code: Select all

double value = 0.0;
switch (mWave) {
	case SINE:
	{
		value = sin(mPhase);
		break;
	}
	case SQUARE:
	{
		if (mPhase <= mPI) {
			value = 1.0;
		}
		else {
			value = -1.0;
		}
		break;
	}
	case SAW_UP:
	{
		value = (2.0 * mPhase / mTwoPI) - 1.0;
		break;
	}
	case SAW_DOWN:
	{
		value = 1.0 - (2.0 * mPhase / mTwoPI);
		break;
	}
	case TRIANGLE:
	{
		value = (2.0 * mPhase / mTwoPI) - 1.0;
		value = 2.0 * (0.5 - fabs(value));
		break;
	}
}

mPhase += mPhaseIncrement;
while (mPhase >= mTwoPI) {
	mPhase -= mTwoPI;
}
Of course, if I use this as audio oscillator sources, I will got lots of aliasing, which is not so good.

But, is it so bad used as LFO oscillator that will modulate a parameter? Did you make alias-free LFO generators? And why you should do it?

Just learning :wink:

Post

Nowhk wrote: But, is it so bad used as LFO oscillator that will modulate a parameter? Did you make alias-free LFO generators? And why you should do it?
Don't worry, it's totally fine as an LFO. It's so slow that aliasing doesn't matter. You could say that the harmonics have plenty of space to decay into inaudibility. Also at subsonic frequencies you don't hear tones, you hear rhythm. So any aliasing wouldn't be audible as tones. The result is at most a sub-sample inaccuracy in timing. Kudos to you if you can hear that. 8)

Post

hugoderwolf wrote:Don't worry, it's totally fine as an LFO. It's so slow that aliasing doesn't matter.
Are you saying that It would matter if LFO were speedy? I don't get why it should...
Thinking to a square wave that modulate a gain: it always wrap between 1 (0db) and -1 (let say -70db, immediatly) even if I do it in many/few ms.

Post

I thought aliasing was only an issue for stuff approaching the nyquist frequency (hence the reference to the 'speedy' part I'm guessing)

Post

Nowhk wrote:
hugoderwolf wrote:Don't worry, it's totally fine as an LFO. It's so slow that aliasing doesn't matter.
Are you saying that It would matter if LFO were speedy? I don't get why it should...
Thinking to a square wave that modulate a gain: it always wrap between 1 (0db) and -1 (let say -70db, immediatly) even if I do it in many/few ms.
When modulating anything with a broadband audio-frequency waveform, you have much worse issues anyway. It's not just about bandlimiting the oscillator, but also about bandlimiting the modulation itself. Modulating a gain (amplitude modulation) is the simplest case here. Both waves need to be bandlimited, but the result of multiplying two broadband waveforms doubles bandwidth, so you need some antialiasing scheme for the modulation itself as well.

For now, stay away from doing any kind of frequency modulation (FM, PM, Filter-FM) with anything but a sine wave. It'll bring you straight into hell. ;)

Post

hugoderwolf wrote:Both waves need to be bandlimited, but the result of multiplying two broadband waveforms doubles bandwidth, so you need some antialiasing scheme for the modulation itself as well.
Really, visually I can't see how "aliased" modulation source (Modulator, such my LFO) can introduce "alias" to the processed audio signal (Carrier). Or at least, why it introduce alias only if I set a faster frequency for my LFO :neutral:

How could I see it on a plot?

Post

Nowhk wrote:
hugoderwolf wrote:Both waves need to be bandlimited, but the result of multiplying two broadband waveforms doubles bandwidth, so you need some antialiasing scheme for the modulation itself as well.
Really, visually I can't see how "aliased" modulation source (Modulator, such my LFO) can introduce "alias" to the processed audio signal (Carrier). Or at least, why it introduce alias only if I set a faster frequency for my LFO :neutral:

How could I see it on a plot?
Modulation introduces sidebands to the resulting spectrum.

AM introduces sum and difference signals. If M and C are both sine wavs and C = 100hz and M is 1hz, then you will have 99, and 101hz sidebands.

FM introduces sum and difference signals and integer multiples thereof going to positive and negative infinity (and reflecting/aliasing back at nyquist and DC in digital audio). If M and C are both sine wavs and C = 100hz and M is 1hz, then you will have 99, 98, 97, 96, 95... and 101, 102, 103, 104, 105... sidebands. The amplitude of these sidebands is controlled by the modulation index (or frequency deviation), and follow Bessell functions. Generally they decay to infinity the father away from the carrier you are and at some point can be considered non-existant for practical purposes.

If either/both C and M are complex signals (anything other than sine wav) you would have to do this same calculation for each and every partial combination/permutation between C and M.

So if for example you have triangle C and M and C is 1000hz and M is 20hz and you perform FM, the 25th harmonic of M is going to be modulating the 20th harmonic of C (ok fine there is no 20th harmonic of a triangle wav, but forgive that for sake of easy math :wink: ), so you would have:

20000 +/- n*500
=
...
17500
18000
18500
19000
19500
(20000)
20500
21000
21500
22000
22500
...

if SR is 44.1k, the last component aliases...

in the case of two triangles the level is extremely low... but if it were two saws or two squares (even both band limited) the aliasing could be more prominent...

basically the more HF energy in the C or M, the faster the mod rate, and the deeper/wider the mod depth the more the bandwidth expands... it expands very quickly for complex wavs even if both C and M are perfectly band-limited.

Post

..and if M is not properly band limited and instead just calculated "naively" it really just means two things:

1) the M signal now has additional inharmonic partials in it that will create their own sidebands via combination/permutation with harmonics in the C signal.

2) the M signal may have more HF energy at around 1/2 SR compared to it's band limited version, depending on how steep the band limit filter is, so it might expand the bandwidth just a little more comparatively...

Post

Nowhk wrote:
hugoderwolf wrote:Don't worry, it's totally fine as an LFO. It's so slow that aliasing doesn't matter.
Are you saying that It would matter if LFO were speedy? I don't get why it should...
Thinking to a square wave that modulate a gain: it always wrap between 1 (0db) and -1 (let say -70db, immediatly) even if I do it in many/few ms.
If you for instance amplitude modulate audio with a 1 Hz not-antialiased square wave, then you will likely hear two clicks per second in the audio.

The clicks would always be there, but may be more or less noticeable to the ear depending on the nature of the music masking the clicks. It would be typically easier to hear the clicks on such as a sustained mellow organ or flute track, and less-easy to hear the clicks on a busy latin percussion or drum track.

Also kind of a statistical thing. The ear wouldn't necessarily notice every single click, depending on the nature of the music. OTOH even one click will ruin a track.

You could also get repetitive clicks when amplitude modulating with even a non antialiased triangle LFO. With the triangle LFO it would be even more a "statistical" thang, being less likely to hear any particular click, but fairly likely you might hear at least one of them during the play length of a song.

Post

Nowhk wrote: How could I see it on a plot?
Watching how a single carrier shifts the spectrum in AM modulation. The imagine you having an aliased carrier that has several frequencies that each shift the baseband signal on its own.

Post

@Galbanum: in these days I'll try to do some test with your test example values. Thanks for write your effort :tu:
JCJR wrote:If you for instance amplitude modulate audio with a 1 Hz not-antialiased square wave, then you will likely hear two clicks per second in the audio.

You could also get repetitive clicks when amplitude modulating with even a non antialiased triangle LFO. With the triangle LFO it would be even more a "statistical" thang, being less likely to hear any particular click, but fairly likely you might hear at least one of them during the play length of a song.
Yes, but I'll got clicks even if I use aliased or not aliased source (LFO) modulator. What's the point of this? :)
SISKO wrote:Watching how a single carrier shifts the spectrum in AM modulation. The imagine you having an aliased carrier that has several frequencies that each shift the baseband signal on its own.
But in that case, carrier is aliased, not modulator. I'm talking about if modulator is not alias free...

Post

To answer the original question:
An aliasing LFO will produce aliased results when it modulates a signal. This is obvious, because by definition the aliasing LFO contains unwanted frequencies, and if the LFO is doing anything at all to the output signal then those frequencies will have some unwanted effect.

Whether those unwanted effects are a problem depends on (a) the frequency of the LFO, (b) the depth of modulation, (c) what parameter is being modulated, (d) the frequency components of the signal being modulated.

Note that modulating even with a bandlimited LFO can still produce out-of-band frequencies - in practice you can either ignore this and live with the aliasing, or modulate in an oversampled way and then filter and decimate the result. Doing the latter would probably also go a long way towards removing any effect from aliasing in the original LFO.

I would suggest that unless you are planning to do some fairly extreme modulation then it probably isn't worth antialiasing the LFO itself, at least until after you've dealt with any aliasing caused by the modulation itself.

Post

Nowhk wrote:
JCJR wrote:If you for instance amplitude modulate audio with a 1 Hz not-antialiased square wave, then you will likely hear two clicks per second in the audio.

You could also get repetitive clicks when amplitude modulating with even a non antialiased triangle LFO. With the triangle LFO it would be even more a "statistical" thang, being less likely to hear any particular click, but fairly likely you might hear at least one of them during the play length of a song.
Yes, but I'll got clicks even if I use aliased or not aliased source (LFO) modulator. What's the point of this? :)
Your original square wave example proposed 100 percent modulation chopping from all-on to all-off. That would take a bit of care to de-click fer sure. But with "naive sharp angles" in a triangle, ramp or square LFO, you could get "occasional clicks" even modulating as little as 1 dB.

If you write the code and don't hear clicks during testing, and then forget about it assuming that the code is debugged-- You run the risk of later user complaints, possibly years later, because the user happened to apply your program onto some kind of audio file which cruelly exposes the clicks. Then if you forgot about that piece of code it might take a long time to debug to figure out where the clicks are coming from. :)

I do not know whether such clicks from "very sharp edged" LFO slope changes are properly named aliasing. I think it is a "transiant aliasing" effect of the control signal splattering numerous brief high harmonics into the audio. Including brief harmonics above nyquist. But maybe it would be called something other than aliasing. Transient intermodulation anyway.

To fully eliminate all clicks pops and thumps, LFO "sharp edges" need rounding off quite a bit lower than nyquist, so dunno if you would call a "smoothed off non-clicking" square wave LFO anti-aliased. Maybe there is a more appropriate word.

Such clicks can also be bug-a-boos in compressors, expanders, noise gates or various envelope-driven filters, and also zipper noise of volume or tone automation.

A square LFO might need slew-rate limiting of the edge transitions of 1 to 10 ms. And the edges of the slew rate limiting needs rounding as well. If you just draw a square wave with a linear 1 or 10 ms ramp substituting for the instant vertical rise or fall of the transitions, you can get clicks from the "sharp angles" at the beginning and end of those linear slews-- Also need to round-off the sharp angular transitions betweenLFO tops and bottoms into the slew regions.

Post

JCJR wrote: To fully eliminate all clicks pops and thumps, LFO "sharp edges" need rounding off quite a bit lower than nyquist, so dunno if you would call a "smoothed off non-clicking" square wave LFO anti-aliased. Maybe there is a more appropriate word.
This is not what "anti-aliasing" means at all. Whether you want your edges to be sharp or soft has absolutely nothing to do with anti-aliasing.

Anti-aliasing means eliminating aliasing. Given perfect anti-aliasing (which you can construct by additive synthesis or approximate with number of other methods) the only difference between the "aliased" and "anti-aliased" clicks is that the timing of the "aliased" clicks are going to be rounded to the sampling intervals (and because this "rounding" has predictable patterns, you'll end up with those aliasing partials), where as the "anti-aliased" clicks will be placed at exact half-periods of the LFO, whether or not this happens to align with the sampling grid.

That's it. They'll be just as "sharp" either way. So let's talk about aliasing instead.

If your LFO is at 20Hz (which is roughly the region where you transition from "low frequencies" where we hear clicks to "audio frequencies" where we hear pitches), then given that a square-wave has 20dB/decade spectral decay, the harmonics at 20kHz will be ~60dB down from the fundamental. If you put the LFO to 2Hz, then you get another 20dB decay. If you have a triangle-wave instead (which is C0-continuous) then you can add 20dB/decade effectively doubling these figures (ie. 20Hz triangle is down by ~120dB at 20kHz). Since 20dB/decade is ~6dB/octave, you can add another 6dB (or 12dB for triangles) for every factor of 2x oversampling you throw into the mix. For these figures to be useful, you need to sample at audio rate, but if you do, then aliasing of actual low-frequency waveforms might not be a very serious concern.

If you sample at some lower control-rate then the aliasing will happen at that control rate and you should then additionally consider any images created by your chosen interpolation scheme. For cheap interpolation schemes (ie. practically anything you would seriously consider for modulation signals), the latter is likely to be a larger problem than any aliasing resulting from sampling a low-frequency waveform at any reasonable control rate and even this is unlikely to make much of a difference unless you are pushing your LFOs into the audio rates.

YMMV.. but like .. for an LFO at actual "low frequencies" you probably shouldn't worry too much about aliasing. You might or might not want to worry about the effect of low control rates and poor interpolation schemes, but .. well .. whatever.

Post

mystran wrote:So let's talk about aliasing instead.
I think it is necessary to me take a break, because maybe I wrong the idea about what is an aliased LFO.

Take a classic sine wave as example.
With the code above, if I set a frequency below the samplerate/2 (in my example, 44100/2 = 22050), I won't get any alias for the LFO.

Instead, if I go "over" that limit (which won't happens, as hugoderwolf assuage me, but lets take the example I will) than I got an alias version of that LFO sine.

But is this the whole concern about a non-alias free LFO? It will only modulate the target parameter not at the "frequency" I set (i.e. 25000Hz) but to an aliased one? If so, I think I won't worry about.

First because my LFO will go max to 200Hz (20hz with a multiplier of 10) for each choosen waveform (so it or harmonics decay below the nyquist).
Second: if this is what will happen (i.e. I go at very high rate), it will "just" modulate the signal with a different "frequency" than the one choosed. A sort of "wagon wheel effect" (not so grave I believe; it wont' "destroy/edit" the audio I'll modulate, it just modulate it using different frequency than the one set).

But not sure if I right understand this eheh...

Post Reply

Return to “DSP and Plugin Development”