Showing the cosine and sine projections for the discrete fourier basis, and also showing the magnitude, for a ramp function which shifts. Notice how the sine and cosine components change, but the magnitude doesn't at all. This is because only the phase is changing as the function shifts

Same as above, but showing two other periods of the ramp function to really drive home the point that we're assuming the signal repeats itself infinitely, and when we do a discrete Fourier decomposition we're just looking in a window equal to one period length

One way to think about what we're doing when we assume something repeats itself infinitely is that we can think about it as living on the circle, wrapping around over and over again. The animation below shows how to warp from the domain of a line segment to a circle.

Once we put functions on a circle, we can then view a phase shift as a rotation! This leads us to the understanding that doing a Fourier decomposition of functions on the circle and recording the magnitudes only gives us a rotation invariant descriptor of shape

Spherical Harmonics

There's an analogous thing we can do to functions on a circle with functions on the sphere. Instead of sinusoids, we instead get these spherical harmonics

Click here to download meshes which represent some of the lower order spherical harmonics, as well as code used to generate them (using my Python mesh library and scipy). You can use meshlab to view them

In those meshes I saved the real component of each spherical harmonic, but just as cosines and sines, there's a real and imaginary component, and we store the magnitude to describe functions along the sphere in a way which is invariant to 3D rotations (thinking of wrapping 2D functions around the sphere and shifting them around). Have a look at section 4 pages 7-8 of this paper to see how spherical harmonics are used to create a fancier type of shell histogram for 3D shapes. The idea is exactly the same as before, but instead of simply counting the number of points that fall in each shell or recording PCA eigenvalues, you instead record the magnitude of the spherical harmonics.