For the second activity in Applied Physics 186, we are asked to familiarize ourselves with programming with Scilab. Scilab is a much more user-friendly programming language with almost the same capability as that of Matlab. In this activity, we are asked to plot 5 synthetic images namely; centered square aperture, sinusoid along the x-direction(corrugated roof),grating along the x-direction, annulus, and
circular aperture with graded transparency (gaussian transparency). My codes are listed below;
//circle
nx=100;ny=100;
//x=linspace(-1,1,nx);
//y=linspace(-1,1,ny);
//[X,Y]=ndgrid(x,y);
//r=sqrt(X.^2 + Y.^2);
//A =zeros(nx,ny);
//A (find(r<0.7))=1;
//imshow(A,[]);
//imwrite(A,’Circle.jpg’);
//square
//x=linspace(-1,1,nx);
//y=linspace(-1,1,ny);
//[X,Y] = ndgrid(x,y);
//z=100;
//C=zeros(nx,ny);
//C(nx/2-z:ny/2+z,ny/2-z:ny/2+z)=1;
//imshow(C,[]);
//imwrite(C,’Square.jpg’);
//sinusoid
//x = linspace(-10,10,nx);
//y = linspace(-10,10,ny);
//[X,Y] = ndgrid(x,y);
//f = 7*%pi;
//E = sin(X.*f);
//imshow(E, []);
//imwrite(E,’Sinusoid.jpg’);
//grating
//x=linspace(-20,20,nx);
//y=linspace(-20,20,ny);
//[X,Y]=ndgrid(x,y);
//Y=sin(X);
//D = zeros(nx,ny);
//D(find(Y<0.10))=1;
//imshow(D,[]);
//imwrite(D,’Grating.jpg’);
//annulus
//x = linspace(-1,1,nx);
//y = linspace(-1,1,ny);
//[X,Y] = ndgrid(x,y);
//r=sqrt(X.^2 + Y.^2);
//B=zeros(nx,ny);
//B(find(r<0.7))=1;
//B(find(r<0.4))=0;
//imshow(B,[]);
//imwrite(B,’Annulus.jpg’);
//circular aperture with graded transparency
//x = linspace(-1,1,nx);
//y = linspace(-1,1,ny);
//[X,Y] = ndgrid(x,y);
//R=sqrt(X.^2+Y.^2);
//F = exp(-3*R);
//imshow(F,[]);
//imwrite(F,’Circular Aperture with graded transparency.jpg’);
To run the code the double slash should be removed for each corresponding plot.
The plots are shown in the following figures;
The centered circular plot is the given example for this activity. he radius of the aperture is 0.7. However to obtain a more resolved graph, the number of elements can be varied.
This second figure is a more challenging image to plot. It was actually the second to the hardest (next to the Gaussian Transparency). The formula is more complicated as shown in the code for the square graph.
This is the plot of a corrugated roof using the sine function. The formula used was sin(X.*f), where f is the frequency which defines the number of corrugation in the plot. For this plot it was set to 7pi.
This plot is somewhat similar to the previous plot, I also used sine function to produce the gratings. I just used the formula Y= sin(X) , however, for this, the mechanism for changing the number of gratings is different.
The image above is an annulus. The algorithm is a lot similar to centered circuar aperture but another aperture was added in zeros to block the portion of the bigger circle. The radii used are 0.7 and 0.3 The fatness of the doughnut will be determined by the difference of the assigned radii.
The last image is definitely the hardest to plot. An exponential function was used for this. It took me a long time to decipher what to do, with the help of some classmates.
All in all, this is an enjoying activity to do, especially if the Scilab easily worked with the SIP toolbox on the first time of trial. It is rather frustrating to be stocked at some poit. I rate myself 9 for this activity, since I think some of my codes are wrong although they produce the desired graph. I would thank Millicent Singson, Celestino Borja, and Kaye Ann de las Alas for their valuable assistane to this activity.