You are on page 1of 6

Software f o r M a t h e m a t i c a l Analysis

D.L. Hench
Imaging Systems Application Company
717 E. Rainier
Orange, CA
7141998-2691

Abstract- An important type of software package that Mathematica can perform are. numeric, symbolic,
that belongs in the engineering workplace is a math- and graphical. In symbolic processing, variables rep-
ematical analysis package. Popular packages include resent more than locations to store numbers, so that,
MATLAB, Mathematica, Mathcad and Maple V. y = 2++1 can be solved as = i g - 4 without assigning
The various packages are compared and contrasted a value to c or y .
here with regard to the insight that they can provide
Mathcad provides a unique new way to work with
for a topic of current interest.
formulas, numbers. text and graphs. It allows formulas
The selected topic is cosine-transform data-
compression as specified in the MPEG standard for to be entered using WYSIWYG (what you see is what
video data compression. This problem is f i s t intro- you get). These formulas can either be used for cal-
duced and the outputs of the various packages are culations in a manner as versatile as a spreadsheet or
shown with an emphasis on the insight to the prob- incorporated into documents, eliminating the need for
lem that can be gained by using an approach that is an equation word processor such as T)i$[5], which was
natural to the software package under consideration. used for this paper.
Keywords- MPEG, DCT, MATLAB, Mathematica, Maple V uses the symbolic engine developed by Wa-
Mathcad, Maple V terloo Maple Software Inc. in Ontario, Canada. It in-
cludes libraries for algebra, group theory, linear algebra.
statistics, optimization, number theory, and other areas
1.O INTRODUCTION of mathematics. It is designed for deriving and simpli-
fying formulas.
Software packages for mathematical visualization, The evaluation was carried out on a 486DX computer
data reduction, and even derivation of equations us- with b Mbytes of RAM and running Windows 3.1.
ing symbolic processing are an important part of an I would like to thank: (1) Tom Iiush (508-653-1415)
engineer’s toolkit. These packages include the matrix of the Math Works, Inc. for providing a copy of
oriented MATLAB [l], the symbolic processing oriented the MATLAB EXPO; (2) Jane Rich (217-398-0700) of
Mathematica [2], the simpler “engineering speadsheet” Wolfram Research for supplying an evaluation copy of
oriented Mathcad [3], and symbolic processing oriented Mathematica 2.2 for Windows (enhanced) and the Elec-
Maple V [4]. trical Engineering Pack; (3) Robert Kelly( 800-628-4223
In this paper we will compare and contrast these x792) of MathSoft for providing evaluation copies of
packages in terms of the insight that they provide to Mathcad Plus 5.0 for Windows and Maple V, Release
a subject of current interest in video data compression. 2.
This subject is the application of the Discrete Cosine
Tkansform ( DCT).
2.U ,\IPE;G VIDEOCOMPRESSION
MATLAB [l] is designed as an interactive program
to help with numeric computation and data visualiza-
tion. Fundamentally, MATLAB is built upon a foun- A popular video data compression technique devel-
dation of sophisticated matrix software for analyzing oped for the coded representation of moving pictures
linear systems of equations. The tools springing from and associated audio on digital storage media is spec-
these numerical foundations have proven to be versatile ified by the MPEG-1 standard [6]. MPEG stands for
and useful in engineering, applied mathematics, statis- Motion Picture Expert Group. This standard provides
tical analysis, and finance. This package seenu best VHS qualit1 imager!- using oiily 1.5 Mbit,s/sec. An
suited to the problem at hand and is referenced the MPEG-2 standard [$I is now available which is said
most. to yrovidr broadcast quality at about 5 Mbits/sec. In
Mathematica is a general system for doing mathemal- wiit,rasi. st i c d i o digital imagery conforming to standard
ical computation. The three major types of calculatioiis ( ’( ‘1H ROI ir] at 720+;$60( color) pixels/line by 485 lines

258
using 8 bitslpixel and 30 franies/sec requires about 80 10 tht decoder to produce acceptable encoding. The

times this bandwidth (125,712 Mbits/sec). default intra-quantization matrix is given by


In addition to transform coding, MPEG coding uses.
(1) frame-teframe predictive coding, ( 2 ) niotion coni-
pensation , and (3) variable length coding. 111 the pre-
dictive coding techniques, each video frame is predicted 16 16 22 24 27 29 34 37
from the previous frame and this predicted frame is sub- 19 22 26 27 29 34 34 38
tracted from the actual frame and only the difference 22 22 26 27 29 34 37 40
is coded by transform techniques. In motion compen- 22 26 27 29 32 35 40 48
sation, the frame-teframe motion of regions of the im- 26 27 29 32 35 40 48 58
age is transmitted to aid in the prediction. In variable 26 27 29 34 38 46 56 69
length (Huffman) coding, the most likely values are as-
signed a smaller number of bits.
The actual MPEG scheme is somewhat more coiii- It IS of coarse iiecessary to apply the inverse DCT to
plicated. The scheme uses three types of frames, (I, P. I(u.u)*q*M(u.u).
and B ) frames. The I (Intraframe) frames are coded It is easy t o write the DCT of Eq. ( 1 ) in matrix form.
using 8 x 8 transform blocks and the only differenc- With f representing the image function viewed as a ma-
ing used is on the DC component between blocks. The trix, F representing the DCT viewed as a matrix, and T
P (Predicted) frames use motion offset values for 16 representing the transformation matrix with transpose
x 16 regions of the image and the previous I frame. TT,we write
The B (Bi-directional) frames lie between the I and P F=TTfT, (7)
frames and use coded motion vectors from frames be- where the i, j component of T is given by
fore and after the current frame. A typical sequence
is IBBPBBPBBPBBI. The encoder has the option of {T}i, = 0.5C(j)cos( ~ ( 2 i +
l)j/l6) . (8)
changing the sequence used along with many of the
other parameters of compression. This flexibility, b j As will be demonstrated under the description of Math-
design, makes the encoder much more complicated (and cad, the matrix T is Hermetian, i.e., the the inverse of
hence more expensive) than the decoder. This cost dif- this matrix is given by the transpose, T-’= T T . Pre
ferential allows decoders to be used at each end-users and post multiplying Eq. (7) produces
workstation with few encoders.
The 8 x 8 DCT is given in the MPEG-1 standard as f = TFTT . (9)

F ( u ,U)
1
= -4 C(.)C(U)
z=o
?

cm
?

y=o
Y)
Representing the quantized DCT by FQ and the re-
constructed image by fQ,we have using Eq’s (3 t o 4)

x cos( a(22 + l)u/16) ~ I ( i , j )* y


{FQ},= * M ( i ,j ) . (10)
So that the reconstructed image is given by
where fQ = TFQTT
C ( U )= {:/a,i f u = 0,
, if otherwise. 3 . 0 MATLAB
Representing the operation of rounding to the nearest
pixel by round(...), each coefficient is quantized using ‘The DCT application is an idea problem for the ma-
trix oriented MATLAB. In fact, the DCT is a func-
I(U , U ) = round { F (U , v ) / ( y * M (U. U))} . (3) tion supplied in the “Image Processing Toolbox” which
was not readily available in this effort. Here, the
where DCT is written as a functiou. Other available tool-
if U = U = 0, boxes are: 5ignal Processing, System Identification,
y = { kuantizer scale , if otherwise. (4) Symbolic Math . Keural Network, Optimization, Con-
trol Systeni. Robust Control, Nonlinear Control. Neural
M(U, U) ~ intra-qualltization , (5) Network. 5ysteni Identification, p-Analysis. Statistics.
Spline, and Chemonietrics.
Both the quantizer scale and the intra-quantization MATLAB is ail interactive program with a high level
matrix can be modified by the encoder and transmitted language for matrix manipulation and inany built-in

259
Figure 1: MPEG-1 Conipression Applied t,o an Edge
An original 8 pixel x 8 pixel edge image is shown in (a). This edge after reconstruction with q = (1, 2,1} is
shown in (b), (c), and ( d ) respectively.

functions for data manipulation and display. Com-


mands can either be entered directly or stored as “m”- im=128*[0,1,1,1,1,1,1,1;
files which can be called from the command line or from o,o, 1.1,1,1,1.1;
other m-files. Functions can also be written as m-files. o~o.l~l,lsl,l~l;
In MATLAB there are two types of matrix multipli- o,o,o. 1.1,1,1.1;
cation. An expression A*X represents matrix multipli- 0,0.0,0,1,~.~,~;
cation as in Eq. (7) and an expression A.*X represents 0,0,0,0,0.~~~,1;
element by element multiplication as in Eq. (9). 0,0,0,0,0.1,1,1;
An image can of course be represented by a matrix. O,O,O,O,O.O.l,ll +63;
F i g l a . shows a grey level representation of an original dct=dct2(im),
8 x 8 image of an edge. Fig’s l b , IC and Id show the [trans,quantizedl=quan(dct,2);
resulting reconstructed images for y = { 1,2,4} respec- imot=idct2(quantized) ;
*MO L O #- i i l e dct2 .m%%%%%%%%
O OM# a
tively.
The MATLAB code needed to generate Fig. IC is function y=dct2(x)
shown in Fig. 2. The syntax is powerful, but obscure. T=O .5*cos(pi/16*(2*[0:73 +l)* CO: 71) ;
This code can either be entered directly or programmed T(: ,1)=2^(-0.5)*T(:,l);
as an m-file and called from the prompt. y=T ’*x*T ;
The MATLAB language contains flexible techniques LLLLLL/a-f ile q u a .m%%%%%%%%
* # o n o . *

for reorganizing matrices. These techniques make it function Ctran,coefl=quan(dct, scale)


faster to perform repeated calculations than the other qn= [ 8 ,16,19,22,26,27.29,34;
packages. Taking advantage of these techniques we plot 16,16,22,24,27,29,34.37;
the scan order of transmission used in MPEG coding in 19,22,26,27,29,34,34,38;
Fig. 3. This zig-zag pattern allows run-length cod- 22,22,26,27,29.34,37.40;
ing of the coefficients, where the number of coefficients 22,26,27,29,32,35,40,48;
that are zero are transmitted instead of that number 26,27,29,32,35,40.48,58;
of zeros. Fig. 4 shows coefficients plotted versus the 26,27,29,34,38,46,56,69;
zig-zag order. The DCT coefficients are shown as solid 27,29,35,38,46,56,69,83];
lines and the quantized coeffients [after application of tran=round(dct ./(qn*scale)) ;
Eq. (9)] are shown as dashed lines. Fig. 5 shows the coef=tran.*qn*scale;
quantized coefficients before reconstruction. tran(l,l)=round(dct(1,1)/8);
The DCT can be viewed as a catalog of images (basis coef (l,l)=tran(l,1)*8;
functions) which are summed and transmitted. Fig. 7
shows 6 of the 64 images in the catalog
Figure 2. MATLAB Code for Fig. IC
4.0 MATHEMATICA The code that generates Fig. I C is shown along with
subroutines to generate the DCT and quantized coef-
ficients.
Mathematica is a general system for doing numeric.

260
2-

1-

4-

5-

-6-

7-

4-

91 8 1
0 2 4 6

Figure 3: Zig-Zag Pattern for Run-Length Encoding Figure 4: DCT Coefficients


The DCT coefficients are considered in the order The DCT Coefficients of Fig. 1 are plotted in the z i p
shown and run-length encoding is used for compres- zag order of Fig. 1 both as calculated (solid lines) and
sion. as quantized (dashed lines).

symbolic, and graphical calculation. We will concen- is used where 6 represents the Kronecker 6 which is
trate on the numeric and graphical processing and show unity when the arguments are zero and zero elsewhere.
symbolic processing under Maple V. The result is the basis function T4,5 of Fig 7 (the co-
Mathematica has a full matrix capability and any of efficients there are unit based; here zero based) and is
the previous figures could have been generated in Math- given by
ematica (or in Mathcad). The speed of calculation, even
for 8 by 8 matrices, is noticibly slower than MATLAB f ( z ,y ) = 0.25 * cos( 1 . 1 7 8 1 ~+ 0.58905)
and the syntax is more like a normal programming lan- x cos( 1.5708 + 0.78540) . (13)
guage.
The original function is recovered for f ( 3 , 4 ) . It is
Calculations in Mathematica are organized as “Note-
books” with formulas grouped as cells. A notebook that possible to generate an array of values or to unassign
displays the reconstructed edge of Fig. IC as a 3D plot F1(U. U ) and get a symbolic answer.
is shown in Fig. 6.
7.0 CONCLUSIONS
5.0 MATHCAD
In the author’s opinion you need: ( 1 ) MATLAB if
you wish to do heavy duty number crunching with stan-
A demonstration that T is Hermetian is shown in Fig.
dard mathematics . ( 2 ) Mathematica for general math-
8 using Mathcad. A complete window (MicroSoft Win-
ematics including symbolic manipulation, ( 3 ) Mathcad
dows) is shown with the formatting buttons. Hotkeys
if you wish to include equations and results in reports
can be used for rapid formatting.
and don’t wish to learn an equation word processor like
Mathcad is designed to easily export the information
QX. and ( 4 ) Maple V if you are on the cutting edge
shown here to standard word processors so that mathe-
of equation maupulation and derivation. The list costs
matics can be incorporated in reports. It has a limited
are: ( 1 ) $1.695 for MATLAB for Windows and $400-900
symbolic facility borrowed from Maple V and can im-
per toolbox, ( 2 ) $995 for Mathematica 2.2 (enhanced)
port Maple V data.
($595 standard) for Windows and $195 for the Electri-
cal Engineering Pack. ( 2 ) $299.95 for Mathcad Plus
6.0 MAPLE V 5.0, and ( 3 ) $835 for Maple V release 2 for Windows.

The symbolic processing of Maple V is shown in Fig. I

9. Both the DCT and the IDCT are coded with the References
DCT coded in the form of Eq. 1 . A DCT transform of
the form [l] The MATLAB EXPO. The Math Works, Inc., Nat-
F(u,v ) = 6( U - 3. U - 4 ) . (12) ick. MA, 1993.

26 1
Figure 7: Selected Basis Functions
Eight of the 64 basis images for the DCT are shown. These are F12.F147F16vF187F239 F457F673F88 for
a,b,c,d,e,f,g,h respectively.
Ca[~_1:-1f~~--O.l/Surt~2.l,i.i
Tdct=Table[N[0.5 Ca[jlCos~Pi(2.i+l.)j~16.11
(i~O,7)#1j,O,7)1
#

Ilaage=Table~Iftj~0.5+~5./7.)i,63.,191.I,[i,O,7),
( j , 0.71 I
Dct-Transpose[Tdctl.Iaage.Tdct
Imot=Tdct.Dct.Tranepoee[Tdct]

Qn=1(8 .16.19,22.26.27.29,34),
~16.16,22,14.27,29,34,37),
(19.22.26,27.29.34.34,38),
(22,~2.26.27.29.34,37,40),
f22,26,27,29,32,35,40.48),
126.27.29.32.35.40.48.58).
126.27.29.34,38,46,56,69),
(27.29,35.38.46,56,69.83))
Quantize[value-,el:-a Round[value/ql
Coef=Table[
Quantize[
~ t ~ ~ i . j l l . I f [ i = = l . & h j = = 1 . , 8 ,QnIIi.jll
~ 1
I . 1i.1.8). (j,1,8)1
Imot=Tdct.Coef.Transpose[Tdctl
ListPlot3D[Transpose[Imot]]

Figure 5: Quantized DCT Coefficients


The quantized DCT coefficients of Fig. 1 are plotted
in the zig-zag order of Fig. 3

[2] Stephan Wolfram, Mathematzca. A S'ystem for Do-


ing Mathemallcs by Computer. Addison-Wesley,
Redwood City, CA, 1988.
Figure 6 : Mathematica Notebook
[3] MathCad 5.0.f for Wzndows. MathSoft Inc., Cam- A Mathematica Notebook showing a 3D plot of the
bridge, MA, 1994. reconstructed edge of Fig. IC is shown.

[4] D. Redfern, Maple Handbook. Springer-Verlag,

262
> C:=proc(u) if us0 then llsqrt(2) else 1 fi end;
> DCT:=proc(u,v,f) sum('0.25'C(u)'cos(Pi*(2'x+1 )'u/l6)
> *sum('f(x,y)'C(v)'cos(Pi'(2*y+l )'v/l6)','y'=0..7)'
> ,'x'=O..7) end;
> IDCT:=proc(x,y,F) sum('0.25'C(u)'cos(Pi'(2'x+l)'o/16)
> *sum('F(u,v)'C(v)'cos( Pi'(S*y+l)'v/16)','~'=0..7)'
> ,'u'=O..7) end;

> F1:=proc(u,v) if u=3 and v=4 then 1 else 0 fi end;


> IDCT(x,y,'Fl');
.25000 cos( 1.1781 x + .58905) cos( 1.5708 y + .78540)
> f2:=proc(x,y) IDCT(x,y,'Fl') end;
> DCT(3,4,'f2');
1.oooo
Figure 9: Maple V output
. Maple V derivation of the symbolic derivation of DCT Transform for an input 6(z - 3 , y - 4 ) is shown
A
where 6 returns 0 unless the arguments are zero and then returns 1 (Kronecker delta). The inverse transform
is shown at c. = 3, y = 4 (zero based).

New York, 1994


[5] D.E. Iinuth. The Texbook. Addison-Wesley, Read-
ing, Mass. 1984.
Use range variables I and J [6] IS0 Standard 11172, "Coding of Movlng Pictures
1 =o.7 and Associated Audio for Digital Storage Media at
u p to about 1.5 Mbits/s- Part 2:Video". Decern-
define a nx1 vector C 11 ber 1991.
[7] ISO/IEC Standard 13818, MPEG--2. 1994.
[8] KBenson and J . Whitaker, Televzszon Engzneer-
define the transform matrix 6 ,I m g Handbook. pg 21.71-21,74, McGraw-Hill, New

&J J [
T. . :=0.5C:cos n.(2,i+ 11.L
161 ,
York. 1992

and show that it is Hermetian ( T.T*


not shown)

Figure 8: MathCad output


.4 Mathcad window is shown with a demonstration
that T is Hermetian. Formatting is performed by the
buttons at the left or by formatting keystrokes.

263

You might also like