# Encoding color

## YUV color space

In opposite to the RGB color space that we as hackers are used to, the image in PAL is encoded in YUV color space. The Y componen (the luma) is described in part 1 of The theory behind PAL. The U and V component are just other names for the intensity of red and blue (also called chroma blue [Cr] and chroma red [Cb]). As a reference to linear algebra, this is merely a base change.

[ Y ] [ 0.299 0.587 0.114 ] [ R ]
[ U ] = [-0.147 -0.289 0.436 ]*[ G ]
[ V ] [ 0.615 -0.515 -0.100 ] [ B ]

The green information is not lost, but endcode in Y, U, and V all together.

Simplified: Y = Cr+Cg+Cb <=> Cg = Y-Cr-Cb

## Modulation of U and V

To modulate the chroma alongside the luma in the signal, a process called Quadrature Amplitude Modulation (QAM) is used. The Wikipedia has a really good explanation of the process. The modulated signal is then a subcarrier of the main video signal.

Basically, what you can do, is have two scalar signals (our chroma values) and multiply each with two sinusoids having a 90° (π/2 [τ/4]) phase shift against each other. When you add these two resulting signal, you get a sinusoid which phase and amplitude depend on the value of the red and blue signal.

To make this a little bit easier to grasp, I've put together a little something in GeoGebra. The black line is the reference sinusoid which the phase shift will be measured to. The red and blue dotted line are the two sinusoids which are the two signals will be multiplied to. The purple line is the sum of u*blue and v *red.

As you can see, the change of the U and V signal result in a change of the the resulting signal towards the corresponding sinusoid. What we can do now of course is having a mixture of both.

The math behind this is "simple" trigonometry. In the result the amplitude of the chroma signal is

And the phase is

Resulting in

The formulas are especially interesting for demodulation, because now you derive the ration between red and blue from the phase angle

and the the brightness of both of these from the amplitude of the signal.

Couple of weeks ago this idea popped up and I wondered if someone else already do it, found nothing until today ! You have my interest ! I got a SDR kit based on LMS6002 and Cyclone V, what's the burst reference frequency ?