Wednesday, March 26, 2008

Persistence, Part II

PoV Screenshot A few more words and details about the Persistence of Vision hack previously mentioned. Pictured at left is a screen-shot of the application in operation. The astute observer will note that there's enough room for at least 3 more columns to the right of the one on display, and may even wonder why I didn't incorporate that space as well. Honest truth is I did - but the switching time (based on navigating the object model behind the scenes) was painfully slow when the additional 18 cells were added to the process, enough so that the entire effect was rendered defunct (the speed required for movement to match the manifest processor lag was slow enough as to nullify the PoV phenomenon). While it may be possible via native code (sans-framework) and/or enhanced algorithms to achieve a sufficient switching rate, the refresh rate of the screen still poses problems.

The photos of the demo operation in the original article testify of this. Looking closely, there are a few instances where one of the 5 columns composing the virtual letter is absent even in the interior (not on the edge of either the wave or the letter). This demonstrates the mismatch between target refresh rate and screen draw/refresh. Also in that picture my fingers were being held such as to cover the battery/status bar visible at the top of the screenshot (although imperfectly, as evidenced by the tracer in the demo photo). All this griping and analysis is fine for diagnosing the problem, but doesn't do anything to improve chances for success other than defining a starting point. So...

Solutions
  • Full-screen draw available via native libraries (eliminates the battery/status bar)
  • Improved drawing routines (faster object navigation via native libraries, bitwise AND comparison to minimize number of addressed cells per call, etc.)
  • Automatic brightness control (demo was taken at half-brightness w/auto adjust turned on - sub-optimal test, and an error of omission on my part).
  • Processor and/or screen overclocking (don't know if this one is possible yet) OR tapping into hardware accelerated GL routines for performance
  • Not being so @#$& picky.

I'll state for the record here that I have satisfied my original curiosity in the exercise and do not anticipate investing the time to explore the above (or other) solutions. I'm willing to let this one die on the floor and move on to the next project(s) I have in mind, which may or may not eventually be disclosed here. Anybody interested in the source code to this point is welcome to contact me.

Friday, March 21, 2008

Persistence

Not too long ago I was fortunate enough to pick up an iPod Touch (bonus had come in from last year's work). The device has been remarkable, smaller than it looks and packing a nice little portable media punch. It also happens to be a fairly robust mobile computing platform, as evidenced by the strength of community development for the device even prior to the release of the official SDK. Being a developer myself, I was intrigued enough to give that part of it a shot.

Rather than put together an Intel hacintosh or risk the wrath of my wife by messing with her new Intel iMac (used for her wedding photography) as required to run the X Code IDE/SDK, I decided to use Jiggy's JavaScript based framework and IDE. While this surely introduces some functional limitations and performance overhead, it was also a very painless way to slap together a proof-of-concept to get a good idea of the problem space I was approaching.

Given that the device contains a set of accelerometers (used by the iPod/iPhone user interface to determine landscape and portrait layout), I thought it would lend itself well to a Persistence of Vision hack - which is to say, using a thin portion of the display, flash certain bits of it on and off as the device is shaken back and forth. The flashes correspond to certain spaces of the visual field during the swipe, and as a result of the mechanics of the human eye (which takes roughly 1/60 of a second to clear out the stimulus) appears to create many little spots floating in the air which can be used to write letters, display images, etc.

I first encountered the effect at a novelty store when I was about 9, when I saw a clock which consisted of a sturdy base and a spring-loaded wand which, when flicked, would flash it's LEDs as at waved back and forth and created the illusion of floating time. While several devices have picked up the gimmick since then, I've never actually bothered to own any of them. Now that the opportunity was right in front of me with a low barrier of entry, why not give it a shot?

PoV Space MathFirst came the math. Working with my wife we were able to determine that a good hand-wave average was roughly 16", making a full cycle (back and forth) every 1/2 second or so (11 over 5 seconds). In order to achieve sufficient resolution to be able to display any letter of the alphabet discernibly, while still keeping the overall number of cells sufficiently low (so as to have low logical and processing requirements) we chunked this 16" section into 6 letters per wave, with each letter broken into 5x6 segments. 6 letters per wave is pretty low, but the idea was to have a word persist only through a single wave - as soon as the accelerometer detected a significant shift in direction it would load the next word, allowing sentences to be spelled out sequentially.

( 6 letters * 5 columns = 30 columns ) / 16" / 0.25 sec (single wave phase) = 120 columns / 1 second, or 120hz switching. In order for a line to pass through 1/2" of space during the course of a single wave, it would need to be on for only 0.008333... seconds. That's for a perfect line - I would of course be switching a region rather than a mathematical construct, so I would in theory need to divide that 120th of a second by the width of the region in order to achieve the target resolution. I fudged this part, and for the sake of the proof-of-concept development decided to have the region correspond to the width of the column itself - 1/2" square, which means that if everything worked perfectly a total of 1" would be illuminated, a 1/2" of virtual overlap with itself (area of continual brightness) giving a linear fall-off to either side. So the letters would look a little fat and maybe just a touch blurry - but that's acceptable to start with.

However: most displays only refresh at a rate somewhere between 70-90hz. If I'm trying for 120hz it means that each cell would fall quickly out of sync, ending up only partially drawn or have some frames of display skipped altogether (compounded by the actual switching rate of the LCD). The second component of the problem is the brightness of the display itself - in order to sufficiently invoke that perceived persistence of stimulus, a certain intensity is required. If intensity is not available contrast may be substituted, but this means it will only ever work in a darkened environment.

Despite the math working against me I decided to give it a go. Setting the interior timer to 120hz is easy enough, but I suspect the time to navigate the DOM logic to the desired cells and switch their states runs slower than that anyway, plus whatever overhead the Jiggy framework required to assist in doing that. I set up the code to follow this plan, draw a column of cells and switch them over the course of fractional sections to the different mapped columns which comprised an entire letter table (in this case a letter is an array of 5 different numbers 0-63 which corresponds to a 6-bit binary display indicating which cells to turn on and off - makes for very tight book-keeping and rapid addressing, and binary logic is just fun anyway so why not?). My test consisted of letters A through E sequentially set up in memory in a per-wave array (all in a single wave) with events tacked to the accelerometer which would catch significant departures from one direction to the next and determine whether that array was being walked forward or backward, even capable of reversing mid-display.


PoV Wave Demo And it almost worked. In the end I had to simplify the display to at most 2 letters, and it only works if 1) the room is dark and 2) one covers the persistent battery-level display at the top of the screen (otherwise it wrecks the PoV effect). Photographing this is especially difficult when one is both the photographer and demonstrator, compounded by doing it in a dark bathroom shot "through the mirror" without being able to effectively test the composition. In the end I got a few good shots and many not-so-good - shown here are 2 images (ISO 80 f/2.0 @ 1/25 sec, the display simplified to just the letter 'A') combined and slightly enhanced for contrast. This shows the difficulty of keeping in sync with the animation - something that with enough tuning of the accelerometer event code and a steadier hand would become easier, but which I don't plan to pursue due to the aforementioned global limitations. The predicted linear fall-off is visible, as are the very slight gaps between vertical blocks on the display.

Overall I'm very pleased with the exercise: it taught me more about a really fun toy, gave me a chance to play with some simple science, and allowed math to Save the Day. Everything worked almost perfectly the first time and I come out richer in knowledge for the effort. The fact that any of this at all pleases me just reinforces the fact that I'm in the right line of work - I'm pretty sure most of the world would find this pretty dull. Hurray for geeks!

Wednesday, March 05, 2008

Not Dead

I ain't dead, or even disinterested. Just very very busy.

And happy. Much is going on, it's good, and active enough that several pending articles remain incomplete for now. I'll be back in a while.

Thursday, November 29, 2007

Samurai 3000-2007 Katana

It's that time of year again, when we have left-over pumpkin decorations in need of disposal.

This year I decided to make multiple successive passes through a single target - and had multiple targets to eliminate. I first selected the one decorated in the lovely "barren oak tree" motif by my wife, shown here next to the same sword as last year.



I made several test passes in front of the pumpkin before moving in with offensive strike no. 4, per the inset below (fig. 3). Traditional sword strikes with the katana are designed to target soft tissues with large blood vessels, bleeding out the opponent fairly quickly. The are not designed for militant action against insurgent squash.



I failed to bring my pass down into the body of the gourd, instead taking off a thin portion of skin on the upper right and the majority of the stem. The next two passes encountered more success, but revealed a disturbing trend: the lower I cut, the more I favored the no. 6 strike.

This could be considered natural - after all, for right-handed katana use the no. 1, 2, and 6 strikes are the strongest. One may also observe within this diagram that between the no. 4 (neck: carotid arteries) and no. 5 (abdominal wall, intestines, descending aorta) strikes there is no strictly lateral movement: the bones of the arms and ribs make the gesture futile. Thus, time is not spent attacking in that attitude at intervening elevations and the swordsman is likely to drift into more familiar territory instead.

Said pumpkin was also sitting on a wall composed of cement. The further one descends into the no. 6 position, the more likely they are to encounter this wall. I'm not sure if I was too focused on the target to notice, or incorrectly believed myself to have accounted for the obstacle and adjusted my swing accordingly. Whatever the case, the fourth pass met with an unsettling CLANG- twing- *THUNK* -clatter-clatter and I became well acquainted with the interior handle construction of my sword - the blade of which was lodged 25' (7.6m) to my left protruding from some plastic buckets near the sandbox (the edged still remarkably intact, only lightly dulled and still formidable).

The tang reduces until it's screwed into a weight which was then epoxied into the pommel. That mount provided the tension to keep the rest of the stack together, and that's it. Everything else up to the tsuba/hand guard is cylindrically hollow allowing free movement - which may have done well to absorb shock, but drastically reduced strength and stability.

Well illustrated in the lower inset is the abysmal tang itself, measuring less than a ¼ the total blade width and breaking rather predictably exactly at that point.

I'm taking what's left of the blade and will mount that in the end of a bo staff for a home-built naginata. The handle remnants will probably be reassembled for use as a costume piece (snazzy lightsaber, or affixed to the scabbard as a non-functional safe-to-carry-anywhere traditional blade). The real difficulty will be convincing my wife to let me cut anything in the yard ever again.

Monday, November 26, 2007

Finger Kata

I can passably play the piano, which is to say that most of the time I sit down and attempt to sound competent on one I succeed. I started with limited lessons when I was nine (or thereabouts, I really don't recall), but didn't stick with it for more than a couple of months before realizing I just didn't have the patience for it on top of the trumpet. I continued to dabble since we had one in the house but refused to formalize the endeavor.

I stuck with brass instruments for the next several years until the continuing saga of braces (my teeth proudly displayed my recessive British heritage, requiring nine years of extensive orthodontics) curtailed the effort. This also put me into High School, where the physical limitations of the mitochondrial myopathy became dramatically apparent, and the social and familial stresses of the age/environment took their toll.

Exhausted, "misunderstood" (classic teen, eh?), and quite thoroughly frustrated, I approached the instrument differently: it became my release, a loud and dramatic voice of discontent, and from there eventually something a little more beautiful and less abrasive. No less dramatic though, I cite Tchaikovsky, Rachmaninoff, Chopin, John Williams and Enya as my primary musical influences in composition. If it wasn't dark, or over-the-top soulful (preferably both), I likely wasn't interested. I stuck with my own compositions or reverse-engineered (by ear) themes of the above named composers, increasing in technical proficiency as ambitions escalated.

A few select pieces by other artists came to my attention during this time, and were sufficiently complex that simply picking through it audiologically was not on option: I had to confront the sheet music.

Having played brass and sung for so long, deciphering a musical score was a straightforward process. However, I had only ever practiced this on the single lines corresponding to my instrument or part without ten fingers to keep track of. Learning piano music was hard. Eventually I made enough sense of things to commit the pieces to memory as patterns of sound and muscle movement and was able to discard the sheet music - I can, even now many years later still play these proficiently with very little warm up.

Fast forward to last Sunday, where I'd been asked to play a piece in church. The date had shifted a few times and now landed squarely behind a major point release and new client installation at work, tightly curtailing the amount of time to practice my piece. A new piece that I was still memorizing (sheet music continues to scare me). In the week and a half leading up to the performance where I could scratch together enough time to practice I did so until my back burned from the ram-rod straight posture and my fingers swelled and fingertips ached. I used every trick I know for rapid memorization, engaging as much of the brain as possible and going heavily synaesthetic (incidentally, part of the song smells like mustard, one passage feels like a piece of dry driftwood being pressed into sand before the glass and wire atop it sings, and I'm still not fully satisfied with the transition from the red-orange passage through the white/green bridge - but the folded steel and flash of yellow came out well). Finally I had it down.

Except for the nerves.

I can sing, dance, fight, or speak in front of groups and thrive on the adrenaline: but piano is still an intimate catharsis, and opening it up to share with others is a vulnerable and frightening act. My hands shook terribly throughout the performance, and tunnel vision threatened to turn the keys blue and started to ring in my ears. I played on, latching onto the coming landmarks at the beginning of each passage like life preservers. I did it too fast, made five huge mistakes, three of which affected the sound of the piece (I segued through the other two in-key), with one requiring me to stop, pause and assess, and then resume. My struggle was obvious to the audience of about 400, but in a church setting this is a supportive and understanding group in addition to being small. I am not satisfied with what I gave them - it was not as well as I had practiced.

It took me a few days to shake out of the experience as well: that much adrenaline and the feel of failure brought back many unpleasant memories from childhood and adolescence. I can forcefully re-route my response into a positive, "points for trying" or "good enough" take but I'd rather not: that's cheating. Synthetic happiness is not un-genuine, but it can certainly be counter-productive: I'm planning on beating this thing. First by practicing that particular piece well enough that I can get it by heart instead of by head - hopefully more resistant to the influences of the moment, or at least a more deeply ingrained headspace for me to get into. Secondly, by finding a way to conquer the nerves and be able to play as though in private - I should have taken some time in the couple of days prior to set up some post-hypnotic suggestions to help induce that, but didn't. I'll start there and then try to integrate the sensitivities into a more regular comprehensive pattern instead of having to pull a dissociative sleight-of-hand every time I want to play.

I'm glad I did it - everyone should get scared once in a while and be forced to evaluate themselves honestly from the perspective of the unfamiliar. 'Builds character.