Time for another blog! :) For another exercise in AP186, our third activity covers the introduction to Scilab. I've been familiar with Scilab last semester because that is the programming language I used in AP185. We've been able to plot sinusoids, perform convolution and get its Fast Fourier transform, etc.. importing, getting information from sound file... I hope my little background on the said programming language could help me in the incoming "code" exercises throughout this semester. (cross finger) :)
For our practice, a code presented below was provided to create a centered circle. Figure below shows the output of the Scilab code execution. As an aperture, this synthetic image is useful in optics, one field of physics which is somewhat boring because there's endless lens and mirrors. different kinds and combination of them.. but, ironically, one topic that I enjoy because it is pretty geometric in approach and I love my high school geometry.. and it is relatively easier topic (I think) among all physics courses..
Now, we were asked to simulate the other synthetic images on our own. They were as follows:
- centered square aperture
- sinusoid along the x-direction (corrugated roof)
- grating along the x-direction
- annulus
- circular aperture with graded transparency (gaussian transparency)
Hmm..
okay, what to do? Of course, I need to understand the provided code first. Let’s
analyze the lines one by one. Up to line 3 were easy to understand. It is the
usual setting of range of values with the chosen number of points or interval.
Line 5 would be the equation of the circle. Line 6-7 would set the condition of
the part of the circle that would be color white and black represented in
matrix form with 0 equivalent to black and 1 equivalent to white. The remaining
lines would be responsible for the plotting.
Now, time
for coding! The Scilab Help Brower had been my best friend in this activity. Given
the code, the image that would be easy to do next is the annulus. The condition
must only be altered to choose the part of the matrix to be equal to 1. Same
was done for the square, just the equation of the circle could be omitted. The
difficult parts were the sinusoid, grating and aperture with graded
transparency.
I immediately
thought that for the grating, you could only just put all the conditions that
were needed. As you can see in the code at the end of the post, a long list can
be seen. However, I then thought that what if I would like different grating
width, very narrow widths. Then, I would need to have a long list. I planned on
making a loop instead but I think I would have no time.
I have
asked my classmates about this matter but my seatmate Anjali Tarun was also
experiencing the same problem. But then she thought of using the sine function
and that pretty much worked! So I thank Anjali Tarun for helping me understand
the advantage of the sine function to construct my code for grating. And
another thing is.. using the plot3d() function of Scilab, the grating code
would also result to the corrugated roof. For the circular aperture with the
graded transparency, I am acknowledging the help of Eric Limos, Nestor Bareza
and a lecture from the website of University of Ottawa*. Because combining all
the ideas that they provide me, I am able to have an equation of the Gaussian
function.
gauss = exp(-((X.^2)+(Y.^2))/(2.*(0.4^2)))
This would be a two-dimensional Gaussian function, centred at the
origin with r equal to 0.4. I am also thankful to Chester Balingit for teaching
me how to converge it to circular aperture to produce a graded transparency.
This also gave me the idea on how to do the exploration part of the activity. I
tried on subtracting square aperture from the circle and the result is shown in
the figure below. There, you can also see other image outputs.
You can get a grating by thresholding the sine function.
ReplyDeleteI like how you outline your thought process. Keep it up and good luck with the next activities.