[Math] difference between cosine and sine transform

compressionfourier analysistransformation

Surely both should work with the same set of functions. Why is only cosine transform used in JPEG? Why not sine?
It seems that using fourier transform rather than cosine transform would result in complex numbers, but why should that even be a problem at all, surely we know how to do maths with complex numbers and they are not uselss.

Best Answer

As was said in comments, cosines and sines differ only by phase shift. The difference in their performance arises from their boundary behavior. On an interval $[0,\ell]$, the sine system $\left\{\sin \frac{2\pi n }{\ell}\right\}$ satisfies the Dirichlet boundary condition, attaining zero value at $0,\ell$.

A generic function, e.g., one describing the brightness of an image, need not take zero values on the boundary (or satisfy any other boundary condition we may be thinking of). Thus, it cannot be uniformly approximate by a linear combination of sines.

On the other hand, the cosine system $\left\{\cos \frac{2\pi n }{\ell}\right\}$ satisfies the Neumann boundary condition, having zero derivative at $0,\ell$. The boundary values are not pinned down as they are for sines. This makes it possible to uniformly approximate (reasonable*) continuous functions by a cosine Fourier series; the fact that we can't uniformly approximate the derivative is not nearly as damaging.

For illustration, here is $e^x$ approximated by sines and by cosines (after the interval shift from $[-1,1]$ to $[0,2]$), with the same number of terms of Fourier series used (taken from my blog):

Sines

sines

Cosines

cosines

* It's hard to construct a continuous function for which the cosine Fourier series fails to converge to it uniformly on the interval of approximation. It's safe to say that a "naturally occurring" continuous function won't be such a counterexample.

Related Question