Monday, 16 June 2008

Fourier Transform of a Cat

I took the Fourier Transform of a cat...

But it wasn't very useful, so I took the Fourier Discrete Cosine Transform (DCT) of one instead, and that wasn't much use either, but when I DCT'd back I got a ghost cat.

And now, by way of explanation, here's what I really mean...

I loaded a photograph of a tiger into Mathematica, pulled out the grey values of each pixel, then Fourier transformed the data. The Mathematica discrete Fourier transform produces (as you'd expect) complex results from real data, so it was pretty much useless for rasterising back to graphic format.

Fortunately, Mathematica provides a means to obtain real results from a Fourier Transform, by performing Discrete Cosine Transforms (or Discrete Sine Transforms, DST). Doing this allowed me to transform the data corresponding to greyscale pixel values for the tiger image into a Fourier transform of the tiger. The result was mostly black pixels; not hugely interesting. The original greyscale, and the Fourier DCT image are shown below.





In theory, no information is lost when something undergoes a Fourier Transform. This means that transforming again (i.e. performing a reverse transformation) should yield the original data. Since I had to do a DCT in order to get real pixel values, there was a very slight loss of information, and a second DCT revealed a ghost cat:



UPDATE (July 16, 2008):
I've uploaded the Mathematica notebook (with the output stripped to keep it small, you'll have to re-evaluate the cells, but I provided the original tiger.jpg in the ZIP file too!). It's available at http://www.physical-thought.com/files/fourier-cat.zip

UPDATE (April 19, 2009):
The Mathematica notebook linked above is no longer available online. If you really want the file, you'll have to e-mail me and ask. I'll leave it as an exercise for the reader to find my e-mail address.

Sunday, 1 June 2008

Gravitational Potential

Last night I was playing with Mathematica, visualising perturbations to the gravitational potential of one body by the presence of another (e.g. for binary stars, star-planet and planet-moon systems). I did this by writing a gravitational potential function, using

V(r)=\frac{G M}{r}

Actually, I allowed my Mathematica function to take arguments beyond just a distance r... Firstly I split r into x and y, using the relationship
r^2=x^2+y^2
, then allowed the mass M to be parameterised as well as an offset from the origin, since
r^2=(x-a)^2+(y-b)^2
describes a circle of radius r centred on (a,b).

Finally, I used the fact that potentials can be added to generate the true potential of interacting bodies, i.e.
V_\mathrm{total}=V_\mathrm{star}+V_\mathrm{planet}
. With these functions defined, and a few basic quantities such as the mass of the sun (2*10^30 kg) and the distance in metres corresponding to 1 AU (149,598,000,000 metres), I was able to use the Mathematica ContourPlot[] function to plot equipotential lines for various two-body potentials. I was looking for particularly interesting perturbations to the otherwise circularly symmetric (spherically, in 3D) potential of a "point mass". The approximation of a point mass works perfectly as long as we're dealing only with space outside of the true radius of the object, and on the length scales we're looking at here, that is definitely the case.

I've included some of the more interesting equipotential plots below, including the parameters used to plot them. Remember, you can click any of the images to see a bigger version.

Potential around the Sun: MSun at (0,0) on a scale from -10AU to +10AU on both x and y axes


Earth-Sun System: MSun at (0,0) and MEarth at (1AU,0). x-axis from 0.8 AU to 1.2 AU, y-axis from -1 AU to 1 AU


Earth-Moon System: MEarth at (0,0) and MMoon at (384000km,0). Both axes from -2 to +2 times the Earth-Moon separation (384,000 km)


Sun-Jupiter System: MSun at(0,0), MJupiter at (5.15 AU,0). Axes x from 4 AU to 6 AU, y from -2 AU to +2 AU


HD209458
One of the most "famous" exoplanetary systems, HD209458b is a Hot Jupiter orbiting the star HD209458 (note that the 'b' added to the star name gives the planet name, i.e. the planet is the second object (discovered) in the system). HD209458 has a mass of 1.01 MSun, and the planet HD209458b has mass around 0.69 MJupiter. The separation of the two bodies is 0.045 AU.
Axes from 0.02 AU to 0.07 AU on the x, -0.05 AU to +0.05 AU on the y


HD41004B
Another exoplanet system, this time HD41004B is 0.4 MSun and the planet, HD41004Bb is 18.4 MJupiter. The separation is 0.0177 AU and the axes run from -0.03 AU to +0.03 AU on both x and y


Cygnus X
Cygnus X is a 30 solar mass star and an 8.3 solar mass black hole. The separation is 0.2 AU. I plotted this one with the star at -Separation/2, the black hole at Separation/2 in the range -0.25 AU to +0.25 AU on both x and y axes


PSR B1913+16
A binary pulsar (the first one detected, I think). A 1.441 Solar mass neutron star and a 1.387 Solar mass companion star. Separation 0.0130356021 AU. Axes from -0.02 AU to +0.02 AU on both x and y


I also tried plotting some 3D equipotential surfaces, but the results weren't quite so impressive. Here's the equipotential surface for the Cygnus X system in 3D, range -0.5 AU to 0.5 AU in all three dimensions:


After this, I tried to visualise some of the general relativistic potentials (i.e. corrections to the standard Newtonian potential to take into account general relativistic effects) but didn't get any of them to produce nice visualisations, yet!