Current Signal Phase Shift Compensation in HYPERSIM

Hi,

We are using OPAL-RT, HYPERSIM along with an OPAL-RT amplifier hardware for voltage and current signal generation. We have observed a phase shift of approximately 3° between the voltage and current channels when using OPAL-RT HYPERSIM with the OPAL-RT amplifier. This observation has been confirmed across multiple voltage and current channels on the same device. We have also confirmed this observation with the OPAL-RT support team.

For example, HYPERSIM generates the following signals:

  • Voltage: 1 @ 0 deg
  • Current: 1 @ 0 deg

However, on the oscilloscope (Opal RT Amplifier), we observe:

  • Voltage: 1 @ 0 deg
  • Current: 1 @ -3 deg

To compensate for this phase shift, one possible approach is to multiply the final current signal by a unit-magnitude phasor with a compensating phase angle (e.g., +3°), without changing the current magnitude. If there is a better approach, please suggest it, ensuring that the phase compensation is applied without introducing any additional delay to the power system signals.

Could you please explain how to implement this multiplication in HYPERSIM, including the appropriate blocks, mathematical expressions, and block connections? A simple schematic or example would be helpful.

Thank you for your support.

Hello!

Did you know that in HYPERSIM the signals are instantaneous waveforms, not phasors, so you can’t multiply them by a unit phasor directly? A +3° shift on a waveform is really a small time advance (about 0.167 ms at 50 Hz or 0.139 ms at 60 Hz).

You could avoid adding delay by:

Option 1: Add the offset at the source (simplest)
If the current comes from a source block with a phase angle parameter, just set it to 0° + 3°. There’s no extra blocks and no delay.

Option 2: Compensate the signal itself
If the current comes from the network or a measurement, you can build the phase-shifted version from the signal and its derivative:

i_comp(t) = cos(3°) · i(t) + (sin(3°) / ω) · di/dt

With cos(3°) ≈ 0.99863, sin(3°) ≈ 0.05234 and ω = 2πf:

50 Hz: second gain ≈ 1.666e-4

60 Hz: second gain ≈ 1.388e-4

Block layout:

i(t) ──┬──► [Gain: 0.99863] ───────────────────┐
│ ├──► [Sum (+,+)] ──► i_comp ──► amplifier output
└──► [Derivative] ──► [Gain: sin3°/ω] ───┘

Based on my trial and errors before, I found that this is only true at the fundamental frequency though. Harmonics won’t get the right correction, and the derivative amplifies noise.

A 3° shift at every channel looks more like a fixed delay in the amplifier current path than a true phase offset. If so, the angle error will change with frequency. A quick test at a different frequency would confirm it. If it’s a delay, calibrating the hardware may be a better long-term fix than compensating in the model.

I hope this helps! Let me know how it goes :slight_smile:

@sorfina, Thanks for the solution. I understood the points. The first option is not useful for me, as I already have power system networks. I will try the second option and test it with different frequencies as well.

However, I did not clearly understand the block layout. Could you please explain it in more detail?

Also, is it possible to use a C-code block or UCM block to implement the same functionality, with all the required expressions included in a single block? The input would be the instantaneous current without phase compensation, and the output would be the phase-compensated current.

I have multiple current outputs from amplifiers, so having this functionality in a single reusable block would be very useful, as I could use multiple instances of the same block for different current signals.

Hi @Suved, glad it helped!

  1. 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.

  1. 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.

Thank you, @sorfina, for your efforts and helpful solutions. I understand now, and I’ll give it a try.

@Suved why does the amplifier have 3 degrees phase shift?