LabGuy's World: YUV to RGB Color Matrix Project

Color matrix board in detail 20140330

       PROJECT GOAL: Build an electronic video matrix that converts YUV video outputs from a standard definition DVD player into red, green and blue pseudo-B&W video signals to drive the one inch CRT monitors of the [Tiny Triniscope TV project].

       To avoid constructing and entire NTSC demodulator, I had chosen to use the YUV outputs of my DVD player for the source of color video signals. Using YUV would eliminate NTSC decoding artifacts, producing a superior color image. In NTSC composite video, the recovery process can leave garbage in the color signals if not done properly. That is something I would rather not deal with at this time. An NTSC to YUV demodulator may very well be a future project. If you are not familiar with color matrices, Wikipedia offers an excellent tutorial on [the subject of the YUV matrix] with links to even more.

       If you are new or inexperienced in electronics construction, allow me to share my experience with you by visiting my [Electronics Hobby] page. Learn how I construct my prototype boards after thrity years of working in Silicon Valley.

Color matrix input and output video waveforms and their image - 20140328

       The three images above show us the input video waveforms, the output waveforms and what they look like on TV screen. The two scope screen shots show four TV lines of the upper color bars only. We ignore the inverted bars and the I, WHT & Q signals at the bottom of the test pattern. The first photo shows the Y, U & V signals after clamping and amlifying. U is amplified over 2.032 times and V is amplified by at least 1.14 times. These can then be mixed with Y to extract the red, green and blue video signals. To find out how the constants of 2.032 and 1.14 were derived read on.

       The second photo is the green, blue and red output signals from the matrix circuit. Note that all three video signals now have sync pulses. These are the small negative going pulses on all three waveforms in photo 2. This makes for a simple one wire composite video connection to each monitor. These signals are now fully ready for use.

       Here is how the signals translate to color bars on screen:


Color bars component video signal generator on the cheap!

       The waveform shown is standard color bars which I burned to a DVD and then send to this matrix. I found a nice photo of color bars on the web. Dropped it into my video editor and burned it to DVD. Crude. But, expedient. The noise seen in the waveforms is the result of JPEG encoding of the low res image found on line. Was not going for broadcast quality here. It worked and that's what counts in this hobby! (Yes. If I'd had a component video generator, it would have been used!)

       Hi there! Do you live in nation that essentially resents and rejects American standards and values? No problem then! This matrix will work for PAL and SECAM as well as it does for NTSC. It probably works very well for HDTV as well, with an appropriate sync separator to replace the LM1881N. A truly international, multistandard and multiformat, design!

[Color matrix schematic in PDF format] - 20140328

       The Y signal is the BW portion of color video. It also contains the sync information. Y is a unipolar signal that goes from zero to .714 volts. Sync is also unipolar and goes negative .286 volts. U and V are color difference signals. They are bipolar, meaning that they have both positive and negative excursions. Coming from my DVD player, these three signals were sitting on DC levels about one volt above ground. They can not be matrixed in this form. The output results will be the correct relative levels sitting on extreme DC offsets. Quite likely clipped at either plus or minus five volts, the power supply rails. What we scientists call unacceptable.

       The first step was to remove the DC offset, or clamp the video to zero volts DC. An LM1881N sync separator (U4) and a DG211 quad CMOS switch (U5) form an active DC clamp system. Video is AC coupled to the op amp. Between the capacitor and op amp, the cmos switch goes to ground. During the video blanking intervals, where the video signals need to be at zero volts DC reference, the ampifier inputs are briefly connected to ground by the CMOS switch. This keeps the input nodes referenced to zero volts. During the remainder of the time, the switch is open and video is allows to flow unimpeded. The 1881 takes the sync from the Y signal and creates the clamp pulse ready to use. Easy peasy.

       Here are the equations for creating Y, U & V from R, G & B:

Y = (.3 x R) + (.59 x G) + (.11 x B)
U = 0.492 x (B - Y)
V = 0.877 x (R - Y)

       Two things are happening to the U & V signals. First the redundant Y signal is subtracted from each of the red and blue signals. The results of this algebraic addition creates two signals that are now bipolar. They can have either positive or negative polarity. The second thing is that they have departed from the one volt scale of the input R, G, B, and Y signals. They are both now larger than one volt. U covers a range of 1.4 volts total and V needs over 1.7 volts of range.

       In practice, video signals are constrained to a one volt range to accomodate the electronic circuitry! Its easier to build all the paths to process a standard one volt signal rather than accomodating different levels that can and will experience different amounts of linearity distortion. So, the electronic amplifiers are standardized and all video intermediate video signals are scaled to this operational range for practical reasons. But, it does gum up the math just a little.

       After the RGB summations, the full scale of U is now +/-0.7 volts and the full scale V signal is +/-0.88 volts. (approximately) The absolute range is now 1.4 Volts for U and 1.7 Volts for V. So, to scale U & V to fit into the one volt channel of the amplifiers and digitizers, we multiply U by .492 and V is scaled by .877. Now U & V are approximately +/-0.5 volts pk-pk. Like this:

Y = (.3 x R) + (.59 x G) + (.11 x B)
U = 0.492 x (B - Y)
V = 0.877 x (R - Y)

       To undo the scaling of the U & V signals, we use the recipricol values of .499 and of .877. A ricipricol is a number that has been divided into 1. If the result is divided into 1 again, the original number is produced. To get the inverse scaling factors:

2.032 = 1/ 0.492       AND       0.492 = 1/ 2.032

1.14 = 1/ 0.877       AND       0.877 = 1/ 1.14

       So, before the U & V can be matrixed with Y to recover R, G and B, the unity scaling, conversion to a common voltage range, must be reversed. U is multiplied by 2.032 and V is multiplied by 1.14. When added to Y, the U and V signals become the original blue and red signals.

       Here are the equations for the Tiny Triniscope color matrix that reverses the process above:

RED = Y + ( 1.14 x V )
BLU = Y + ( 2.032 x U )
GRN = 1.695 x ( Y - ( 0.3 x RED ) - ( 0.11 x BLU ))

       In this matrix circuit, U & V are boosted high enough to be properly summed with the Y signal. Summing U & Y derives blue video. Summing V & Y derives red video. In turn, red and blue video signals are inverted, in effect multiplied by negative one (x -1), and scaled to .3 and .11 respectively. (See the original RGB equations for these coefficients) Both of these are then algebraically added to Y to derive the green signal. We are literally subtracting the red and blue contributions from the "white" signal Y, leaving only the green part. The recovered signal is now only 59% amplitude, relative to one volt, the original green signal scaling coefficient! The recipricol of .59 is 1.695, the amplifier gain for the green output channel.

Full color matrix images displayed on the Tiny Triniscope monitor - 20140329/20141005

       Above we see color bars that originated on the web at a low resolution, were burned to DVD, played back as YUV components, dematrixed back to RGB and finally displayed on the three one inch CRTs in the Tiny Triniscope monitor! The middle photo was taken by me and my friend Steve Kyte, on March 29 of 2014, while I manually held the red and blue CRTs in their approximate locations, he snapped the picture we see here. This was actually the first display test of the first color matrix as well. Up til then, I had only viewed the matrix signals on the o'scope. Looking good!!! It looked even more fantastic when it was all completed, as seen in these updated first and third photos! Discover the rest of the story on the [Tiny Triniscope TV project] page.


Created: March 21, 2014 Last updated: October 5, 2014