Saturday, April 4, 2015

Satellite tracking with telescope

So after years of trying to get a video of the International Space Station, we finally did it! Here's the result:

This video is centered by using a weighted-average of the following video:

So how do you get a video like that? Well here's what the setup looked like a few minutes before ISS passed overhead! A telescope, some computers, in a parking lot 10 meters from our front door.

Here's a schematic diagram of the setup:

How does it work? Well, you need a telescope and a camera. A classic orange Celestron C8 (30+ years old) and a Celestron NexImage webcam get the job done. It helps to have a Telrad to center the telescope on moving targets. This is all you really need! Oh, maybe a broomstick to manually slew the telescope to ISS.

If you want automated tracking, then things get a bit more tricky. From this point on, everything is custom. For the guidescope, a Logitech webcam that has the lenses removed is attached via some Thorlabs optics to a 150mm lens. So the light coming from infinite distance (ISS is pretty far away) is focused onto the detector at a distance of 150mm. The webcam is held onto the optics with packing tape.

A custom guidescope: a Logitech webcam with lenses and case removed attached via Thorlabs optics to a 150mm lens

The guidescope sends low resolution images over a relatively large field of view, and because it's a small 25.4mm diameter lens, the amount of light collected is pretty low so it can only track bright objects such as planets, bright stars, or ISS. The guidescope is connected to a Gateway laptop that is running Labview software. The Labview software finds the coordinates of the brightest object in the image using a simple algorithm: weighted mean of all pixels above a user-defined threshold. The user also inputs desired coordinates. So there's a deltaX and a deltaY of coordinates which are used to control the Right Ascension (RA) and Declination (D) velocities. The user-defined X and Y are set to line up such that the satellite is in frame on the imaging webcam. Here's a video of the setup tracking Jupiter (before alignment of 3 axes):

At the end of the video you can see the Telrad pretty close to aligned with Jupiter!

Here it is after alignment of all 3 axes, and you can see Jupiter in the main imaging webcam.

To control the telescope, Labview sends commands via ASCOM Telescope MoveAxis rate commands. So we are updating the desired RA and D rates. These commands are sent via a USB to serial port to the Celestron Advanced GT mount hand controller. Here's a screen shot of the custom tracking software GUI:
Labview GUI screenshot

This is where it's refreshing that blogs are not peer reviewed. The following works, but I don't know why! I don't know exactly how to solve the control system for this telescope. If someone has ideas for this, please let me know. Attached is my best guess for what I'm doing, but I haven't solved it using Laplace transforms or anything like that due to the mysterious motor controller black box. Perhaps someone has a good model for how the motor controller and physical response of telescope?  The factor of 1/cos(D) is because as the declination approaches the polar axis (D=90 degrees), the RA becomes less and less sensitive. In fact, at D=90 degrees, moving RA only rotates the image, it does not actually move laterally!

It would be nice if Celestron or ASCOM allowed us to control the current (in Amps) directly to the motor. Any insight here would be appreciated! But the bottom line is that despite the uncertainty in why exactly it works, it does in fact work!

Warmup schedule

2 weeks before ISS pass:

2 days before ISS pass:

2 hours before:

  • start up laptop, check software (Labview has a tendency to crash randomly!)
  • bring telescope outside, set up telescope mount such that highest point of transit is perpendicular to polar axis of equatorial mount. So the perpendicular-to-equatorial plane should intersect the highest point of the transit. We want the highest point of the trajectory at declination = 0 degrees to get highest sensitivity on our motors.
  • Align 3 axes: Telrad, guidescope, main telescope
  • Focus main tube on bright object (moon, jupiter, bright star). 
  • check that telescope can slew over entire predicted trajectory (or as much as possible)

2 min before

  • switch to manual mode, use XBox controller to move around, get familiar with up/down, control, etc
  • start scanning the sky for ISS 

During ISS pass

  • use Xbox controller and Telrad to point telescope at moving target
  • once ISS is in the center of the Telrad and velocity is approximately correct, press "A" button to enable automatic tracking
    • if program "locks on" then great!
    • if program loses lock, then press "B" to enable manual mode and try again
  • Use Sharpcap running on second laptop to save video file from Celestron Neximage webcam, adjust exposure using Philips webcam control driver

1 minute after

90% of the time: Curse and cry due to fog on lens, algorithm error, incorrect alignment of axes, clouds, car driving by, etc etc.

10% of the time: PARTY!

1 hour after

Postprocessing of AVI file in Matlab (cropped to weighted centroid). No color adjustements, etc, performed.

Any comments or questions definitely welcome!


Oom Hank Verwest and late Aunt Barbara Verwest for kindly giving me the Celestron C8 telescope tube.

Tim Long and Rick Burke of ASCOM for posting useful information online

Thierry Legault's websiteRalf van de BerghSylvain Weiller and Atroguyz for inspiration

Thanks to my girlfriend Fernanda for spotting ISS, but mostly for keeping me company through all the failed attempts at capturing ISS :)

Sunday, June 15, 2014

How does World Cup Spray work?

World Cup ball
Hassan Ammar/Associated Press

In this World Cup, I was surprised when I saw a referee draw a white line on the ground for a free kick. "What a great idea!" I thought. But how does it work? Numerous google searches turned up meaningless articles such as this that basically describe the working principle of the spray as "you spray it on the ground and it leaves a line." NO SHIT SHERLOCK...
So how does it really work? Well, the can is under pressure, probably somewhere around 5 atmospheres of pressure, depending on the strength of the can. The main ingredient is water (80%). A mixture of gases are used to propel the surfactant out of the can, including butane, isobutane, and propane. Once the high pressure mixture of ingredients leave the can and enters the atmosphere, they expand and create a foam on the grass.

The most important ingredient is "polyoxyethylenated sorbitan monolaurate" (aka Tween20 at a concentration of around 1%). This molecule is known as a surfactant (more about this later!) The chemical structure is shown here (from Wikipedia):

Looking at this molecule, the left side is hydrophillic (likes water) and the right side is hydrophobic (likes sticking to hydrocarbon molecules such as butane, isobutane, and propane!) This is the key concept of how a surfactant works: it will stick to the interface between the water and the butane, to form surfaces. This allows the butane to form small drops in water (an emulsion) instead of just phase-separating with all the butane in one half of the can and the water in the other half of the can.

The other key concept is the phase change that Butane undergoes. The hydrocarbons that are under pressure (I would guess 5 atmospheres of pressure) in the can, expand to many times their volume when the enter the atmosphere. This is because Butane is a liquid at room temperature, for pressures greater than 2.5 atmospheres (density of 599 kg/m^3), but it is a gas at pressures below 2.5 atmospheres (density of 2.48 kg/m^3). So the Butane expands to ~250 times its volume when it leaves the can. It turns from a liquid into a gas and expands into massive bubbles. The water in the can doesn't change volume because it's a liquid at both atmospheric and can pressures.

So the expanded butane drops make a foam on the grass, which scatters light and makes it white in appearance. In my drawing, I only showed a few bubbles, but in reality there will be billions of them.

Eventually, the bubbles of propane will combine, pop, and evaporate, leaving only a residue of the surfactant (Tween20) and water on the grass. What makes the bubbles scatter light is the billions of interfaces of differing refractive indexes. Once these interfaces combine to form a thin layer of Tween20, they no longer scatter light, and become invisible.

Now you know: that's how World Cup Spray works!

Some of the other ingredients in the can are: a chelating agent "tetrasodium EDTA acid" at around 2% composition. A chelating agent is basically just a chemical that binds to metal ions. Who cares about metal ions? Well, metal ions (such as those that make up the can) have a tendency to break polymer chains such as the one that is used in the foam. So basically, the chelating agent helps preserve the important Tween20 chains from breaking down during storage in the can.

There are also some preservatives to prevent Bacteria from growing in the spray can if it's left on a shelf for a long time.

I made a schematic diagram of how I understand the can's operating principles. If you have questions, or think that my interpretation is wrong, please let me know and I'll update it! In particular, I'm not sure about the exact state of the foam while it's on the grass surface. Are they bubbles of propane? Or maybe not spherical bubbles?

My interpretation of how the spray works is based mainly on the patent by the inventor that I found here:

Sunday, February 2, 2014

The thermodynamic limit of bitcoin mining

There has been a trend in improving energy efficiency of Bitcoin mining machines. But how good can they get? What are the fundamental limits to the hashrate? What is the ultimate GH/J?

We can use thermodynamics to explore this possibility. If we treat the computation of a SHA256 hash as a simple operation, with a single bit of entropy required to calculate, then the energy expended to perform the hash is equal to the Landuaer limit: k*T*ln2. The blackbody temperature of outer space (caused by the cosmic microwave background left over from the big bang) is: 2.7K. So if we built a computer that was operating at 2.8 K and was radiating waste heat into outer space at 2.7K, we could theoretically perform each hash at 1.38E-23 J/K * 2.7K = 3.7E-23 J/operation, or inversely, 2.7*10^13 GH/J, or around 13 orders of magnitude better than the current Bitcoin miners! So plenty of room for improvement.

If we assume a Moore's law type improvement in efficiency of doubling every 18 months, then the time it will take before someone develops a thermodynamically limited ASICminer will be 65 years or so. I expect that DNA-based and other soft-matter computers will be much more energy efficient than current CPUs. I think it's not crazy to believe that a soft-matter computer (ie DNA annealing computer) may improve the energy efficiency of Bitcoin mining by a few orders of magnitude. 

So now if we harnessed the entire power of the sun to perform bitcoin operations, with around 3.8*10^26W of power, in theory we could perform: 3.8*10^26W/ 3.7E-23 J/operation =10^49 operations per second. The current Bitcoin mining network performs around 2*10^16 Hash/s, and so there are around 33 orders of magnitude left before the entire power of the sun is consumed calculating Bitcoin hashes.

OK, now what if someone built a hyper-efficient computer? What would happen to the difficulty of mining? Well, currently, the "target" to create a new block while mining on the Bitcoin network is: 0000000000000001F52C00000000000000000000000000000000000000000000
This number means that if a miner stumbles upon a hash that is less than this value, he/she wins the block reward. So around in in every 15 and 1/16 hexadecimals will be rewarded, which is (15 1/16)^17 = 7*10^18 hashes. So we expect each block to be solved in around: 7*10^18 hashes/2*10^16 Hash/s = 350 seconds, or 6 minutes or so. Now if we want to keep the block generation rate of the Bitcoin network the same, but with massively increased hashrate, the target just need to be readjusted. So what would the target have to be if we are using all of the power of the sun in a thermodynamically limited computer that radiates energy into space? Well, the target would have to be 10^33 times more difficult, or 33ln10/(ln16)=27 hexadecimals further to the right. So the target would have to be approximately: 000000000000000000000000000000000000000001F52C00000000000000000

And so, the Bitcoin system is pretty much OK with any foreseeable improvements in computational speed.

If you know how a quantum computer might affect these calculations (I don't), then please comment below!

Saturday, November 30, 2013

Bitcoin mining

For fun, I just put together a Bitcoin mining machine! The machine does brute-force calculations to try to solve the mathematical problem of what input (random string), in combination with the current Bitcoin block header (that contains a list of transactions) will produce the desired output, a series of numbers that starts with a bunch of zeroes. As an example, here is a script that will calculate the hash of Bitcoin Block number 125552:

import hashlib
header_hex = ("01000000" +
"81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +
"e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +
"c7f5d74d" +
"f2b9441a" +
header_bin = header_hex.decode('hex')
hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
print "The hash of block 125552: ", testblock;

I got this from here . You can test this script for yourself by pasting and executing it here: Note that the first few digits of the resulting hash are zeroes, which is the criteria for mining a new block. This block was mined by trying numbers in the place of the '42a14695' until one of them worked. Note that the number 2504433986 is 9546A142 in hexadecimal, which becomes 42a14695 when re-arranged between little and big endian. So we can speculate that perhaps the miner had to try more than 2 billion combinations before finding the one that worked! All the current Bitcoin miners in the network are brute-force trying numbers, hoping to get lucky and collect the 25 Bitcoin reward. By performing this work, miners verify that the transactions are valid and secure the network as a whole since other miners scrutinize the block header looking for any mistakes that would invalidate it and prevent it from being widely accepted.
The mining setup that I built uses an ASICMiner Erupter Blade. I mounted the Blade in an old broken lab power supply that had a working fan in it already. The power supply is a 12V 10A LED power supply. I read some reports of the wires overheating so I went overkill and put some super beefy wires (AWG 8) between the power supply and the Blade. It took a lot of tinkering to set up. Eventually I settled on using 32 bit bfgminer since it has built in stratum proxy capability. I ran it with "bfgminer --http-port 8330" where I configured the Blade through a browser at as follows:

UPDATE: I created a .bat file, and put a shortcut to it in my startup folder. Now, everytime I start up my computer, it automatically starts mining. I had to set the properties of the shortcut to run as administrator in order for it to work. The bat file contains:
"cd Desktop/bfgminer-3.7.0-win32
bfgminer --http-port 8330 -o -u username -p 123"

Currently, the device mines approximately 293 micro-BTC/hr, but this is likely to decrease in the near future with faster mining machines. Update: down to 99 micro-BTC/hr :(

Update: I stopped mining because electricity costs became greater than the mining reward!

Comments/questions welcome! And of course donations :) 1EXhFqvXkwcXRfhUxmbaUSZgLhGCsWsUcu

Tuesday, October 23, 2012

DIY sonar using PC speaker and microphone

Together with my friend and colleague John Berezney, I decided to make a sonar system using a microphone and speaker. The idea is to make an active sonar system using PC speakers as output and a microphone as an input. I got some inspiration for this project from this website:

The first step is to make a chirp, which is just a type of pulse that changes frequency (see Figure). The audio speakers I have can only make pulses up to 20kHz (I think?), so I make chirps that vary between around 4kHz and 16kHz. I used Labview software to program the chirp and make it come out of my speakers.
The equation for this chirp, C(t) is a function of the pulse length T as well as the minimum and maximum frequencies in the chirp f_min and f_max. Typically I would choose a pulse length of T=2 milliseconds and f_min=4kHz and f_max=12kHz. The first part of the equation with the exponential is just an envelope function that prevents the frequency content from leaking into adjacent frequencies. The equation is:

Once we have a chirp coming out of the speakers, the next trick is to process the recorded audio that is coming in through the microphone. There are many ways to do this. I chose to use a matched filter. The idea is that whenever the microphone picks up a chirp that matches the one I sent, it makes a spike. This trick (matched filters) is used in radar all the time. The math for turning the microphone recording R(t) into a useful sonar signal S(t) using a matched filter is:

Note that we have to take the complex conjugate of the Fourier tranform of the chirp signal, multiply that by the Fourier transform of the Recording in frequency space, and then inverse Fourier transform to get a signal as a function of time. The signal S(t) has spikes wherever there is a reflection. Here you see S(t) which has a strong signal where the microphone picks up the direct wave, and a weaker signal for all the reflections.

The final step is to keep making chirps (my program could make around 4 per second) and then plot the intensity vs distance vs time (yes a 3D graph on a 2D plot!). To do this, I made an intensity graph, where height represents distance away in the reflection, and the time scrolls horizontally. I was holding a sound-reflecting clipboard, and walked away around 3 meters, and then returned to the computer. You can see that as a high intensity reflection going vertical on the graph (far away) and then closer.

John and I have some fun ideas for improving our sonar, I will keep the world updated as we make more improvements! I would be happy to hear if you guys have some fun ideas for improvements! I did all the signal processing and speaker output using Labview software. I am happy to give you the source code if you are interested.

Friday, April 13, 2012

Single laser wavelength STED

On around August 2009, during a late-night brain-storm session with my colleague Erik Garbacik, I came up with the idea for my MSc project at the University of Twente: STED microscopy with a single laser wavelength. A few months later, a patent surfaced by Stephen Baer which basically said exactly the same thing as my MSc project proposal did. However, Baer didn't have any experimental proof in his patent, and so I figured I would go ahead and be the first to get results in the form of a Master's thesis.

Since I finished my MSc, a few more papers have surfaced (one by Baer: still no experimental proof!) and a few more from research groups in France and Italy that experimentally demonstrated the concept.

I am very curious to see what happens to the single wavelength STED microscope, especially whether or not it will indeed be used to make scientific discoveries about biology on the nanoscale. If you have any updates I'd be happy to hear them!

Sunday, September 11, 2011

Magnetic Tweezers

So I thought I'd just write down what I'm working on for the average person who's curious. I work on an instrument called a magnetic tweezer. We use magnetic tweezers to study biophysics. We can take a single strand of DNA and bond a magnetic bead to one end of the DNA and a glass slide to the other. Since the bead is paramagnetic, we can stretch a single strand of DNA when we bring a magnet close by. By changing the distance of the external magnet we can change the force on the DNA, and thus we can do force spectroscopy (a fancy word for measuring DNA length as a function of force). Within the Saleh Lab where I work, there are a few main topics of research using magnetic tweezers: ion-DNA interactions, DNA-DNA interactions, and protein-DNA interactions.

I work on protein-DNA interactions. Specifically, I am interested in a class of proteins called helicases. These proteins unzip genes and are therefore the subject of many biology-related pickup lines. Perhaps even more interesting is that they are involved in replication and all sorts of biological functions. You have trillions and trillions of helicase molecules in your body. Helicases are the bulldozer at the front of the replication machinery. We have classified a bunch of different types of helicases, but we don't yet understand how helicases move. We know that they burn ATP, but do they take single base-pair step for each ATP consumed? Or do they take steps of multiple base-pairs? Right now we don't know, and I hope to use magnetic tweezers to measure the step-size of helicase molecules.

There are numerous technical challenges standing in the way of answering fundamental questions about how helicases move along DNA. First of all, we can't actually see the DNA or the helicase. All we can see is the magnetic bead and use that bead as a probe to deduce the position of the protein. We typically use a hairpin of DNA, whereby each base-pair that is unzipped results in the magnetic bead moving towards the magnets by about 0.6 nanometers per base-pair unzipped. To put that in perspective: that's very small!

Measuring helicase steps are further complicated by the fact that the magnetic beads are undergoing Brownian motion from being bumped around by the surrounding water molecules. So when we see the bead move, we never really know for sure if it was because the helicase unzipped a single base-pair or if the water molecules bumped the bead and stretched the DNA a bit. The only way to get around the thermal noise is to take lots of measurements and average out the noise. So that's the reason I have been playing with a high-speed camera a lot lately. Oh, and everything is cooler in sloooowww moootttiiiooonnnn.

I'm trying to make the best of your tax-payer dollars, but if you have any questions or comments I'd be happy to hear them.