# Scripted element implementing 2x2 coupler does not seem to behave properly

#1

I have created a 2x2 scripted coupler to get familiar with the scripted elements.
However, when comparing with the native coupler from the interconnect library, the readings on the powermeters are a bit off:

When I check the transfer matrix values from within the script, I get the correct phase and amplitude.
Do you have any idea of what could have gone wrong?

The test I am running looks like this:

Please find below the full script used in the coupler

# Initialize tranfer matrix
freqs = [1.90950610191e+14, 1.95942783007e+14];
nb_freqs = length(freqs);
T = coupling;
R = 1-T;
r = sqrt(R);
t = sqrt(T);
amplitudes = zeros(4, 4);

amplitudes(1, 3) = r;
amplitudes(1, 4) = t;
amplitudes(2, 3) = t;
amplitudes(2, 4) = r;

amplitudes(3, 1) = r;
amplitudes(4, 1) = t;
amplitudes(3, 2) = t;
amplitudes(4, 2) = r;

# Phase matrix (non-dispersive)
phases = zeros(4, 4);
phases(1, 4) = pi/2;
phases(2, 3) = pi/2;
phases(4, 1) = pi/2;
phases(3, 2) = pi/2;

# Transfer matrix elements
trans11=zeros(nb_freqs, 3);
trans12=zeros(nb_freqs, 3);
trans13=zeros(nb_freqs, 3);
trans14=zeros(nb_freqs, 3);
trans21=zeros(nb_freqs, 3);
trans22=zeros(nb_freqs, 3);
trans23=zeros(nb_freqs, 3);
trans24=zeros(nb_freqs, 3);
trans31=zeros(nb_freqs, 3);
trans32=zeros(nb_freqs, 3);
trans33=zeros(nb_freqs, 3);
trans34=zeros(nb_freqs, 3);
trans41=zeros(nb_freqs, 3);
trans42=zeros(nb_freqs, 3);
trans43=zeros(nb_freqs, 3);
trans44=zeros(nb_freqs, 3);

trans11(:,1)=freqs;
trans12(:,1)=freqs;
trans13(:,1)=freqs;
trans14(:,1)=freqs;

trans21(:,1)=freqs;
trans22(:,1)=freqs;
trans23(:,1)=freqs;
trans24(:,1)=freqs;

trans31(:,1)=freqs;
trans32(:,1)=freqs;
trans33(:,1)=freqs;
trans34(:,1)=freqs;

trans41(:,1)=freqs;
trans42(:,1)=freqs;
trans43(:,1)=freqs;
trans44(:,1)=freqs;

## AMPLITUDES
trans11(:,2)=amplitudes(1,1);
trans12(:,2)=amplitudes(1,2);
trans13(:,2)=amplitudes(1,3);
trans14(:,2)=amplitudes(1,4);

trans21(:,2)=amplitudes(2,1);
trans22(:,2)=amplitudes(2,2);
trans23(:,2)=amplitudes(2,3);
trans24(:,2)=amplitudes(2,4);

trans31(:,2)=amplitudes(3,1);
trans32(:,2)=amplitudes(3,2);
trans33(:,2)=amplitudes(3,3);
trans34(:,2)=amplitudes(3,4);

trans41(:,2)=amplitudes(4,1);
trans42(:,2)=amplitudes(4,2);
trans43(:,2)=amplitudes(4,3);
trans44(:,2)=amplitudes(4,4);

## Phases
trans41(:, 3)= phases(4,1);
trans14(:, 3)= phases(1,4);
trans23(:, 3)= phases(2,3);
trans32(:, 3)= phases(3,2);

# PORT MAPPING
setsparameter("port 1", "port 1", "transmission", trans11);
setsparameter("port 1", "port 2", "transmission", trans12);
setsparameter("port 1", "port 3", "transmission", trans13);
setsparameter("port 1", "port 4", "transmission", trans14);

setsparameter("port 2", "port 1", "transmission", trans21);
setsparameter("port 2", "port 2", "transmission", trans22);
setsparameter("port 2", "port 3", "transmission", trans23);
setsparameter("port 2", "port 4", "transmission", trans24);

setsparameter("port 3", "port 1", "transmission", trans31);
setsparameter("port 3", "port 2", "transmission", trans32);
setsparameter("port 3", "port 3", "transmission", trans33);
setsparameter("port 3", "port 4", "transmission", trans34);

setsparameter("port 4", "port 1", "transmission", trans41);
setsparameter("port 4", "port 2", "transmission", trans42);
setsparameter("port 4", "port 3", "transmission", trans43);
setsparameter("port 4", "port 4", "transmission", trans44);


#2

Hi @damien,

The script has no problem and the power meters measure different result because there is a delay at the beginning of the signal for the Scripted Element. The post list below talks about this into details:

Basically, the power meter measures the average results over the whole time window and the Scripted Element has a delay before it outputs the results.

Hope this makes sense.

#3

thank you @gwang,

I understand the behaviour better now.

Have just looked at my scripted coupler delay using the optical scope. It looks like it has about 80ps delay (which is rather large for an photonic component).

I have also cascaded several of them to check that this is not a delay artifact at the beginning of the simulation.

Is there any way to remove or overwrite this default delay in my scripted component?

Many thanks,

Damien

#4

Hi @damien,

Sorry for the late reply. The delay is caused by the digital filter used in the Scripted Element. When the Scripted Element is defined by a S-Parameter, a digital filter will be used to convert the frequency domain element into time domain, and added Ntaps/2 samples delay in the simulation. The element does the convergence test by itself and choose the number of taps for the filter automatically, so the number of taps used for the digital filter is different for different models. In our case, the number of taps used is 256 taps.

That said, it is not possible to eliminate the delay totally, but you can tweak the delay time by changing the time domain settings (sample period especially). Unfortunately the number of taps is set by Scripted Element automatically and we cannot change this number.