Physics 6730 Assignment 8
For each of the following exercises create the specified files with
your answer(s). Submit your homework using the course submit
utility.
Exercise 1 The incomplete code
This exercise comes to us courtesy of Ben Bromley. In
~p6730/examples/a08 you should find an image file
arf.ppm (portable
pixel map format) that is viewable with the command xv
arf.ppm. We will be manipulating this image.
The purpose of this exercise and the follow-on next week is to
practice doing Fourier transform filtering, noise reduction, and
deconvolution of real-valued 2D data. Here we do a Gaussian smoothing
convolution of the image. This is a 2D filtering process analogous to
the one we did in 1D in Assignment 5. The incomplete code is in
arf.cc. To complete it you must read and understand the code,
of course, portions of which are found in the header files in
~p6730/include. In particular, please read through the header
files realft2d.h and ppm.h.
In a file arf.txt answer the following
questions about the Fourier transform and the code:
- What member functions of the class RealFt2d set and
extract the Fourier transform components?
- What do the two member functions inverse do, and in what
way are they different?
- List the class constructors and describe their differences.
- The Fourier components F(m,n) are specified by a pair of
integer indices m and n. Write the formula that defines
them in terms of the real data in the spatial domain f(x,y)
where x and y are also integers ranging over
[0,nx] and [0,ny], respectively.
- Write the reflection property that relates F(-m,-n) to
F(m,n). Write the periodicity property in both indices
m and n.
- Which Fourier components (m,n) are always real?
- Near the top of the file realft2d.h there is a rule for
traversing all the stored Fourier components once and only once.
Justify this rule in terms of the reflection and periodicity
properties.
- Use the template array class in ppm.h to write a
declaration that defines and initializes an integer array of dimension
10 x 5. Call it grayscale.
Exercise 2 Completing the code
In this exercise you are asked to complete the code arf.cc and a Makefile and it in.
This code uses routines defined in ppm.h to read the
.ppm image. This image is characterized by an 8-bit gray-scale
value in the range [0,255] for each pixel in a regular 512 x 512 grid.
Zero is black and 255 is white. The image is to be smoothed with a
gaussian filter function, given in coordinate space as
gfltr(x,y) = norm * exp(-(x*x+y*y)/(2*sig*sig))
where sig is supplied at run time and norm is calculated
so that the sum over all pixels is 1. Such a filter function could
represent a degradation of the image due to light scattering.
The smoothing is done by convolving the filter function with the
image. This operation is done by taking the 2D Fourier transform of
the image and of the filter function, multiplying the results, and
doing the inverse transform of the product to get the output image.
To complete the code, write the subprogram smooth and any
auxiliary subprograms you need for doing the filtering. Please be
sure you do the filtering operation on each Fourier transform point
once and only once. (See Exercise 1, part 7 above.)
When you run the code with the command
arf 3 < arf.ppm > arf_smooth.ppm
the original image should be as shown on the left and the smoothed
image as shown on the right below:
You should also try running your code with different values of
sig to check that it performs as expected.
Note that if you like, you may convert the PPM images to JPEG format
with the command
cjpeg arf.ppm > arf.jpg
Compression in this format reduces the file size considerably.
Exercise 3 Monte Carlo simulation of radioactive decay
In a Poisson process, such as a radioactive decay or in a uniform
random queuing process, the arrival intervals (times between successive
events) are distributed according to the exponential distribution
exp(-x/T)/T, where T is the mean lifettime, i.e. 1/T is
the mean decay rate. We would like to simulate such a process.
Please answer the following question in a file geiger.txt.
-
Suppose you have a random number generator that produces a random
number r uniformly distributed on the interval [0,1]. How can
you use it to generate a random number x distributed according
to P(x) = exp(-x/T)/T?
The exercise code ~p6730/exercises/nonlinear_optimization makes
use of the system random number generation routines to generate random
numbers on the interval [0,1]. Using the same procedure and the rule
you worked out above, write a short code geiger.cc (to be handed in) to generate a
sample of 20 random decay times with lifetime T. So we
can check your code, have it read the following three values from
standard input in precisely this order: (1) random number seed, (2)
mean lifetime, (3) number of events. For simplicity, omit the make
file this time. It should compile with the command make geiger.
Exercise 4 Jackknife error and bias
Here we use the jackknife method to look for sampling bias and
estimate errors in determining the decay rate from data generated by
your code in Exercise 3. Please put answers to the following
questions in a file jackknife.txt.
-
Run your code geiger with seed 27182 (to make it easier
to compare our results), mean lifetime 2, and 20 events. List your
results in the answer file.
-
Compute the mean decay rate and std deviation of the mean from your
sample and give the result in the answer file. The decay rate is 1/T
where T is the mean lifetime, computed by averaging your sample
lifetimes. You may use the course utility meansd, but notice
that it reports the population standard deviation. The simple error
in the mean decay rate is dT/T^2 where dT is the error in the mean
lifetime T.
-
In the directory ~p6730/exercises/jackknife you will find the script
jacksamples.sh which we used to generate
jackknife sampled masses. Modify this script so it reads your list of
decay times from a file, constructs the 20 single-elimination
jackknife samples, and for each, computes the mean and writes the
result for the estimated decay rate 1/T_mean. You should be able to
do this by deleting a few lines and modifying one line. Summarize
your results in the answer file. Hand in the script file.
-
Give the jackknife estimate of the error in the mean decay rate and
correct the sample mean decay rate for bias, based on the jackknife
analysis.
This page is maintained by:
Carleton DeTar Mail Form
Last modified 22 March 2004