Mar 30, 2013

Rendering PCM with simulated phosphor persistence

When PCM waveforms and similar function plots are displayed on screen, computational speed is often preferred over beauty and information content. For example, Audacity only draws the local maximum envelope amplitude and (what appears to be) RMS power when zoomed out, and when zoomed in, displays a very straightforward linear interpolation between samples.

Here's the startup beep of my Kenwood TK-2302, rendered by Audacity:

Audacity waveform

Analogue oscilloscopes, on the other hand, do things differently. An electron beam scans a phosphor screen at a constant X velocity, lighting a dot everywhere it hits. The dot brightness is proportional to the time the electron beam was directed at it. Because the X speed of the beam is constant and the Y position is modulated by the waveform, brightness gives information about the local derivative of the function.

Of course, PCM is all about "dots" as well, so we could possibly mimic this behavior digitally. I'm going to simulate an electron beam by first oversampling the above waveform by an insane amount – at 1,099,961 Hz, to be exact. (It's a prime number as well, hopefully minimizing aliasing artifacts.) Downpass filtering follows, with a cutoff frequency at the Nyquist frequency of the original PCM. Now, a program reads in the processed PCM and for each sample will make the corresponding dot on the XY plane a little brighter. (Actually each sample will affect 4 image pixels because of bilinear interpolation.) This method gives us a much more interesting rendering:

Now how cool is that? It looks like an X-ray of the signal. We can see right away that the beep is roughly a square wave, because there's light on top and bottom of the oscillation envelope but mostly darkness in between. Minute changes in the harmonic content are also visible as interesting banding and ribbons.

At very high zoom, Audacity doesn't even bother reconstructing the actual waveform but just thinks of it as a "connect the dots" puzzle. This is computationally feasible, of course. Oversampling at 3,000,017 Hz and downpass filtering at the original Nyquist frequency, on the other hand, results in an apparent reconstruction of the analogue wave:

Wave closeup

Finally, the soprano section of the Finnish Radio Chamber Choir singing a D note in a piece by Einojuhani Rautavaara:

Relevant code for scientific interest in this Gist.

Update: The bit about prime resampling rates seems to be irrelevant. It was supposed to prevent the new sample rate from coinciding with a harmonic of the waveform, and producing a "dotted" result, or Moiré pattern. Such patterns emerged nevertheless. Perhaps adding Gaussian noise would work against this.

6 comments:

  1. That last one is pretty sweet!

    ReplyDelete
  2. so nice! Sometimes I still pull out an old analog spectrum from the 70ties as it's the only thing at the lab that's fast enough to show the "ghosts" of parametric oscillations etc.

    ReplyDelete
  3. This is visually just way to awesome !

    I read through your blog, and only now realized that the aweseome modem sound poster was done by you. I hope you know you made a lot of people very happy for half an hour.

    ReplyDelete
  4. Since Audacity is Open Source, have you considered letting the developers know about these *AWESOME* ideas? Having been a Geek since I could walk, ;) I am VERY familiar with the unique and very revealing characteristics of oscilloscope displays. Having an OPTION to select such a display in Audacity would be totally awesome! I'd gladly sacrifice some computing speed to get O'Scope-like renderings like this! However, I don't use Audacity, I use Cool Edit 2000. (I paid for it, and by golly, I am going to use it until the bits wear out!) ;) If they added this feature to Audacity, I'd install it JUST FOR THAT! :)

    ReplyDelete
  5. I've also looked into this a bit. I wrote a simple cairo-based program that can do sinc interpolation and phosphorus-like waveform rendering based on the (estimated) derivative of the signal. https://bel.fi/alankila/test.png is my current result. It is missing gamma correction so it looks a bit poor at this moment.

    ReplyDelete
    Replies
    1. Adding to below: the test.png file has now been updated with gamma corrected rendering using 12 bits per pixel resolution.

      Delete

To prevent spam, comments will only appear after moderation.