ECE 448: Spring 2015Lab 5
Mandelbrot Set Fractal
1
Introduction to Lab5
2
3
Benoit Mandelbrot
• Mandelbrot was born in Poland in 1924.
• Father of fractal geometry.
• He showed how fractals can occur in many different places in both mathematics and elsewhere in nature.
What is a Fractal?Fractals are mathematical structures defined by two
properties– Iterative– Self-similar
• Zooming in or out on the image reveals deep repetition of patterns
4
The Mandelbrot Set
• The Mandelbrot set is a set of points in the complex plane, the boundary of which forms a fractal.
• Mathematically, the Mandelbrot set can be generated using a very simple iterative formula, called the quadratic recurrence equation, applied to points in complex plane
zn+1 = zn2 + c
That is, a complex number c, is in the Mandelbrot set if the absolute value of zn never exceeds a certain number.
5
6
The Mandelbrot Set
Pseudocode
for cy = -1 to 1, step 2/400 do
for cx = -2 to 1, step 3/600 do
{
zx = 0
zy = 0
iteration = 0
7
In the pseudocode below, c=cx+i·cy, corresponds to one pixel of the display region. The plotted region should have the following limits
-2 ≤ cx=Re[c] ≤ 1
-1 ≤ cy=Im[c] ≤ 1
Pseudocode Cont…
// z = z2 + c =
// =(zx2 – zy2 + cx) + i · (2 · zx · zy + cy)
while (zx2 + zy2 < 4 && iteration < MAX_ITER ){
zxtemp = zx2 – zy2 + cx
zytemp = 2 · zx · zy + cy
zx = zxtemp
zy = zytemp
iteration++
}
8
x = x_conv(cx) // conversion to the x-coordinate of a pixel
y = y_conv(cy) // conversion to the y-coordinate of a pixel
if zx2 + zy2 < 4
color(x,y) = fractal_color
else
color(x,y) = background_color
}
9
Pseudocode Cont…
x_conv() and y_convThe functions x_conv() and y_conv() are used to convert the coordinates of the complex number c into x and y coordinates of the pixel.
x = x_conv(cx) = 20 + (cx-(-2))*(600/3) = 20 + 200*(cx+2)
y = y_conv(cy) = 440 – (cy-(-1))*(400/2) = 440 - 200*(cy+1)
10
11
The magnification of the last image relative to the first one is about 10,000,000,000 to 1.
Fixed Point Representation• You can use Q4.28 representation
– 4 integer bits– 28 fractional bits
• Addition/Subtraction performed as usual
• Multiplication of two Q4.28 numbers results in a Q8.56 number, which should be converted back to Q4.28
12
VGA Display Area
• Use a rectangular area of the size (600 x 400) to display the Mandelbrot set fractal.
• Left and Right border = 20 pixels each
• Top and Bottom border = 40 pixels each
13
Cont..
• Top border should display “The Mandelbrot Set” in the center.
• Bottom border should display– Percentage of the display area, increasing
every 0.5%.– Progress bar – Total execution time with the step 0.1 s.
14
Input/Output Scheme
15
• Use BTNS as the Start/Pause button to start/pause the computations.
• The color of the fractal and background should also change, depending on the positions of switches
Final VGA Display Outlook
16
THE MANDELBROT SET
95.5% 33.1 s
Bonus Tasks
17
• Increase the speed of calculations, by evaluating 4 values of c in parallel.
• Determine the maximum speed-up possible by evaluating N values of c in parallel, where N is limited only by the available FPGA resources.
• Add colors by assigning a different color to each value of c, based on the number of iterations required for the decision based on the following formula:
color = iteration mod 8