Tutorial Number 12
Analyzing a Beam

Suppose one has been following a beam along a pair of simulated fibers which are close enough to each other for coupling. One wishes to watch the energy slosh back and forty and know the energy content of these simulated fibers and how much energy is lost. One would also wish to keep track of the effect of mode upon these processes and discover some things about the process.

We will start by opening the program in a 256x256 screen and placing a symbol list icon next to the start icon. We are going to make a square mask (square fibers??) so we compute a function which looks fort of like an inverted pyramid using the rescale icon's formula function. So opening the formula pane check the "use x" and "use y" boxes and insert the following in the "real part" field:abs(x+y)+abs(x-y).
Now place a "Truncate and so forth" icon next and its settings: value to 60, real part, from below, big array map (1,0). Follow this with a clip icon (put in big array from data connection) make the data connection add a display big array so you can check the progress so far, and run the script. You should see a square with corners at (-29,-29) and (29,29).

Now rearrange the icons to look like that below

Here's what going on with these icons. The "truncate and so forth" icon has been lifted to you can see it feed the same mask to three places in the script. The first yellow shifter icon shifts the square in the big array 31 pixels to the right. The shifted square is then captured by the clip icon next to it (we need it later). A new copy of the square is inserted with the put icon and a Hermite-Gauss function is inserted sigma = 16 vertical order is 2 and horizontal order is 1 (don't forget to check check the multiply box). The result is now shifted to the same location as the box was shifted. The result is saved at the right. Once again a box is entered into the middle. it is shifted to the left by 31 pixels. The new box is now saved for latter use and is also added to the first box to produce a pare of boxes. Check to see if all looks ok so far. You should see two black squares separated by 3 pixels.

we will use these two boxes to create a mask which will shape the beam. We will assume that we are looking down the two fibers of glass which have an index of refraction "n" and that as the beam progresses forward by a small step "step" and assuming a wave length "wl" that the phase will be advanced in these boxes by ph = 2*pi*(n-1)*step/wl. So to bring this about we open the "Symbol Defs" icon and define "n" as "1.3", "step" as "0.001"mm and "wl" as "0.5". We now replace the display again this time with a rescale icon and in the "quick calc" pane and in field one write "ph = 2*pi*(n-1)*step*1000/wl". The extra 1000 is to change the wave length from microns to millimeters. Don't forget to check the box in front of the field so that the value of ph will be added to the symbol list. Then, in the multiply real the box below put "ph" and in the "add imaginary" field enter 1. So up to now the imaginary part of the big array has been equal to zero we have just made all of the imaginary parts of all of the pixels "one". The real part of the big array should be zero except where the squares have been on the screen and there the value is the value of "ph". Check it out, and then add a "polar to rect" icon . If you now look at the contents of the big array you see that phase in the squares is -144 degrees, way too much, it looks more like a phase retarded, rather than advance. So either the step is too large of the phase shift is too large. Lets change the index. Open the "Symbol Defs" icon and change "n" to 1.05. Check it out. Thirty six degree phase shift looks good.

We capture this mask with a "clip" icon. We will use it on every step of our simulation. I put it to the left to give room for more icons.

Now we set up the Fourier space mask that we use in the propagation.
Place a lens function icon after the clip icon, open it, and click "ok symbols". In the yellow boxes enter "wl", "step", and "pitch" for the pixel pitch. Check the boxes in front of these fields. Make sure to define the symbol "pitch" in the "Symbol Defs." icon. Use 0.0002 to start. Check the "complex conjugate", "FT duel lens", and "non-paraxial" check boxes. Do not check "multiply big array". Put a clip icon in place to save this mask.

Now we build the core of the propagation loop. First we enter the saved Gauss function into the big array by placing a "clip" icon set to "Paste Big Array". The flow continues to a "Display" icon and continues in a loop returning to the "Display" icon. The loop contains "inverse Fourier", "clip" set to multiply big array, and "Fourier". It should sort of look like this. Notice that the loop will go forever. To stop click the "Stop, Single step" check box.

This works. You can see that after about 8,000 cycles the beam has been transferred pretty much from one square to the other. But one is dissatisfied with the lack of information about the process. What is the energy in each of the squares? What is the distance covered by the simulation? Are we losing energy in the calculation? can the process be improved? It sure is slow. And what about all the energy we see banging around outside of the boxes?
The last issue can be helped by noting that drawing to the screen is demanding of machine cycles. Lets put in a counter than only draws one in a hundred cycles on the screen. Put a branch icon between the bottom two icons. Have it go 99 times to the inverse Fourier transform icon for each alt branch to the display icon. To know how far we have traveled down the beam we introduce a variable "z" and monitor its progress.

So go to the first "rescale" icon right next to the "Symbol Defs" icon. In the first field of the "Quick calc" pane, click the check box and type "z = 0". This defines z and initializes its value and will enter it in the "symbol defs." icon. Since we all forget to return to the "formula" pane which should be front and active in order to make the function described above, click the check box at the bottom. Now place a "rescale" icon between the "display" and inverse Fourier icons. In the first field of the "Quick Calc" pane, Check the box and write "z=z+100*step" click the monitor button when the new window appears type "z" in the yellow field, close the "rescale" window and slide the little new window to a handy place. This will tell you of the progress in inits of mm.
Now we will add elements to monitor and record the energy content of the two boxes. By energy, I should tell you I mean the sum of the magnitude squared of all of the appropriate pixels. This is achieved cutting into the loop after the display icon saving the state of the big array going and doing some complicated stuff and coming back and restoring the saved state and continuing on.
Here is what we are going to add. You can see that it fits just to the right of the loop. It features the clip and put icons to referred to above. Following the flow of the script from the clip, we have a "paste big multiply" which comes from the clip icon which is the second before the "Gauss" icon and is the mask for the right hand square. The next icon makes the magnitude square of each icon. The result is real. The Fourier transform has the property that the pixel at the (0,0) position now holds the sum of all the pixels divided by N.
The next icon, on the bottom right, saves the energy to the variable "e1", you cause this to happen by going to the "quick calc" pane, clicking the box any of the numbered fields and entering in that field "e1=Rpt*N". Its hard to see the flow arrow but the next icon in the flow is the "put" icon above and to the left of the mag-square icon. It restores the state of the big array so that we can find the energy of the left square, which I call "e2", using the same steps. Besides "e1" you should define a new symbol "et=e1+e2". Click the box.
The "Save Symb." icon has several functions for this exercise we are using the third option "Add symbol values ...". (Notice that the icon changes from the blue of a file saving icon to green .) So now we should add some symbols. Type the symbols "z","e1","e2","et" separated by commas, return, or tab in the left text area. Check the box "Save Symbols as Column Headers". Run this script for a while. There is no need to close this window. It can be left open so you can watch developments. You should see 4 columns of numbers.
We should add one more icons to make a usable script. A way to stop the script. As you see below you add a "branch" icon set to branch at something like 50 or 200. There is no need to branch via a green connection to anything. The execution will just stop. Put this icon in place.


You can clip these data from the window in the usual way and paste them into a spread sheet like Numbers or Excel to be plotted.

This completes the first part of the tutorial but you can probably think of some extensions. You can see the opportunity to break out of the loop an any time to save an image if you wish by just inserting a branch icon. You may also choose to add another Save Symbol icon to save all of the symbols using option one of the selection buttons or a subset of the symbols using option two in the "Save Symbols" window. You may also have noticed that, if you close the script window by clicking the red button at the top left, The script runs much faster.

Part two: You may have noted that the energy total of the two fibers goes down a lot in just 2 cm you may wonder why this is so. Set the script to single step start it and advance it until the clip icon that follows the lens icon is highlighted. Now in the "view options" section of the main window click the pop-up menu and select magnitude. Note that the kernel function you are looking at is a circular plateau with a radius of about 100 that drops off rapidly to infinitesimal values beyond this edge. This is because of the pixel pitch of our grig is so much less than a wave length that the grid can represent features such a sharp edge that have a Fourier transform that exceeds what can be carried by this wave length of light. This is something that one does not encounter in the case of the paraxial approximation, but is all too real when we get down to small distances and the necessary non-paraxial calculation. The script above multiplies the field of numbers by a sharp edged phase mask on every cycle of the calculation which introduces some values at the edge of the Fourier plane which are thrown away by the kernel function.
We should modify this function so it does no do this by convolving the phase with a Gaussian with a half width of 1.3 wave lengths. So in "Symbol Defs." icon define a quantity "softSig" as "1.3". In the following "rescale" icon define a new variable (checking the box) as "Dsig = N*1000*pitch/(pi*wl*softSig)". [This "Dsig" is the half width of the Gaussian resulting from the Fourier transform if a Gaussian of half width "softSig".] This will be used in the convolution. To make room for this move the "polar to Rect" and the "display" icons to the side to make room for the convolution which is done by three icons. (F-1 Gauss F) Now open the new "Gauss" icon select the "OK symbols" and "multiply" check boxes and type "Dsig" in the yellow field. Run it. Here is what "Excel" did with the resulting data.

Right away you see that the coupling between the fibers has been reduced and that the energy is now, more nearly conserved. We can increase the coupling by reducing the index. We can test a whole series of index values softSig and separation distances (offset like 30,31,32,etc.)in an overnight run. Open excel and make a table (no headers, you just have to keep track of what you do here.) enter a column of values for trial indexes, another for softSig, and another for separation. Save this file as a CSV file. Now the changes to the script. Add two "Save Symbol" icons as shown below. In this upper click the first option to save all symbols. Give the file a name ending in #1. Go back to the lower icon and change its file name to also end in #1. Now add one more icon a "rescale" icon. Put it over next to the "Symbol Defs." icon. Open this icon to the "Quick Calc." pane and define "n=c1", "softSig=c2", and "shiftL=c3". Don't forget to check the boxes in front of these boxes. Go the the first "shift" icon open it click the "OK Symbols" button click the box before the x yellow field, and type "shiftL" in the box. Now we connect things up. Drag a flow line to the last icon you installed (a rescale icon) all the way across then to the very first rescale right after the symbol list. Connect the "Symbol Defs." icon to your new "rescale" icon. Before you run the script you need to change the last branching icon to make sure that it says branch after 200 and return after 1. Now it should run (after a lot of debugging), and give you a set of numbered files. You should run this overnight (depending on computer speed) making sure that a window of the program is visible on the screen and that all is running well.
This tutorial can be very educational. Especially if you make some variations in the parameters and break into the cycle between the Fourier transforms periodically to look at what is going on in Fourier space.