Hacker News new | ask | show | jobs
by elromulous 1159 days ago
To add another misconception, the Nyquist frequency is a lower bound, below which you necessarily get aliasing. It doesn't say anything about whether said sampling rate is sufficient for reconstruction or whatever your intended use is.

E.g. sampling a 1hz signal at 2hz still doesn't tell you if the signal was a 1hz sin or a 1hz sawtooth (depending on how lucky or unlucky you are).

9 comments

That isn't really what is going on. If the signal doesn't contain any higher frequency information, the Nyquist limit establishes what you need to exactly reconstruct the signal. It is therefore sufficient for any use.

So your case, a 1hz sin doesn't contain any higher frequencies, and will be reconstructed perfectly. A 1hz sawtooth contains higher frequencies, and so is not.

I think what you are really getting into is that a signal with periodicity of, say 1hz, does not mean that the Nyquist limit is 1hz. Square waves and sawtooths are particularly obvious examples of this, because the sharp edges cannot be achieved without (very many) high frequency contributions.

Now you can avoid this by creating a different set of component functions and a different sense of "frequency" but that just pushes the problem around. Also, since you are doing non-standard things you need to explain it, especially if what you are using doens't form a proper basis.

Finally, of course this is all in the idea mathematical setting, in real world noise etc. also has to be taken into effect.

A 1Hz sawtooth contains frequencies above 1Hz.

It actually has frequency components that go out to infinity, so its impossible to perfectly reconstruct a sawtooth without knowing beforehand that its a sawtooth.

This is true for any signal with discontinuities (i.e. not "band-limited").

This is incorrect, though subtly, and for several different reasons:

1) It is completely possible to create a sawtooth wave that contains only a single frequency. However, you could also consider the wave to be an (infinite) sum of sinusoids at different frequencies. Both views are "correct", and which is more appropriate depends on the context.

2) Related to (1): natural (acoustic) sounds are almost always best considered as a sine series. While there are such sounds which are most easily described as a sawtooth, when you consider the physical/mechanical process by which they are formed, the sine series is a more obvious approach.

3) A digital 1Hz sinusoid can trivially contain no harmonics at all. However, the moment you attempt to convert this into an acoustic pressure wave, the nature of the physical world essentially guarantees that the acoustic pressure wave will have a series of harmonics going out far beyond the base frequency. Once you start actually moving things (like magnetic coils, speaker cones and air), it's more or less impossible to avoid generating harmonics. But since the original signal was genuinely a pure sine tone, it becomes a little tricky to decide what the correct way to describe this is.

At the "textbook"/"theory" level, the person you are replying to is not wrong. A sawtooth waveform has infinite harmonics. If you were going to be nitpicky (which your response was in that spirit), the best thing to have said (IMO) was that the high frequency harmonics are going to drop off and be below any sort of "noise floor" or sensitivity of the system and not matter anyways. Instead you wrote a bunch of stuff about sounds and pressure waves that I don't think had the effect you intended. I think you lost the plot somewhere along the way.
> A sawtooth waveform has infinite harmonics

This is only true if you consider the waveform to be a sine series. As I indicated, this is a perfectly legitimate way to think about a sawtooth (and indeed, it appears to be fundamentally how the human ear works too).

But a sawtooth waveform is also nothing more than a very sharp rise/drop in air pressure followed by a longer drop/rise, repeated over and over again.

If you want to synthesize a sawtooth wavefrom with analog equipment, then thinking of it as an (infinite) sine series makes sense, because that's how you will end up approximating the (perfect) sawtooth.

However, digital synthesis does not require this sort of conception at all, and can be constructed without any summing of a harmonic series.

Also, I find it assuming that in the comments of a post about nyquist, you would write

> a bunch of stuff about sounds and pressure waves that I don't think had the effect you intended. I think you lost the plot somewhere along the way.

What do you the plot is?

You can’t physically construct a speaker that makes a sawtooth wave. Its cone would need to change velocities from -n to +n or vice-versa instantaneously in order to generate the ‘teeth’ of your wave. The air particles you are moving would likewise need to instantly accelerate. That is a physical impossibility - these things have mass, accelerating them requires force, infinite acceleration requires infinite force.

Those physical constraints manifest as limits on the frequency of sinusoidal harmonics it is possible for you to put into the wave; for the medium to carry; and for you to physically detect at the other end.

Mathematicians don’t break functions down into sinusoidal harmonics because they like trig functions. They do it because they fundamentally are what’s happening.

> You can’t physically construct a speaker that makes a sawtooth wave.

This was my point (3), though you've added an additional set of reasons why it is particularly hard for shapes like a sawtooth.

> However, digital synthesis does not require this sort of conception at all, and can be constructed without any summing of a harmonic series.

Yes, but you also cannot just make something that goes from -1 to 1 and then wraps back to -1 again, in a discrete-time (sampled) world.

You will get aliasing, because at some point your harmonic series will have partials that are noticeably large and exceed the Nyquist frequency, which will fold back into the output signal's spectrum. And, wouldn't you know it, except for a few very precise frequencies, those aliases will be inharmonic as all hell.

Here's an example (headphone warning - excessively loud) from a daft idea I had to implement a "virtual analogue" synth on an Arduino. Yes, one of the 8-bit ones, that can't do arithmetic.

https://raw.githubusercontent.com/ErroneousBosh/slttblep/mas...

The first sweep is generated with bandlimiting disabled, and you can hear the "swoopy" noises as the aliases slide up and down. The second sweep has some bandlimiting applied by "bending" the points where the signal resets to roughly correspond to a weighted sinc filter, eliminating (most of) the partials above Nyquist.

It uses 16-bit arithmetic on 8-bit lookup tables, and is output through an 8-bit PWM abused as a DAC, so it's not super clean, but it is at least not grossly incorrect.

You cannot filter the synthesized partials that go past Nyquist out after the signal has been generated, because the damage has been done.

> However, digital synthesis does not require this sort of conception at all, and can be constructed without any summing of a harmonic series.

A naive sawtooth algorithm (linear rise from -1.0 to 1.0) will create aliasing and not be a true saw. You cannot filter out this aliasing unless you do this with extreme oversampling. Otherwise you need to synthesize the waveform in an alias-free (or alias minimizing) method.

There's quite a few ways to digitally synthesize a sawtooth, all with some compromise, but they're all based on sine summation theory.

One of the more common ways is to precalculate a table of single-cycle bandlimited waveforms for every 1/3 octave or so, and choose the nearest table index for a given note-frequency being played, and interpolate as needed. (It's essentially mipmapping).

> It is completely possible to create a sawtooth wave

For a loose definition of "wave". All of the math behind information theory and sampling signals assumes waves are sinusoids. It also happens that waves in nature behave like (dampened) sinusoids. It's a completely natural way to model them mathematically when one has no a prior knowledge of the source, which is what the comment above you is pointing out.

To recognize and then reconstruct a sawtooth with no a priori knowledge, you need to sample much higher than the frequency of the sawtooth. You can compress said information quite well if you have not only wavelets, but sawtooths in your encoding. I am no audio expert but I don't think codecs exploit sawtooths (sawteeth?) for compression because they sound unnatural (because they are).

Note that even digitally you can't create a perfect sawtooth wave because there is a fundamental quantization of time in digital systems. It's a question of, again, how fast you can alter voltages, i.e. a frequency, so you end up generating a step-like function, inescapably. Yeah, sure, you can switch digital systems at MHz or GHz, but still.

> All of the math behind information theory and sampling signals assumes waves are sinusoids

This isn't really true. The point about the sinusiods is mostly that the form a very convenient complete basis of a useful space of functions, hence the fourier expansion. This doesn't amount to an assumption about how the signals are generated, rather how they are represented. You could pick a different basis and you'd get a different representation, but as functions they are identical. By definition this applies equally to any signal in the class, however you generate it.

Where the shape of the underlying basis vectors does show up is in errors and estimation, e.g. the similar estimation error in fourier vs. Haar will show up as sinusoids or steps.

> To add another misconception, the Nyquist frequency is a lower bound, below which you necessarily get aliasing. It doesn't say anything about whether said sampling rate is sufficient for reconstruction or whatever your intended use is.

Yes, it does. The Nyquist criterion gives exactly the (minimum) sampling frequency you need for perfect reconstruction of a bandlimited signal.

> E.g. sampling a 1hz signal at 2hz still doesn't tell you if the signal was a 1hz sin or a 1hz sawtooth (depending on how lucky or unlucky you are).

A 1 Hz sawtooth is not a bandlimited signal, so the Nyquist theorem does not apply.

> It doesn't say anything about whether said sampling rate is sufficient for reconstruction or whatever your intended use is.

Formally, the Shannon-Nyquist theorem states that if you sample a band limited signal at twice its bandwidth, an ideal reconstruction filter can be used to perfectly reconstruct the input signal. There's some wiggle room over ideal sampling/filtering, but the point is that it tells you exactly what the input was, provided it was band limited.

The misconception I think you're having is that band width is not the period of a signal.

If you know the signal is periodic with known frequency/period, you can be clever and sample it at that that frequency +/- a small offset. The frequency spurs then will not fall on top of each other and you can "unwrap" them to give a more complete picture of the signal. In that way you could determine whether a signal with a known frequency of 1Hz is a sawtooth or sine.

Nyquist more or less says "If I you know nothing about the signal, by sampling at X Hz, you can determine what the signal looks like over a bandwidth of 0 Hz to X/2 Hz". If you have additional knowledge about the signal (eg. band limited, periodic or other) you can exceed those limits.

It can also be looked at from an information viewpoint. Nyquist says "if you sample a signal at a certain rate you will get a certain amount of new information about it". You might "spend" this information by saying something about the signal over the band DC-f/2, or you might choose to say something about the signal over a different band of frequencies. In the example above we chose to say something about a set of discrete harmonic frequencies over a very wide bandwidth, ignoring the frequencies in between the harmonics as the 1Hz constraint told us they will be zero.

What is the point of adding a misconception?

The conception of the theorem is that if the signal being sampled is sufficiently integrable AND bandlimited AND the signal is uniformly sampled at at least the Nyquist rate over all time/space THEN then reconstruction of the bandlimited signal is exactly possible using the sinc interpolator. The proof is covered in "Shannon's original proof" in the Wikipedia article and most books on signal analysis such as Gaskill's Linear System book. Most EE people will have to do the proof as an intro course assignment in the first month of a DSP class.

OTOH, if you are not able to sample the function over all space or time AND the function happens to be periodic outside the interval you did sample THEN reconstruction of the bandlimited periodic signal is possible using the Dirchlet kernel.

If you are not able to sample the function overall space (from the first) AND that function is not periodic, you have small problems which occasionally become big problems if you are no careful. Most DSP books have a chapter about windowing discrete data and dealing with this conundrum. Basically, exact reconstruction is not guaranteed and context-specific techniques need to be employed to ensure desirable fidelity.

A 1hz sawtooth would not be band limited below 2hz
A low pass filter at 2hz would filter out the high frequencies contained in a sawtooth waveform, thus rendering a 1hz sine waveform.

To accurately sample a 1hz sawtooth waveform, you'd have to filter/sample at a much higher frequency.

Sampling a 1Hz sawtooth at 2Hz will alias.