DSPRelated.com
Forums

Anti Aliasing of Arbitrary Waveforms

Started by Scott Gravenhorst September 23, 2008
Eric Jacobsen <eric.jacobsen@ieee.org> writes:

> On Thu, 25 Sep 2008 09:43:57 -0400, Randy Yates <yates@ieee.org> > wrote: > >>Eric Jacobsen <eric.jacobsen@ieee.org> writes: >>> [...] >>> 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. >> >>I think it does, but I can't prove it right now. >> >>The notion is that the nonlinear function is applied as though the >>signal was analog, so it generates harmonics. > > By "nonlinear function" do you just mean sampling?
Hey Eric, No. Amplitude quantization is definitely nonlinear, but that's not the nonlinearity I was talking about. What I meant was any nonlinear function applied to the signal in the digital domain. A simple example would be the function y[n] = x[n], |x[n]| < A, A, otherwise. Note that the input to this function is digital and the output is digital (and the output sample rate is the same as the input sample rate). The notion I mentioned previously is that it is AS IF x[n] was first converted to an analog x(t), the nonlinearity function y(t) = x(t), |x(t)| < A, A, otherwise, applied in the ANALOG domain, and then y(t) sampled WITHOUT the use of an antialiasing filter to y[n]. Notice that X(f) = F[x(t)] should be zero at f > Fs / 2, but no such guarantee occurs for y(t). It is the abrupt rollover of the phase accumulator that is the nonlinearity in the case of the OP. That is, you could model the signal generator as having an initial ramp function x[n] = a*n that is input to the nonlinearity x[n] = a*n mod A, where x[n] mod A = x[n] - (floor(n/N) * A). (I think I got that right...) -- % Randy Yates % "Remember the good old 1980's, when %% Fuquay-Varina, NC % things were so uncomplicated?" %%% 919-577-9882 % 'Ticket To The Moon' %%%% <yates@ieee.org> % *Time*, Electric Light Orchestra http://www.digitalsignallabs.com
Scott Gravenhorst <no.spam@gte.net> wrote:

>On Thu, 25 Sep 2008 09:43:57 -0400, Randy Yates <yates@ieee.org> >wrote:
>>Eric Jacobsen <eric.jacobsen@ieee.org> writes:
>>> 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.
>>I think it does, but I can't prove it right now. >> >>The notion is that the nonlinear function is applied as though the >>signal was analog, so it generates harmonics. If the sample rate isn't >>high enough, many of those harmonics alias back into the Nyquist >>bandwidth. If the sample rate is higher, the harmonics are properly >>represented up to the Nyquist frequency, THEN start aliasing back in, >>and since most harmonics decrease with increasing frequency, much less >>energy gets aliased back in at this higher sample rate. >> >>Then when you filter and decimate back to the original sample rate, the >>properly-generated harmonics are filtered out and the residual aliased >>energy is much lower than if you hadn't upsampled. >> >>Does that make sense?
>That is how I understand it. As was already pointed out, I need to >seriously increase my upsampling (or simply generate my arbitrary >waveform at a much higher sample rate than my DAC's).
It would be good to understand why these two are not equivalent. Steve
Jerry Avins wrote:
(snip)

> Quite so, but where in a sawtooth is the derivative zero?
Right at the tips, both top and bottom. That is, in between the parts with positive derivative and negative derivative. -- glen
Jerry Avins wrote:
(snip)

> P.S. Dithering will make at most a barely audible difference, probably > none at all.
originally I thought it might be in eight bits or so. I believe it was later indicated to be 24 bits. -- glen
Eric Jacobsen wrote:
(snip)

> If you're right, you should be able to see it in the output waveform > with the Oscope. Aliasing is a distortion, it changes the output > waveform from what it's supposed to be to something else. If you can > hear it, there's a good chance you'll see it on the scope. Being > able to see the nature of the change could go a long ways toward > understanding where it's coming from and confirming whether it's > really aliasing (and how bad and what you might be able to do about > it), or some other effect.
As far as I know, you won't be able to see much. Many distorted waveforms will sound pretty much the same, and many that look about the same will sound very different. Among others, the ear is fairly (but not completely) insensitive to phase in the harmonics, but the waveform can look very different. Without a reference sine to look at, I doubt most people can recognize a fairly large amount of third harmonic added to a sine. Even harmonics will be much easier to recognize in the asymmetry of the result.
> Since your desired waveform is a simple sawtooth, it should be pretty > easy to see distortions. If there are distortions such as ringing, > etc., the scope will help to measure the period of the ringing and > help analyze whether it's really aliasing or a filter effect or > something else.
-- glen
jim wrote:
(snip, I wrote)

>>Consider that he took an ideal sawtooth wave,
> He explained what he is doing, He has no ideal sawtooth. He has a register that > gets incremented every time the the clock strikes and then when it overflows it > starts over.
Yes. But a band-limited sawtooth won't look like that.
>>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.
> 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? It seems to be obvious to you that incrementing a register until it overflows generates a sawtooth. Why is that so obvious? A properly band limited sawtooth won't have equal increments.
> 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.
No, artifacts are already there at constant frequency. New ones will appear from the sweep, but for sufficiently slow sweep they should be pretty much inaudible. It shouldn't be hard to calculate the appropriate sampled values for a band limited sawtooth. Take the Fourier series terms less than Fs/2, calculate the appropriate sampled values. -- glen
glen herrmannsfeldt wrote:
> Jerry Avins wrote: > (snip) > >> Quite so, but where in a sawtooth is the derivative zero? > > Right at the tips, both top and bottom. > > That is, in between the parts with positive derivative > and negative derivative.
If a derivative doesn't have the same value when approaching a point with decreasing and increasing X, it doesn't exist at that point. That's a functional definition of a cusp. Still, that's a nice place to change the period. You can't always get the sweep rate you want that way, or even a constant sweep rate. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295; ** Posted from http://www.teranews.com **

glen herrmannsfeldt wrote:
> > jim wrote: > (snip, I wrote) > > >>Consider that he took an ideal sawtooth wave, > > > He explained what he is doing, He has no ideal sawtooth. He has a register that > > gets incremented every time the the clock strikes and then when it overflows it > > starts over. > > Yes. But a band-limited sawtooth won't look like that.
OK now I see what the problem is. There is a very simple way to avoid aliasing just don't think of this as sampling a ideal sawtooth. That is clearly what is causing the problem. What he needs to do to avoid aliasing is just start every ramp cycle at the same value. Of course that destroys the analogy to sampling an ideal function but so what? who cares? It will eliminate the aliasing and it is simple to implement. Ultimately, he is going to have to do this anyway if he wants to adjust the volume of his tone. Presumably he doesn't want it to always be full volume.
> > >>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. > > > 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? >
> It seems to be obvious to you that incrementing a register until it > overflows generates a sawtooth. Why is that so obvious? > A properly band limited sawtooth won't have equal increments.
Right if you put yourself into that mental straight jacket you arrive at that conclusion. A waveform with equal increments can be bandlimited. If he starts each wave at a different value then yes that will produce artifacts that aren't harmonic. Under his current implementation, if his increment is a power of 2 then each and every waveform is identical - surely you can see that will only produce harmonic of the fundamental? And it will be a sawtooth. If he does it that way it will quantize the fundamental tone frequencies he has available. but there still should be thousands of available frequencies.
> > > 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. > > No, artifacts are already there at constant frequency.
Not if he resets the register and starts each ramp at the same value.
> New ones will > appear from the sweep, but for sufficiently slow sweep they should > be pretty much inaudible.
Ultimately I think he is going to have to come up with a scheme that determines the initial value and the increment value for each waveform and have those two control values change slowly and smoothly in order to modify frequency and amplitude dynamically. That will address the issues better than brute force method of oversampling by a whole bunch. If he is working with 32 bit registers he should easily be able to get close enough to any ideal amplitude and frequencies he needs -so close that no one will be able to tell the difference. -jim
> > It shouldn't be hard to calculate the appropriate sampled values > for a band limited sawtooth. Take the Fourier series terms less > than Fs/2, calculate the appropriate sampled values.
But then he isn't incrementing a register. ----== 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 =---
Do we know yet what the output waveform looks like? I like Eric's
advice about using a 'scope. Do we know the nature of the DAC being
used? The OP mentions stereo - (others have mentioned this but) the
DAC in an _audio codec_ will be unable to generate a sharp
discontinuity and will very likely produce quite pronounced ringing.
Some audio codecs upsample internally and implement a fairly sharp
cutoff reconstruction filter digitally - this will give the
aforementioned ringing if driven by a massive discontinuity (as is
being generated here). In some codecs it is possible for this ringing
to overflow/wraparound within its digital reconstruction filter
circuitry and to cause unexpected results even if the input data
remains within (it can't do otherwise!) the range implied by the
number of bits representing it. If you drive the type of codec I'm
thinking of (assume 16-bit) with data sequence 0, 1, 2, ..., 65533,
65534, 65535, 0, 1, 2, ... then the amplitude of the ringing aound the
large discontinuity may extend well beyond the 0 to 65535 range and
the digital filter circuitry producing it may overflow.
On Sep 24, 7:46&#4294967295;pm, Eric Jacobsen <eric.jacob...@ieee.org> wrote:
> On Wed, 24 Sep 2008 22:52:16 GMT, no.s...@gte.net (Scott Gravenhorst) > wrote: > > > > > > >On Wed, 24 Sep 2008 15:16:00 -0700, Eric Jacobsen > ><eric.jacob...@ieee.org> wrote: > > >>On Wed, 24 Sep 2008 17:45:21 GMT, no.s...@gte.net (Scott Gravenhorst) > >>wrote: > > >>>On Wed, 24 Sep 2008 09:49:22 -0700, Eric Jacobsen > >>><eric.jacob...@ieee.org> wrote: > > >>>>On Tue, 23 Sep 2008 17:35:02 GMT, no.s...@gte.net (Scott Gravenhorst) > >>>>wrote: > > >>>>>What are the common method(s) for preventing aliasing of arbitrary > >>>>>waveforms generated within a DSP application? &#4294967295;I understand that > >>>>>waveforms supplied as analog signals and presented to an ADC must > >>>>>first be lowpass filtered to remove harmonics above the Nyquist > >>>>>frequency, but what about generated waveforms? &#4294967295;I know about
I think the right answer for the OPs saw tooth case, is the OP needs to find the correct math function that generates the sawtooth in the digtial domain with an INHERENTLY BANDLIMITED output. If you use a phase accumulator it will have the aliasing or whatever you want to call it built in and it cannot be filtered out. As for the arbitrary waveform case, if these arbitrary waveforms are created in the digital domain, the same answer applies, the function has to be inherently bandlimited or there will be aliasing. Now I guess you can use very high oversampling so the alisasing that does occur (and falls back in the audibale range) is a very high harmonic number and therefore sufficently low in amplitude as to be acceptable. This is an intereting issue. Anytime you generate (or modify) a signal in the digital domain mathematically it is already sampled and you have no opportuninty to apply an anti-alias filter, so in order to avoid aliasing the math function itself must be somehow bandlimited. So how do you mathematically create an inherently bandlimited sawtooth for starters? Mark