# Power Module

The power module contains a set of functions to calculate quantities of interest for power production and power quality.

Note

The names of the functions below are of the convention `path.path.function`. Only the function name is used when calling the function in MATLAB. For example, to call on `mhkit.wave.io.read_NDBC_file` simply use `read_NDBC_file`.

## Characteristics

The characteristics submodule calculates power quantities of interest from voltage and current timseries.

Functions

Description

`instantaneous_frequency`

Calculates instantaneous frequency of measured voltage

`dc_power`

Calculates the real power from DC voltage and current.

`ac_power_three_phase`

Calculates the real power from three phase ac voltage and current.

mhkit.power.characteristics.ac_power_three_phase(voltage, current, power_factor, varargin)

Calculates the real power from three phase ac voltage and current.

Parameters:
• voltage (`Time series of all three measured voltages [V]`) –

Pandas data frame

To make a pandas data frame from user supplied frequency and spectra use py.mhkit_python_utils.pandas_dataframe.spectra_to_pandas(time,voltage)

OR

structure of form:

voltage.voltage : matrix of all three phases

voltage.time : time vector

• current (`Time series of all three measured current [A]`) –

Pandas data frame

To make a pandas data frame from user supplied frequency and spectra use py.mhkit_python_utils.pandas_dataframe.spectra_to_pandas(time,current)

OR

structure of form:

current.current : matrix of all three phases

current.time : time vector

power_factorfloat

power factor for the system

line_to_line: bool (Optional)

set true if the given voltage measurement is line_to_line

Returns:

P (Structure)

P.power [W]

P.time

mhkit.power.characteristics.dc_power(voltage, current)

Calculates the real power from DC voltage and current.

Parameters:
• voltage (`Time series of  measured voltages [V]`) –

Pandas data frame

To make a pandas data frame from user supplied frequency and spectra use py.mhkit_python_utils.pandas_dataframe.spectra_to_pandas(time,voltage)

OR

structure of form:

voltage.voltage : matrix or vector

voltage.time : time vector

• current (`Time series of current [A]`) –

Pandas data frame

To make a pandas data frame from user supplied frequency and spectra use py.mhkit_python_utils.pandas_dataframe.spectra_to_pandas(time,current)

OR

structure of form:

current.current : matrix or vector

current.time : time vector

Returns:

P (Structure)

P.power [W]

P.gross: gross power from all lines [W]

P.time

mhkit.power.characteristics.instantaneous_frequency(voltage)

Calculates the instantaneous frequency of a measured voltage

Parameters:

um (`structure with handles- um.voltage and um.time`) – measured voltage source (V) with each timeseries in its own column

Returns:

frequency (structure) – frequency of the measured voltage with handles frequency.time and frequency.frequency

## Quality

The quality submodule functions assess power quality, including harmonics, interharmonics, and distortion. Calculations are based on IEC TS 62600-30:2018 ED1 and IEC TS 61000-4-7:2008 ED2.

Functions

Description

`harmonics`

Calculates the harmonics from time series of voltage or current based on IEC 61000-4-7.

`harmonic_subgroups`

Calculates the harmonic subgroups based on IEC 61000-4-7

`total_harmonic_current_distortion`

Calculates the total harmonic current distortion (THC) based on IEC/TS 62600-30

`interharmonics`

Calculates the interharmonics from the harmonics of current

mhkit.power.quality.harmonics(x, freq, grid_freq)

Calculates the harmonics from time series of voltage or current based on IEC 61000-4-7.

Parameters:
• x (`structure with x.time and x.current or x.voltage as values`) – Time-series of voltage [V] or current [A]

• freq (`double`) – Frequency of the time-series data [Hz]

• grid_freq (`int`) – Value indicating if the power supply is 50 or 60 Hz. Options = 50 or 60

Returns:

harmonics (structure) – harmonic amplitude and frequency of the time-series data

mhkit.power.quality.calc_shortterm_flicker_severity(P)

Calculates short-term flicker severity P_st according to the IEC 61000-4-15(ed2.0) section 5.7.2 Short-term flicker evaluation.

Parameters:

P (`struct()`) – contains fields of flicker levels exceeded for . percent of the time. P.p0p7, P.p1, P.p1p5: flicker levels exceeded for 0.7%, 1%, and 1.5% of the time. P.p2p2, P.p3, P.p4: flicker levels exceeded for 2.2%, 3%, and 4% of the time. P.p6, P.p8, P.p10, P.p13, P.p17: flicker levels exceeded for 6%, 8%, 10%, 13%, 17% of the time. P.p30, P.p50, P.p80: flicker levels exceeded for 30%, 50%, and 80% of the time.

Returns:

P_st (double array of size dtime/10min) – One flicker emission value on the fictitious grid for each 10 min time-series of u_fic(t).

Note

1. Unless otherwise specified, the Pst evaluation time is 10min. For the

purpose of power quality surveys and studies, other time intervals may be used, and should be defined in the index. For example a 1 min interval should be written as P_st,1m.

2. The suffix ‘_s’ indicates the smoothed values and obtained following the equations specified in section 5.7.2:

P_50s = (P_30+P_50+P_80)/3.; P_10s = (P_6+P_8+P_10+P_13+P_17)/5.; P_3s = (P_2.2+P_3+P_4)/3.; P_1s = (P_0.7+P_1+P_1.5)/3.;

mhkit.power.quality.total_harmonic_current_distortion(harmonic_subgroups, rated_current)

Calculates the total harmonic current distortion (THC) based on IEC/TS 62600-30

Parameters:
• harmonic_subgroups (`structure with handles- harmonic_subgroups.amplitude and harmonic_subgroups.harmonic`) – Subgrouped current harmonics amplitude indexed by harmonic order

• rated_current (`double`) – Rated current of the energy device in Amps

Returns:

THCD (double) – Total harmonic current distortion

mhkit.power.quality.calc_ideal_voltage(Un, alpha_m)

Calculates the ideal phase-to-neutral voltage source (V) u0(t)

according to IECTS 62600-30(ed1.0) Eq (2).

u0(t) should: 1) be without any fluctuations; 2) have the same electrical angle (alpha_m) as the fundamental of the measured voltage (u_m).

Un: double

RMS value of the nominal voltage of the grid (V).

alpha_m: double array (ntime)

Electrical angle of the fundamental component of u_m(t)

u0: double array (ntime)

Ideal phase-to-neutral voltage source (V).

1. According to the IECTS-62600-30(ed1.0) Eq (2):

u0(t) = sqrt(2/3)*Un*sin(alpha_m(t)).

IECTS 62600-30(ed1.0) Eq (2)

mhkit.power.quality.flicker_ufic_workflow(Sr, Un, SCR, fg, u_m, i_m, method, methodopts)

Conduct flicker assessment according to IECTS62600-30 and IECTS61400-21-1. A workflow of MATLAB functions up to calculation of u_fic.

Parameters:
• Sr (`double`) – Rated apparent power of the marine energy converter (VA).

• Un (`double`) – RMS value of the nomianal voltage of the grid (V).

• SCR (`double`) – Short-circuit ratio, SCR = S_kfic/Sr

• fg (`double`) – Nominal grid frequency, 60Hz or 50Hz

• u_m (`struct()`) – u_m(t) is the measured instantaneous voltage (V) .time: time at each measurement (s) .data: array of size (ntime) measured instantaneous voltage (V).

• i_m (`struct()`) – i_m(t) is the measured instantaneous current (A) .time: time at each measurement .data: array of size (ntime, 4) measured instantaneous current (A) at impedance phase angles = 30, 50, 70, 85.

• method (`string`) – Method used to calculate fundamental frequency of u_m, ‘zcd’ or ‘stft’

• methodopts (`cell array`) – Name-value arguments for STFT method, if using ‘ZCD’ method, can set to {}.

Returns [Lfic,Rfic,alpha0,freq,alpha_m,u0,u_fic] ——-

out: struct()

output a MATLAB struct() that contains u_fic and all the intermediate variables, including:

.Lfic: double array (4)

fictitious grid inductance (H) for Phi_k = 30, 50, 70, 85.

.Rfic: double array (4)

fictitious grid resistance (Ohm) for Phi_k = 30, 50, 70, 85.

.alpha0: double

.freq: struct()

.time: time at each measurement time step (s) .data: double array of size (ntime), freq(t), the fundamental frequency calculated for u_m(t).

.alpha_m: double array (ntime)

Electrical angle (alpha_m(t)) of the fundamental component of u_m(t)

.u0: double array (ntime)

Ideal phase-to-neutral voltage source u0(t) (V)

.u_fic: double array (ntime,4)

Instantaneous phase-to-neutral voltage simulated at fictitious grid (V) for impedence angles = 30, 50, 70, 85

Note

Step 1. Construct the fictitious grid by calculating Rfic and Lfic.

[Rfic,Lfic]=calc_Rfic_Lfic(Sr,SCR,Un,fg)

Step 2. Calculate ideal voltahe source (u0) from measured voltage (u_m).
Step 2.1 Calculate the fundamental frequency and alpha_0 of u_m

[alpha0,freq] = calc_fundamental_freq(u_m,method,methodopts)

Step 2.2 Calculate the electrical angle (alpha_m)

alpha_m = calc_electrical_angle(freq,alpha0)

Step 2.3 Calculate the ideal voltage (u0)

u0=calc_ideal_voltage(Un,alpha_m)

Step 3. Calculate simulated voltage (u_fic) for the fictitious grid

u_fic=calc_simulated_voltage(u0,i_m,Rfic,Lfic)

mhkit.power.quality.gen_test_data(Un, In, fg, fs, fm, fv, DeltaI_I, opt, T)

Generate test data according to IEC61400-21-1 Annex B.3 to be used for the verification test of the measurement procedure for flicker.

Parameters:
• Un (`double`) – RMS value of the nominal voltage of the grid (V).

• In (`double`) – Nominal current (A).

• fg (`double`) – Nominal grid frequency, 60Hz or 50Hz

• fs (`double`) – Sampling frequency (Hz).

• fm (`double`) – Modulating frequency for current.

• fv (`double`) – Modulating frequency for voltage used in B.3.4. The test is divided into 60 different cases, with fν in [0.5:0.5:30].

• DeltaI_I (`double array (4)`) – Relative current changes (%) according to Table B.2 and Table B.3 in IECTS61400-21-1.

• opt (`int`) – Option number used to indicate different test datasets.

• T (`double`) – Duration (s) of the generated u_m and i_m.

Returns:

• u_m (struct()) – u_m(t) is the measured instantaneous voltage (V) .time: time at each measurement (s) .data: array of size (ntime) measured instantaneous voltage (V).

• i_m (struct()) – i_m(t) is the measured instantaneous current (A) .time: time at each measurement .data: array of size (ntime, 4) measured instantaneous current (A) at impedance phase angles = 30, 50, 70, 85.

Note

1. Options (opt=0,[2,5]) opt = 0: Pure sine wave i_m and u_m with alpha0=pi/6. opt = 2 - 5 B.3.2 Fictitious grid performance testing, pure sine wave for u_m B.3.3 Distorted u_m with multiple zero crossings B.3.4 Distorted u_m with inter-harmonic modulation B.3.5 Slow frequency changes

mhkit.power.quality.harmonic_subgroups(harmonics, grid_freq)

Calculates the harmonic subgroups from the harmonics of current

Parameters:
• harmonics (`structure with handles- harmonics.amplitude and harmonics.harmonic`) – harmonic amplitude with each timeseries in its own column

• grid_freq (`int`) – value indicating if the power supply is 50 or 60 Hz. Valid input are 50 and 60

Returns:

harmonic_subgroups (structure with handles harmonic_subgroups.amplitude and) – harmonic_subgroups.harmonic

mhkit.power.quality.calc_Rfic_Lfic(Sr, SCR, Un, fg)

Calculates resistance (Rfic, Ohm) and inductance (Lfic, H) of the fictitious grid according to IECTS-62600-30 Eq (4-5).

Parameters:
• Sr (`double`) – Rated apparent power of the marine energy converter (VA).

• SCR (`double`) – Short-circuit ratio, SCR = S_kfic/Sr. To obtain simulated voltage fluctuations within the flickermeter range, an SCR of [20,50] is recommended (ref: IECTS62600-30(ed1.0) pg 24).

• Un (`double`) – RMS value of the nominal voltage of the grid (V).

• fg (`double`) – Nominal grid frequency, 50Hz or 60Hz

Returns:

• Rfic (double array (4)) – fictitious grid resistance (Ohm) for the impedance phase angle (Phi_k) equals to 30, 50, 70, and 85 (degrees).

• Lfic (double array (4)) – fictitious grid inductance (H) for Phi_k = 30, 50, 70, 85.

Note

Phi_k: network impedance phase angle (degree)

The flicker index should be reported for Phi_k=30, 50, 70, 85. (refs: IECTS62600-30(ed1.0) Annex A Table A.6)

Eqs from IECTS62600-30
SCR, short-circuit ratio:

SCR = S_kfic/Sr (pg24)

S_kfic, short-circuit apparent power (VA):

S_kfic = Un^2/sqrt(Rfic^2+X_fic^2) (Eq5)

Phi_k, network impedance phase angle:

tan(Phi_k) = X_fic/Rfic = 2*pi*fg*Lfic/Rfic (Eq4)

X_fic, reactance of fictitious grid (Ohm)

Therefore, we have:

sqrt{Rfic^2+[Rfic*tan(Phi_k)]^2} = Un^2/S_k,fic –>> Rfic = Un^2/{S_kfic*sqrt[1+tan(Phi_k)^2]} & Lfic = Rfic*tan(Phi_k)/(2pi*fg)

mhkit.power.quality.calc_simulated_voltage(u0, i_m, Rfic, Lfic)

Calculates the simulated voltage at a fictitious grid according to IEC standard 62600-30(ed1.0) Eq (1).

Parameters:
• u0 (`double array of size (ntime)`) – Ideal phase-to-neutral voltage source u0(t) (V).

• i_m (`struct()`) – i_m(t) is the measured instantaneous current (A) .time: time at each measurement .data: array of size (ntime, 4) measured instantaneous current (A) at impedance phase angles Phi_k = 30, 50, 70, 85.

• Rfic (`double array of size (4)`) – Fictitious grid resistance (Ohm) for Phi_k = 30, 50, 70, 85.

• Lfic (`double array of size (4)`) – Fictitious grid inductance (H) for Phi_k = 30, 50, 70, 85.

Returns:

u_fic (double array (ntime,4)) – Instantaneous phase-to-neutral voltage simulated at fictitious grid (V) for Phi_k = 30, 50, 70, 85

Note

1. ufic(t) = u0(t)+Rfic*im(t)+Lfic*dim(t)/dt (Eq1, IECTS62600-30)

mhkit.power.quality.calc_electrical_angle(freq, alpha0)

Calculates the electrical angle alpha_m(t) of the fundamental of the

measured voltage (u_m(t)) according to IECTS 62600-30(ed1.0) Eq (3).

Parameters:
• alpha0 (`double`) – Electrical angle (radians) at t=0.

• freq (`struct()`) – .time: time at each measurement time step (s) .data: double array of size (ntime), freq(t), the fundamental frequency (that may vary over time) for u_m(t).

Returns:

alpha_m (double array (ntime)) – Electrical angle (alpha_m(t)) of the fundamental component of u_m.

Note

1. IECTS-62600-30 Eq(3):

alpha_m(t) = 2pi*integral(freq(t)dt)+alpha0

mhkit.power.quality.interharmonics(harmonics, grid_freq)

Calculates the interharmonics from the harmonics of current based on IEC 61000-4-7.

Parameters:
• harmonics (`structure with handles- harmonics.amplitude and harmonics.harmonic`) – Harmonic amplitude with each timeseries in its own column

• grid_freq (`int`) – Value indicating if the power supply is 50 or 60 Hz. Options = 50 or 60

Returns:

interharmonics (structure with handles interharmonics.amplitude and) – interharmonics.harmonic

mhkit.power.quality.calc_fundamental_freq(u_m, method, methodopts)

Calculates the fundamental frequency of the measured voltage u_m(t) using Zero-Crossing-Detection (ZCD) or Short-Time Fourier Transform (STFT).

Parameters:
• u_m (`struct()`) – .time: time for each time step; .data: array of size (ntime), measured voltage (V) with instantaneous values u_m(t).

• method (`string (case-insensitive)`) – can be either ‘zcd’ or ‘stft’. ‘zcd’: Zero-Crossing-Detection method ‘stft’: Short-Time Fourier Transform method

• methodopts (`cell array`) –

Name-value arguments for STFT, e.g., opts = {‘Window’,rectwin(M),’OverlapLength’,L,

’FFTLength’,Nfrq,’FrequencyRange’,’onesided’}

if using ‘ZCD’ method, can set to {}.

Returns:

• freq (struct()) – .time: time at each measurement time step (s) .data: double array of size (ntime), freq(t), the fundamental frequency (that may vary over time) calculated for u_m(t).

• alpha0 (double) – The electrical angle (radians) at t=0.

Note

1. Window settings are crucial to get accurate results if Short-Time Fourier Transform (STFT) is used to calculate the frequency. 2. Steps:

Step1. adjust time values Step2. Estimate fundamental freq using either STFT or ZCD Step3. Interpolate estimated freq back to u_m.time

mhkit.power.quality.calc_flicker_coefficient(P_stfic, S_kfic, Sr)

Calculates the flicker coefficient c(Phi_k) for each set of the 10 min measured voltage and current time-series, using the calculated flicker emission values using IECTS-62600-30 Eq (6).

Parameters:
• P_stfic (`double`) – short-term flicker severity (Pst) (flicker emission value) on the fictitious grid.

• S_kfic (`double`) – Short-circuit apparent power (VA) of the fictitious grid. S_kfic = Un^2/sqrt(Rfic^2+X_fic^2) (Eq5)

• SCR (`double`) –

Short-circuit ratio:

SCR = S_kfic/Sr (pg24)

• Sr (`double`) – Rated apparent power (VA) of the marine energy converter unit.

Returns:

coef_flicker (double) – Flicker coefficient for continuous operation

Note

1. According to IECTS62600-30 Eq (6):

c(Phi_k) = P_stfic*S_kfic/Sr