problem in interpolation while writing script.



Hi Can somebody help in interpolation ?

I have a parameter sweep results in file. And I want to use the sweep results to interpolate the phase value. I have script to calculate phase value using some formula. Now I want to get corresponding width value from the phase angle graph of the s-parameter (S12 angle value from parametric sweep results).

I would love to use spline interpolation. Probabily, the main problem is for loop. Because it is not similar to matlab. Its showing some error. So unable to move further. I found one for loop example on Lumerical webpage, but for my case, its showing error.

for(i=1:100) {
for(j=1:100) {
x(i,j) = i^2+j;

When, I am using its showing error.

Square_Si.lsf (1.0 KB)
Square_Si.fsp (300.2 KB)


Hi @visvas, Looking at your script one thing that I would recommend is to use the same unit for length for all variables (meter). Another thing that need to be modified is that you need to initialize any matrix before you can assign values to its elements. So before you can assign values to “phase(j,i)” you will need to initialize the matrix like this:

phase = matrix(length(x),length(y));

I also noticed some possible typo in the expression to calculate “phase(i,j)”. My guess is that it should look like this:

phase(j,i) = (2*pi/lambda)*sqrt((x(i)^2+y(j)^2+f_length^2)-f_length);

Finally, use the command “mod” to calculate the residual while normalizing the phase

phase(j,i) = mod(phase(j,i),6.24);

Please make these updates and let me know if you still have errors.


So, we need to define a variable of same size before to use it in loop. :slight_smile:

I think you are right, all units must be same in meter. So, I did it. Now we have phase values matrix.
So, could you please tell how to "Pinch"or get sweep results to get angle of S12 data ? And finally to get equavalent width with interpolation.
Square_Si.lsf (1.2 KB)


You need to use the command “getsweepresult” to get the data from a sweep. In your script, therefore, you can use the following lines to read and plot the angles of the s parameters:

s_params = getsweepresult("square_sweep","s_parameter"); S11 = s_params.S12; S22 = s_params.S22; width = s_params.width; plot(width,angle(S11),angle(S22));

You can learn about the use of the “pinch” command here:


Hi @aalam, First of all, thanks for help. Infact it is too basic, but still you did not loose your patience. :slight_smile:
Infact, I am beginner in script programming. So, its almost done. Now its little making me confuse. First things, when I am seeing phase from results monitor, this is a linear graph from 0 to lets say some 7.8. See figure;

But, when I am collecting results from the monitor (getsweepdata), the phase is from 0 to 3 (probably 3.14 = Pi) to and -3 (-Pi) and so on.

So I guess this is phase rolling and phase unrolling issues. So my questios is about interpolation. In this case, I guess interpolation will not be correct. So any simple way to see the results in same format, so interpolation will be in correct form.

Square_Si.lsf (1.7 KB)


Hi @visvas, you are most welcome. It is hard to get started with a new scripting language and I’d he happy to provide any help necessary for you to get started. Whenever you are looking for some information on any script command, try searching for it in the KB seach.

Regarding the different values of the phase you are right, the reason the phase from the script looks different is because it only plots the phase between -pi to +pi. Good news is that we have a script command that can unwrap this data and give you the one you see in the sweep result view. I myself wasn’t aware of this script command and thanks a lot to @fgomez for showing this to me! Simply use the following script command to plot the angle and you should get the same plot: