DSPRelated.com
Forums

Anti Aliasing of Arbitrary Waveforms

Started by Scott Gravenhorst September 23, 2008
glen herrmannsfeldt wrote:

>> As far as I can tell he is just adding increments to a storage >> register and when it overflows it starts over. The pitch of his >> waveform varies with the size of increment added. It isn't clear if >> he "samples" this register after each addition or if he samples it >> at some n number of iterations or at some fixed interval of time. >> He has been very vague and unclear about describing the actual >> process. > > Consider that he took an ideal sawtooth wave, digitized it, designed > logic to generate the sampled (digitized) result, but didn't do any > low pass filtering. The fact that the sampling is done on paper or > in his mind doesn't make the result any different than done in an A/D > converter. >
An "ideal sawtooth wave" arguably exists only in the analog domain (i.e. as generated within classic analog synthesizers such as the Moog "Minimoog"). There is no issue around hard bandlimiting per se with analog circuits,and as a result everyone tends to think of such waveforms as "simply" a pair of straight lines joined by a perfectly vertical one; but any digital emulation is obliged to respect the Nyquist limit; which means among other things disallowing hard discontinuities. The OP is (to avoid music synthesis jargon which is clearly totally unfamiliar to some people here!) generating a phasor at audio rates, with the period set by the increment, and the resulting values are sent directly to the DAC. So he is "listening to a phasor", while ~thinking of it~ as a sawtooth waveform. Clearly, at the wraparound point there is a hard discontinuity which manifestly does not respect Nyquist, so ~of course~ there is ("in effect") aliasing - becoming increasingly obvious as the frequency is increased. Indeed, this method is close to canonical for audio dsp folk as a way of demonstrating aliasing within digital audio synthesis, en route to explaining why so much effort (and CPU load) is devoted to achieving truly bandlimited synthesis while retaining as much of the sawtooth (or whatever) shape as possible, and still supporting frequency modulation by LFOs (e.g. for vibrato). The latter makes things that bit more nasty, as the high harmonics cannot drop out suddenly, they need to fade in/out, or we will hear little discontinuities; the ear being remarkably sensitive to such things. Put at it's simplest - while we want to imagine that the sawtooth wave is preserved over the range, clearly once the frequency is above 1/4 of the sampling rate, the only waveform it can have without aliasing is one which translates as a sinusoid. And needless to say, we want at least the amplitude to be constant whether there is one harmonic or 200. That same stream of numbers could alternatively be used as the index values into a lookup table containing a cycle of a sinewave, or anything else for that matter, even a sound sample ("wavetable synthesis"). Then, you get different problems - amounts of noise arising from truncated lookup etc; and possibly aliasing as well. All in all, a lot of nasty little problems which make "ideal" digital synthesis of geometric waveforms far more difficult than we would wish it to be. In music circles, "ideal" synthesis of a sawtooth or similar classic "analog" geometric wave requires additive synthesis, where as the fundamental frequency increases the number of active oscillators neccessarily reduces until at the upper limit only one remains "on". Of course, it is costly, and all other methods strive to achieve (more or less) the same result more cheaply. Richard Dobson
On Wed, 24 Sep 2008 18:40:56 -0500, jim <".sjedgingN0sp"@m@mwt.net>
wrote:

> > > >> > >> >That may or may not be its way too abstract for me to tell. I can't even begin >> >to attach useful meaning to the statement "he took an ideal sawtooth wave". Did >> >he visit an ideal hardware store? >> > The logic that he designed produces a wave form whose frequency can be >> >controlled in a simple way. As long as he just sets the desired frequency he has >> >no problem with artifacts appearing. It is only when he does something >> >non-linear like sweeping the frequency that he hears a problem. >> > >> >> Almost - when the system is producing a high frequency sawtooth (5KHz >> to 10KHz), if I stop the sweep, I am still able to hear inharmonic >> partials. At lower frequencies, because the harmonics that fall above >> Nyquist are quite low in amplitude, these effects are not perceived. > > >Well then you need to get your story straight. Here is what you wrote earlier > >"The siren effect is apparent _only_ while the fundamental frequency of >the sawtooth is actively changing, not while it is constant." > >You even emphasized "only".
Sorry, what I was trying to make clear is that the siren, as in a changing frequency, is apparent only while sweeping the sawtooth and that there is no siren effect when the frequency is static. While static, the effect is an inharmonic partial, not a siren. The aliasing produces the inharmonic partial(s) and when the sawtooth is swept the alias produced inharmonic partials also change to make what I called a siren effect.
> > Your set up should be band-limited as long as you keep the increment value >below half the size of the register (2^16?). As long as you keep the number of >samples per period to >2 it is bandlimited. At your sample rate you probably >aren't even going to hear anything unless you have at least 15-20 samples per >period as your Nyquist rate is way above what you can hear. > When the frequency is not changing there is no reason for any aliasing to occur >so it now sounds like what you think your wave generator is doing is not really >what it's doing. That is something is not working like you think it is. > > If it were working properly and the frequency is not changing you should get a >note that sounds something like a tinny oboe. > >-jim > > >----== Posted via Pronews.Com - Unlimited-Unrestricted-Secure Usenet News==---- >http://www.pronews.com The #1 Newsgroup Service in the World! >100,000 Newsgroups >---= - Total Privacy via Encryption =---
On Sep 24, 6:52&#4294967295;pm, no.s...@gte.net (Scott Gravenhorst) wrote:
  ...

> The experiment setup uses a stereo DAC, one channel outputs the raw > sawtooth, the other channel outputs the filtered signal (filtered > meaning upsample 2:1 to an 8 pole chebyshev filter .5% ripple to a > decimater 1:2). &#4294967295;I can hear the aliases in both channels. &#4294967295;I know why > the raw one aliases, I would have thought the filtered one would have > reduced that somewhat. &#4294967295;From other posts, I'm coming to understand > that firstly, my 2:1 upsampling is not enough. &#4294967295;Or I could simply > clock the waveform generation much faster, lowpass filter and then > decimate back to my DAC's output sample rate.
Rarely have I seen so much blather and misinformation here in comp.dsp. You need at least the 7th harmonic to synthesize a passable sawtooth and 11 or so for a decent one. With a sample rate of 44.1 Khz, any frequency above 11 KHz can be no more complex than a pure sine, and a good sawtooth can be no higher than 1 KHz. This irrespective of the method used to generate it. As for generating it, upsampling by two is entirely inadequate. Sixteen would be more like it. Jerry P.S. Dithering will make at most a barely audible difference, probably none at all.
Richard Dobson  <richarddobson@blueyonder.co.uk> wrote:

>An "ideal sawtooth wave" arguably exists only in the analog domain >(i.e. as generated within classic analog synthesizers such as the Moog >"Minimoog"). There is no issue around hard bandlimiting per se with >analog circuits,and as a result everyone tends to think of such >waveforms as "simply" a pair of straight lines joined by a perfectly >vertical one; but any digital emulation is obliged to respect the >Nyquist limit; which means among other things disallowing hard >discontinuities.
>The OP is (to avoid music synthesis jargon which is clearly totally >unfamiliar to some people here!) generating a phasor at audio rates, >with the period set by the increment, and the resulting values are sent >directly to the DAC. So he is "listening to a phasor", while ~thinking >of it~ as a sawtooth waveform. Clearly, at the wraparound point there is >a hard discontinuity which manifestly does not respect Nyquist, so ~of >course~ there is ("in effect") aliasing - becoming increasingly obvious >as the frequency is increased. Indeed, this method is close to >canonical for audio dsp folk as a way of demonstrating aliasing within > digital audio synthesis, en route to explaining why so much effort >(and CPU load) is devoted to achieving truly bandlimited synthesis >while retaining as much of the sawtooth (or whatever) shape as possible, >and still supporting frequency modulation by LFOs (e.g. for vibrato). >The latter makes things that bit more nasty, as the high harmonics >cannot drop out suddenly, they need to fade in/out, or we will hear >little discontinuities; the ear being remarkably sensitive to such things. > >Put at it's simplest - while we want to imagine that the sawtooth wave >is preserved over the range, clearly once the frequency is above 1/4 >of the sampling rate, the only waveform it can have without aliasing is >one which translates as a sinusoid. And needless to say, we want at >least the amplitude to be constant whether there is one harmonic or 200.
>That same stream of numbers could alternatively be used as the index >values into a lookup table containing a cycle of a sinewave, or anything >else for that matter, even a sound sample ("wavetable synthesis"). Then, >you get different problems - amounts of noise arising from truncated >lookup etc; and possibly aliasing as well. All in all, a lot of nasty >little problems which make "ideal" digital synthesis of geometric >waveforms far more difficult than we would wish it to be.
>In music circles, "ideal" synthesis of a sawtooth or similar classic >"analog" geometric wave requires additive synthesis, where as the >fundamental frequency increases the number of active oscillators >neccessarily reduces until at the upper limit only one remains "on". >Of course, it is costly, and all other methods strive to achieve (more >or less) the same result more cheaply.
Richard, thanks for your insight. Coming from a digital audio (but not a electronic music) perspective, I have some difficulty seeing how the full additive synthesis could be really costly in a modern system, even a relatively cost-constrained system. Nor does the subtractive method of creating a very high sample rate version of the target waveform, and filtering it, seem too much of a problem. Maybe long ago these were daunting. Or maybe there are costs I'm not seeing; unsure. Steve
On Wed, 24 Sep 2008 21:16:02 -0700 (PDT), Jerry Avins <jya@ieee.org>
wrote:

>On Sep 24, 6:52&#4294967295;pm, no.s...@gte.net (Scott Gravenhorst) wrote: > ... > >> The experiment setup uses a stereo DAC, one channel outputs the raw >> sawtooth, the other channel outputs the filtered signal (filtered >> meaning upsample 2:1 to an 8 pole chebyshev filter .5% ripple to a >> decimater 1:2). &#4294967295;I can hear the aliases in both channels. &#4294967295;I know why >> the raw one aliases, I would have thought the filtered one would have >> reduced that somewhat. &#4294967295;From other posts, I'm coming to understand >> that firstly, my 2:1 upsampling is not enough. &#4294967295;Or I could simply >> clock the waveform generation much faster, lowpass filter and then >> decimate back to my DAC's output sample rate. > >Rarely have I seen so much blather and misinformation here in >comp.dsp. > >You need at least the 7th harmonic to synthesize a passable sawtooth >and 11 or so for a decent one. With a sample rate of 44.1 Khz, any >frequency above 11 KHz can be no more complex than a pure sine, and a >good sawtooth can be no higher than 1 KHz. This irrespective of the >method used to generate it. As for generating it, upsampling by two is >entirely inadequate. Sixteen would be more like it. > >Jerry > >P.S. Dithering will make at most a barely audible difference, probably >none at all.
One of the things I'm trying to get my head around through this discussion and relevant discussions is how generating the sawtooth at a higher sample rate and then bandlimiting is different than generating it at a bit lower frequency and then bandlimiting. What would be the difference between two sawtooth waveforms bandlimited to, e.g., 20kHz at the same sample rate, with one generated at 1MHz and one generated at 200kHz? Done correctly, I think, aliasing wouldn't come into play in either case. Eric Jacobsen Minister of Algorithms Abineau Communications http://www.ericjacobsen.org Blog: http://www.dsprelated.com/blogs-1/hf/Eric_Jacobsen.php
Eric Jacobsen  <eric.jacobsen@delete.ieee.org> wrote:

>On Wed, 24 Sep 2008 21:16:02 -0700 (PDT), Jerry Avins <jya@ieee.org>
>>Rarely have I seen so much blather and misinformation here in >>comp.dsp.
>>You need at least the 7th harmonic to synthesize a passable sawtooth >>and 11 or so for a decent one.
Well, that's a relative statement. "Passable" does not imply any particular number of harmonics.
>>With a sample rate of 44.1 Khz, any >>frequency above 11 KHz can be no more complex than a pure sine, and a >>good sawtooth can be no higher than 1 KHz. This irrespective of the >>method used to generate it. As for generating it, upsampling by two is >>entirely inadequate. Sixteen would be more like it.
>>P.S. Dithering will make at most a barely audible difference, probably >>none at all.
In this case dithering is not relevant; I did suggest it at an early stage of the conversation before more facts came out. This is just part of problem-solving.
>One of the things I'm trying to get my head around through this >discussion and relevant discussions is how generating the sawtooth at >a higher sample rate and then bandlimiting is different than >generating it at a bit lower frequency and then bandlimiting. What >would be the difference between two sawtooth waveforms bandlimited to, >e.g., 20kHz at the same sample rate, with one generated at 1MHz and >one generated at 200kHz?
>Done correctly, I think, aliasing wouldn't come into play in either >case.
Aliasing seems to be common terminology (in digital music) for the fact that the one generated at 200 Khz will have more energy at some inharmonic frequencies than the one which is generated at 1 Mhz and then filtered, a fact I think we can agree on. Steve
Steve Pope wrote:
..
> > Coming from a digital audio (but not a electronic music) perspective, > I have some difficulty seeing how the full additive synthesis could > be really costly in a modern system, even a relatively > cost-constrained system. Nor does the subtractive method of creating > a very high sample rate version of the target waveform, and filtering > it, seem too much of a problem. Maybe long ago these were > daunting. Or maybe there are costs I'm not seeing; unsure. >
It's costly because we want a lot of them. My own experiments indicate that for sufficiently "powerful" lf sawtooths, we can get by with 48 harmonics, but more is definitely better for those trouser-flapping and ear-challenging low frequencies. This is for one synth voice. Even today, commercial emulations of analog synths rarely get beyond 8-voice polyphony. We would like at least 64 voices (imagine using the sustain pedal on a piano and then playing a fast glissando). Of course there is a lot more to one note than just the waveform generation; we have filters, modulating oscillators (lfos), envelope generators and so on. We usually run at least two tone generators per voice (a classic analog sound, "pulse width modulation" (= square wave with variable duty cycle) is generated by summing two sawtooth waves with a variable phase offset between them). So we don't just want 96 harmonics, we want 6144 smoothly time-variable harmonics. We need to preserve the sawtooth (or triangle, square) shapes as at any time the performer/composer may want to modulate some tone with a sawtooth lfo to make a siren or sweep effect. We can easily use lookup tables containing a sine cycle, to generate our harmonics; but as we all know memory overheads are at least as expensive these days as computational ones. All those table lookups really slow things down. If we use direect computation, we find that we really cannot get away with single (32bit) precision, as over time the nominally tiny phase accumulation errors do accumulate, such that what starts as a clean-looking sawtooth transmogrifies after half an hour or so into some very different shape. Still sounds the same, but we want the shape too. The other sticking point for direct computation is that we need all copmponents to support time-varying frequency control, whether simply for pitchbend, or for effects. So even the simple quadrature iteration method give problems as we need to recalculate using a sin or cos call whenever the pitch changes - which in a no-compromise setup could be every sample (for classic musical FM synthesis, it ~has~ to be per sample). There are solutions using ffts; but not without problems, with fine time-variability (and latency) being among the more obvious ones. Table lookups remain popular as they do avoid a lot of problems (e.g. interpolating between wavetables containing different numbers of harmonics); but I am unaware of any offering high polyphony. So, one way or another, making digital quasi-analog synths with lots of voices is computationally demanding, and there is no obvious free lunch solution, or we would all be using it already! Richard Dobson

Eric Jacobsen wrote:
> > On Wed, 24 Sep 2008 21:16:02 -0700 (PDT), Jerry Avins <jya@ieee.org> > wrote: > > >On Sep 24, 6:52 pm, no.s...@gte.net (Scott Gravenhorst) wrote: > > ... > > > >> The experiment setup uses a stereo DAC, one channel outputs the raw > >> sawtooth, the other channel outputs the filtered signal (filtered > >> meaning upsample 2:1 to an 8 pole chebyshev filter .5% ripple to a > >> decimater 1:2). I can hear the aliases in both channels. I know why > >> the raw one aliases, I would have thought the filtered one would have > >> reduced that somewhat. From other posts, I'm coming to understand > >> that firstly, my 2:1 upsampling is not enough. Or I could simply > >> clock the waveform generation much faster, lowpass filter and then > >> decimate back to my DAC's output sample rate. > > > >Rarely have I seen so much blather and misinformation here in > >comp.dsp. > > > >You need at least the 7th harmonic to synthesize a passable sawtooth > >and 11 or so for a decent one. With a sample rate of 44.1 Khz, any > >frequency above 11 KHz can be no more complex than a pure sine, and a > >good sawtooth can be no higher than 1 KHz. This irrespective of the > >method used to generate it. As for generating it, upsampling by two is > >entirely inadequate. Sixteen would be more like it. > > > >Jerry > > > >P.S. Dithering will make at most a barely audible difference, probably > >none at all. > > One of the things I'm trying to get my head around through this > discussion and relevant discussions is how generating the sawtooth at > a higher sample rate and then bandlimiting is different than > generating it at a bit lower frequency and then bandlimiting. What > would be the difference between two sawtooth waveforms bandlimited to, > e.g., 20kHz at the same sample rate, with one generated at 1MHz and > one generated at 200kHz? > > Done correctly, I think, aliasing wouldn't come into play in either > case.
Absolutely Right. Even bandlimited to 20Khz generated at 41Khz should work fine as long as the frequency and amplitude of the tone are held static. It is only when they are not static that the advantages of higher sampling rates come into play. -jim ----== Posted via Pronews.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.pronews.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= - Total Privacy via Encryption =---

Scott Gravenhorst wrote:

> > Sorry, what I was trying to make clear is that the siren, as in a > changing frequency, is apparent only while sweeping the sawtooth and > that there is no siren effect when the frequency is static. While > static, the effect is an inharmonic partial, not a siren. The > aliasing produces the inharmonic partial(s) and when the sawtooth is > swept the alias produced inharmonic partials also change to make what > I called a siren effect.
There should be distortion when the tone is static. If you generate a 2Khz tone that should have about 100 samples per period at your sample rate. If your accumulator and DAC is 16 bits you should be able to get an analog output with a waveform that looks pretty much like sawtooth on an O-scope. -jim
> > > > > Your set up should be band-limited as long as you keep the increment value > >below half the size of the register (2^16?). As long as you keep the number of > >samples per period to >2 it is bandlimited. At your sample rate you probably > >aren't even going to hear anything unless you have at least 15-20 samples per > >period as your Nyquist rate is way above what you can hear. > > When the frequency is not changing there is no reason for any aliasing to occur > >so it now sounds like what you think your wave generator is doing is not really > >what it's doing. That is something is not working like you think it is. > > > > If it were working properly and the frequency is not changing you should get a > >note that sounds something like a tinny oboe. > > > >-jim > > > > > >----== Posted via Pronews.Com - Unlimited-Unrestricted-Secure Usenet News==---- > >http://www.pronews.com The #1 Newsgroup Service in the World! >100,000 Newsgroups > >---= - Total Privacy via Encryption =---
----== Posted via Pronews.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.pronews.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= - Total Privacy via Encryption =---
jim wrote:
> Martin Eisenberg wrote: >> jim wrote: >> >> > Sampling it at a higher rate and smoothing out those >> > kinks will help a little. But a better way IMO would be >> > to only change the rate at the beginning of a wave form. >> >> That is, at a waveform peak so that the first derivative will >> be continuous.
I should have written "at a critical point".
> Do you mean "so that the first difference will be constant" > There is no first dirivative it is a digital signal.
No, I mean the derivative of the formula Scott is sampling. Changing frequency at a zero crossing of the signal puts a step in the first derivative. Changing at a zero of the signal derivative, the step is only in the second derivative. That means the step's contribution to the noise floor, which gets sampled along with everything else, falls off at 18 dB/oct (and more at saddle points) instead of 12 dB/oct. Of course, the sawtooth Scott is currently testing with doesn't have any critical points. Martin -- Quidquid latine scriptum est, altum videtur.