Teh Internets are Teh Idiots

Kristin and I had a bet going about which was bigger (geographically): the U.S. or China.  Right now, the bet is still unresolved, as they appear to be closely-matched enough to produce different results depending on the calculation method and assumptions.  In the process of looking for a definitive answer, I stumbled upon this soul-crushing piece of flabberghast-inducing stupidity on the brain trust that is Yahoo Answers:

My favorite part is that the apparent justification for such an apparently obvious conclusion is “what are u talking about?”  And this is the best answer, deserving of thanks.

Well, if that doesn’t just revive your hope for the future of mankind, I don’t know what will.

Trotsky Drive Breadboard

After finally having some success with my “Mastodon Dave” guitar distortion pedal, I’ve been wanting to make a few more.  I’m continually amazed, however, at how many different electronics parts there are out there…  I’ve got coffee tins full, rubbermaid organizers full, and I STILL hardly ever have the parts on hand I need to make one of practically anything.  So I was looking around for a pedal circuit I could build without waiting around for parts to show up, and I found the Trotsky Drive.  After digging around to see what diodes I had, BINGO!  So tonight I threw it all together on the breadboard.

It sounds pretty good too, but it’s a little hummy – which I think is probably the breadboard.  A very simple circuit, but has a couple options for modding.  There’s a low-pass switch you can throw, and you can swap out the capacitor for different amounts of low-pass.  And you can mess with the kinds of diodes you use, and whatnot.  Fun project, with a Russian name, so I’m going to have fun painting this one.

Most of the trouble with this project was hacking through the various electronics components grab bags I bought to find the right parts.  The numbering schemes on the caps in particular are tricky.  I got a few that I think are caps, but I’m still not sure.  And how do I tell what kind a random diode is?  If I ever find out, I’ll let you know.

Anouncing Foodblog

I started a food blog called Foodblog!

Thyme Chicken

It’s a combination of show-offy pictures of food, recipes, discussion about cooking techniques, and food/diet/culture talk.  Sustainability and being healthy and all that hippie crap.

It’s a separate blog, so you want to follow it, you should subscribe to the Foodblog RSS feed in addition to this one.

My Workspace

My Workspace

This was my workspace on 2-5-2010. Click for a humongous version (1.9mb).

Items of note:

  • Ohm’s Law
  • Medicine Man balsa wood glider (half finished)
  • Make:Electronics book, Maker’s Notebook
  • Woolly Mammoth clone guitar pedal, nearly done
  • 2.5 gallon fishtank, testing out temperature logging via LM34 and Arduino (see FishApp) for more details.
  • There are no less than five computers on/around my desk. Not all are visible.
  • Small cheap telescope
  • Printing plate of some old ship
  • Guitars.
  • More guitars.

The mess?  Oh, that just means I’m getting work done.

Vonnegut Talks About Art

Some of my friends were trying to have an aesthetics discussion on twitter today. And I wanted to quote this bit from Kurt Vonnegut’s “Timequake” that I thought was rather applicable, but being as it was twitter, I couldn’t fit it in 140 characters, so I just made a snide comment instead. But I promised I would post the excerpt on my blog, so here it is. It’s a bit long, but it is very good.

So much for science, and how helpful it can be in these times of environmental calamities. Chernobyl is still hotter than a Hiroshima baby carriage. Our underarm deoderants have eaten holes in the ozone layer.
And just get a load of this: My big brother Bernie, who can’t draw for sour apples, and who at his most objectionable used to say he didn’t like paintings because they didn’t do anything, just hung there year after year, has this summer become an artist!
I shit you not! This Ph.D. physical chemist from MIT is now the poor man’s Jackson Pollock! He squoozles glurp of various colors and consistencies between two flat sheets of impermiable materials, such as windowpanes or bathroom tiles. The pulls them apart, et voila! This has nothing to do with his cancer. He didn’t know he had it yet, and the malignancy was in his lungs and not in his brain in any case. He was just farting around one day, a semi-retired old geezer without a wife to ask him what in the name of God he thought he was doing, et voila! Better late than never, that’s all I can say.
So he sent me some black-and-white Xeroxes of his squiggle miniatures, mostly dendritic forms, maybe trees or shrubs, maybe mushrooms o umbrellas full of holes, but really quite interesting. Like my ballroom dancing, they were acceptable. He has since sent me multicolored originals, which I like a lot.

The message he sent me along with the Xeroxes, though, wasn’t about unexpected happiness. It was an unreconstructed technocrat’s challenge to the artsy-fartsy, of which I was a prime exemplar. “Is this art or not?” he asked. He couldn’t have put that question so jeeringly fifty years ago, of course, before the founding of the first wholly American school of painting, Abstract Expressionism, and the deification in particular of Jack the Dripper, Jackson Pollock, who also couldn’t draw for sour apples.
Bernie said, too, that a very interesting scientific phenomenon was involved, having to do, he left me to guess, with how different glurps behave when squoozled this way and that, with nowhere to go but up or down or sideways. If the artsy-fartsy world had no use for his pictures, he seemed to imply, his pictures could still point the way to better lubricants or suntan lotions, or who knows what? The all-new Preparation-H!
He would not sign his pictures, he said, or admit publicly that he had made them, or describe how they were made. He plainly expected puffed-up critics to sweat bullets and excrete sizable chunks of masonry when trying to answer his cunningly innocent question: “Art or not?”

I was pleased to reply with an epistle which was frankly vengeful, since he and Father had screwed me out of a liberal arts college education: “Dear Brother: This is almost like telling you about the birds and the bees,” I began. “There are many good people who are beneficially stimulated by some, but not all, manmade arrangements of colors and shapes on flat surfaces, essentially nonsense.
“You yourself are gratified by some music, arrangements of noises, and again essentially nonsense. If I were to kick a bucket down the cellar stairs, and then say to you that the racket I had made was philosophically on par with The Magin Flute, this would not be the beginning of a long and upsetting debate. An utterly satisfactory and complete response on your part would be, ‘I like what Mozart did, and I hate what the bucket did.’
“Contemplating a purpoted work of art is a social activity. Either you have a rewarding time, or your don’t. You don’t have to say why afterward. You don’t have to say anything.
“You are a justly revered experimentalist, dear brother. If you really want to know whether your pictures are, as you say, ‘art or not,’ you must display them in a public place somewhere, and see if strangers like to look at them. That is the way the game is played. Let me know what happens.”

I went on: “People capable of liking some paintings or prints or whatever can rarely do so without knowing something about the artist. Again, the situation is social rather than scientific. Any work of art is half of a conversation between two human beings, and it helps a lot to know who is talking at you. Does he or she have a reputation for seriousness, for religiosity, for suffering, for concupiscence, for rebellion, for sincerity, for jokes?
“There are virtually no respected paintings made by persons about whom we know zilch. We can even surmise quite a bit about the lives of whoever did the paintings in the caverns underneath Lascaux, France.
“I dare to suggest that no picture can attract serious attention without a particular sort of human being attached to it in the viewer’s mind. If you are unwilling to claim credit for your pictures, and to say why you hoped others might find them worth examining, there goes the ball game.
“Pictures are famous for their humanness, and no for their pictureness.”

I went on: “There is also the matter of craftsmanship. Real picture-lovers like to play along, so to speak, to look closely at the surfaces, to see how the illusion was created. If you are unwilling to say how you made your pictures, there goes the ball game a second time.
“Good luck, and love as always,” I wrote. And I signed my name.

(From Vonnegut’s 1997 novel “Timequake,” which I kinda liked, even though it was kindof all over the place, because it occasionally contained some really good stuff like this. Please don’t sue me, owners of Vonnegut’s rights. Just trying to make conversation.)

This little bit does a fairly tidy job of responding to the volumes of stuff that has been written trying to pin down really specific definitions of what this crazy thing called art is. Coming from a technical background (with a little artistic goodness thrown in), my inclination was to try to come up with a really nice reductive definition of art (of course ignoring the social conversation going on). But good ol’ Kurt does a good job of making sense, as always.

Merry Christmas!

Robot Nativity

Merry Christmas, from me and my robots.

My thoughts on AMC’s Prisoner remake

Not Amusing.

You tell ‘em, McGoohan.

FishApp – Water Change Detection

The other day, I went to the mall with Kristin.  I usually finish up quicker than her, and this time being in possession of a shiny tiny netbook, I was able to code and tweak the water change detection algorithm for the FishApp while sitting on a bench outside of Macy’s.  I had a couple rather confused onlookers.  I may or may not be on a “do-not-fly” list now.

To refresh your memory, the FishApp keeps track of water changes, and gives you a graph showing weighted-age values for the water in your fish tank.  This requires you to pay attention while you’re doing the water change, and to log in to the website and report how much water you changed when.  Well, I want to have the FishApp sense, measure, and publish water changes for me.  To those ends, I designed a system that can measure the water level in the tank over time, report it to a computer, figure out when and how much water was changed, and report that back to the main fishapp web application.  The measurement is done using a Ping))) ultrasonic rangefinder, and data from that (and other sensors) is fed into a computer.

But just how is the computer supposed to figure out when a water change happened?  It’s input is just a string of numbers, and it’s gotta be smart enough to filter out random noise from tank cleanings, frisky fish, the water filter starting and stopping for one reason or another, or any of a hundred other situations.  What to do?

If you’ve read the last post about the FishApp, you know where to start – smooth out the data.  To recap, I have the sensor set to read the water level every half-second, and report it to the computer.  The raw data is pretty noisy:

but if we make new data points from the median of  every 20 samples, things smooth out pretty quickly:

The system should be able to handle this muuuch easier.

The algorithm works by keeping a queue of recent (smoothed) samples.  By comparing the oldest sample with the newest sample, you can get a “slope” value.   On the graph above, for example, it doesn’t take very many samples until the oldest will be just over 600 but the most recent will be around 800 or so, and you’ll have a large positive slope.  Once the algorithm sees this large positive slope (above a certain trigger value), it knows that a water change is beginning, and notes the water level beforehand.  At some point in the process of a water change, I start filing the tank up again, and we see a large negative slope (around 55-60 on the graph above).  The algorithm notes the capitulation and the minimum water level.  If the absolute value of the slope stays low enough for long enough, the algorithm detects a steady state, and calls it the end of the water change.  The “steps” you see on the graph are because I do my water changes bucket-by-bucket, but because the algorithm is using a slope from a queue maybe 10 samples long, it already does a pretty good job of smoothing these steps out, and not getting too confused.

After running the algorithm against the data above, it worked flawlessly.  Take a look at this graph:

The gray lines are where the important steps in the process were detected.  For example, the first gray line @ x=10 is where the algorithm first noticed we were emptying water out of the tank.  It looks late – and it is, but that’s merely a consequence of using a queue of 10 samples to generate the slope.  The actual “before” water level value it uses is not the one at the gray line, but the minimum one in the queue – which is correct (enough for rock and roll).  Then, at x=54, the algorithm detected a large negative slope and decided that we were filling the tank up again.  It started looking for the start of a steady state, which it found at x=121, and it stayed steady long enough that at x=150, the algorithm wrapped up and decided that we’ve done a water change.  NIFTY!

If you think about what is going on here, it’s really calculus, under the covers.  The slope value is the derivative of the function, and we look for the points that derivative changes sign.  But the function we’re using isn’t perfect, and isn’t continuous, and so we’ve got to build in a little extra wonkitude-resistance.  The algorithm has inputs for the size of the queue, the trigger value for large positive/negative slopes, a tolerance value to ignore noise during steady states, and the number of samples to go during a steady state before deciding we’re really done with the water change – so in theory, this algorithm could be adapted and tuned for a wide range of input sources with little-to-no modification.

Right now, the algorithm is coded in python, but I think it might even be possible to do the crunching on the Arduino.  If I did that and wired the Arduino up to an ethernet shield, I could ALMOST eliminate the computer altogether.  I still need the computer to run the webcam, however, so there’s no point in trying to run this code on the chip or anything like that.  But I think it would be possible in theory, if you don’t want the cam server running.

The Orange Monster

Orange Monster Wants to Believe

The watch is a  Seiko affectionately called the “Orange Monster.”  It’s a huge, loud, fun, heavy watch – and it makes me quite happy.  I also made and put up a giant X-Files “I Want To Believe” poster.  There are several different images for this poster floating around on the net, and much to my chagrin, it turns out it’s NOT the one that I see behind Mulder’s desk in the series.  Ah, well.

What A Water Change Looks Like to the FishApp

One of the goals of the FishApp is to have automatic water change detection available in phase 1. In order to do this, I have a Ping))) ultrasonic distance sensor pointed down at my fishtank. This little guy works by producing a sound above human hearing range, and listening for it to bounce back. If you know the speed of sound, you can calculate how far away the object was that caused the reflection. The sensor I am using is mounted above the tank in a piece of 1/4 inch wood to help shield it from the moisture, and samples the water level at predetermined intervals, sending its data over a serial connection to a host computer via an Arduino controller.

The host computer gets this stream of numbers, and has to have some way of determining when I’ve done a water change, and how much water I’ve changed. I got the feeling that random variation (noise) in the data from the sensor could throw off whatever method I use to compute all of this, so I needed to figure out exactly what the data looks like coming in to the computer, preferably saving it so I can test my algorithms against it without having to do a water change after each revision – that would be a heck of a lot worse than just waiting for the code to recompile.

So I fired up Arduino and Python did a water change, saving the raw data from the Ping))) sensor to a file. Without further ado, this is what a water change looks like to a computer:

Pretty cool, huh?  When I do a water change, I siphon water out of the tank into a 3 gallon bucket, and empty it a bucket at a time, until I’ve taken out as much as I like, and then I re-fill the think 3 gallons at a time.  You end up with the very visible “steps” on the graph.  While the data looks mostly consistent, you can see some wonkiness in some of the steps – which almost looks like thick lines.  The sensor isn’t quite reading the distance regularly in this case.  This looks to me like the kind of data which could really throw of my detection algorithm.  So I had the bright idea of taking a median of 5 samples for each data point and using that series for detection.  Here’s what a median-of-five graph looks like:

Median of Five Graph

Median of Five Graph

You should notice two things: 1) there are fewer datapoints by an order of five, because of the median, and 2) the curve is smoother.  I could prove this by computing the standard deviation on some of those trouble spots from above, but I don’t think it’s necessary: it’s plain to see when graphed.  The data could still be better though – look at the jaggies around 100.  We’ve got plenty of data, so we should be able to create a very smooth line and still have enough resolution to see each step, etc.

I’ll spare you all the gory details, but suffice it to say that the larger the median used, the better.  A median of 10 was better, but still not good.  A median of 15 was nearly perfect, but there was still just a little weirdness.  A median of 20 was perfect:

Median of 20 graph

Median of 20 graph

That’s more like it.  We’ve still got enough data there to see the water change in detail, but smoothed out all the ugliness that could throw off the computer.  Cool stuff.

More details on the detection algorithm’s implementation to follow.  Charts generated with my new favorite tool, Python.