Hi @Suved, glad it helped!
- The block layout, step by step
The idea is to split your current signal into two paths, scale each one, and add them back together:
Split the signal. Take your uncompensated current i(t) and branch it into two lines.
Path A (direct): connect the first branch to a Gain block set to cos(3°) = 0.99863.
Path B (derivative): connect the second branch to a Derivative block, then send its output to a second Gain block set to sin(3°)/ω. That’s 1.666e-4 at 50 Hz or 1.388e-4 at 60 Hz.
Add them. Connect both Gain outputs to a Sum block with two positive inputs (+, +).
Output. The Sum output is your compensated current, so that’s the signal you send to the amplifier channel.
Path A keeps almost all of the original signal, and Path B adds a small 90°-leading component. Together they give the 3° phase lead without any time delay.
- As a single reusable UCM block
Yes, a UCM works well here. Each instance has its own parameters and internal data, so you can create it once and place one copy on each current channel.
In HYPERSIM, click UCM → New UCM (UCM Builder) and give it a name, e.g. PhaseComp.
In General, set the UCM type to Command, since this is a control block, not a network component.
In Tunable Parameters, add f0 (frequency in Hz) and theta (compensation angle in degrees). That way you can adjust each instance from its parameter window.
In Control I/O, add one input i_in and one output i_out.
In Historical Values, add i_prev to store the previous sample. Historical values are computed at each time step and used in the next one, which is exactly what the derivative needs.
In Initialization Code, set i_prev = 0.0;
In After Nodes Voltage Calculation Code, add:
double PI_ = 3.14159265358979;
double th = theta * PI_ / 180.0;
double w = 2.0 * PI_ * f0;
double di_dt;
di_dt = (i_in - i_prev) / ucmTimeStep;
i_out = cos(th) * i_in + (sin(th) / w) * di_dt;
i_prev = i_in;
Save, then right-click the UCM and choose Update. If there’s a mistake in the code, the compiler will show an error.
Once it works, you can add more instances from the same .def file or add the UCM to your HYPERSIM library so it shows up in the component palette.
A couple of tips:
UCMs only support C89, so declare your variables at the top of the code block and define pi yourself, as in the example above.
Test one channel first in ScopeView. Compare i_in and i_out and check that the output leads by 3° with the same magnitude before you copy the block to the other channels.
Let me know how the frequency test goes! If the shift changes with frequency, that would confirm it’s a delay in the hardware path.