Jan 13, 2014

Misleading representations of discrete-time signals

Many audio editor tools draw digitally sampled signals in ways that can be misleading or sometimes downright incorrect. I hope this post will be useful in explaining this recurring and confusing issue.

In Audacity, let's set the project sample rate to 48 kHz and generate a sinusoid tone at, say, 22.5 kHz. Using a tone near the Nyquist frequency and a high zoom level will make what I'm talking about quite apparent:

It appears as though our newly generated sinusoid is "pumping" or going up and down in amplitude! Of course this can't be true; it's just a pure sine wave and should be perfectly reconstructible as such, according to the sampling theorem. But what's happening here?

The problem lies in drawing straight lines between the samples (known as linear interpolation). This overlooks the fact that the original signal – in this case, coming from Audacity's signal generator – only contained frequencies below the Nyquist frequency. Such sharp corners would have been impossible.

A cleaner, more customary way of drawing discrete-time signals is shown below:

Here, only the samples are shown, and their order is discernible from the lines that connect them to the zero level. But we're not trying to claim anything about what's in between those samples (the value is actually undefined).

The "pumping" pattern we're still seeing emerges from the slowly changing phase difference between the sampling frequency and the signal; in other words, the sinusoid is being sampled at different points.

A more faithful representation of the signal can be obtained by low-pass filtering the waveform shown by Audacity – after resampling at a higher rate – using a 'brick-wall' cut-off at the Nyquist frequency. This is equivalent to sinc interpolation, and it's pretty close to what actually happens in the sound card when the signal is played back. We can immediately see how the weird dot pattern was formed:

Sinc interpolation is computationally more complex (slower) than linear interpolation, which is probably why it isn't used by Audacity and others. Some audio editors however, like Cool Edit, do use a better interpolation at high zoom levels.

See also my related post, Rendering PCM with simulated phosphor persistence.

(And since it's been linked so many times – a great episode of Digital Show & Tell explains this and a lot more about sampled signals.)

5 comments:

  1. Are the second and third pictures from Audacity? I was unable to make anything similar using Audacity's low pass filter.

    ReplyDelete
    Replies
    1. No, they are composite images. You would have to step up the sample rate first. The second picture is just a plot with similar colors.

      Delete
  2. As an additional mathematical note: The pumping sine wave would be
    sin(w t)*sin(W t)
    where w is the fundamental frequency (close to the sampling rate) and W is the pumping frequency. But this can be rewritten as
    1/2 (Cos((w-W) t) + Cos((w+W) t)).
    If the second term then is above the threshold of the low pass filter, the pumping sine equals the Cos((w-W) t) at the slightly shifted frequency up to stuff eaten by the band pass.

    ReplyDelete
  3. This is amazing! I found your page thru a link on Slashdot, where you decoded GPS data from a helicopter. That is so far above and beyond "Off the GEEK scale" that I just have to stand and applaud... loudly!! :D

    This all reminds me of some Cool Edit "decoding" I did a few years ago. Someone who was into Phone Phreaking liked to make recordings of "Wrong Number" messages from overseas in the 1970's. Back then, most of those calls were relayed via SW radio. One message he posted had a high-pitched "monkey chatter" signal, which I recognized as speech patterns. With a little sleuthing, I determined that it was a single sideband signal, and was exactly 4Khz above the audio. High pass filter, then "ring modulate" the remaining sound with a 4khz sinewave... the voice was a news feed, describing the death of Jim Jones! I e-mailed the guy who posted it, and he was flabbergasted. :) As geeky as this is, I think you've gone far above and beyond. I respectfully bow to the far superior Geek. :)

    ReplyDelete
  4. A bijou of a post. Thank you so much.

    Edward Carney
    Minnesota, U.S.A.

    ReplyDelete

To prevent spam, comments will only appear after moderation.