This example will demonstrate the MHKiT Power Module functionality to compute power, instantaneous frequency, and harmonics from time series of voltage and current.

We will begin by reading in timeseries data of measured three phase (a,b,and,c) voltage and current. The IEC TS 62600-30 requires that you perform power quality assessments on a minimum of 10-min timeseries data, but for this example we will only look at a fraction of that.

% Read in timeseries data of voltage (V) and current (I)

power_table = readtable('../examples/data/power/2020224_181521_PowRaw.csv');

power_table

To use the MHKiT-MATLAB power module we need to create structures of current and voltage.

current.time = posixtime(power_table.Time_UTC); %setting time in current structure

voltage.time = posixtime(power_table.Time_UTC); %setting time in voltage structure

T2 = mergevars(power_table,[2 3 4]); %combining the voltage time series into one table variable

T3 = mergevars(T2,[3 4 5]); %combining the current time series into one table variable

current.current = T3.Var3;

voltage.voltage = T3.Var2;

The MHKiT power characteristics submodule can be used to compute basic quantities of interest from voltage and current time series. In this example we will calculate active AC power and instantaneous frequency, using the loaded voltage and current timeseries.

To compute the active AC power, we will need the power factor. Power factor describes the efficiency of the energy device.

% Set the power factor for the system

power_factor = 0.96

power_factor = 0.9600

% Compute the instantaneous AC power in watts

ac_power = ac_power_three_phase(voltage, current, power_factor);

% Display the result

plot(ac_power.time,ac_power.power);

title('AC Power')

ylabel('Power [W]')

xlabel('Time')

Using the 3 phase voltage measurements we can compute the instantaneous frequency of the voltage timeseries. The time-varying instantaneous frequency is a required metric for power quality assessments.

inst_freq = instantaneous_frequency(voltage)

%Display the result

plot(inst_freq.time,inst_freq.frequency);

title('Instantaneous Frequency')

ylabel('Frequency [Hz]')

xlabel('Time')

ylim([0,100])

The power quality submodule can be used to compute harmonics of current and voltage and current distortions following IEC TS 62600-30 and IEC 61000-4-7. Harmonics and harmonic distortion are required as part of a power quality assessment and characterize the stability of the power being produced.

% Set the sampling frequency of the dataset

sample_freq = 50000 %[Hz]

sample_freq = 50000

% Set the frequency of the grid the device would be connected to

grid_freq = 60 %[Hz]

grid_freq = 60

% Set the rated current of the device

rated_current = 18.8 % [Amps]

rated_current = 18.8000

% Calculate the current harmonics

h = harmonics(current, sample_freq, grid_freq);

% display the results

plot(h.harmonic,h.amplitude);

title('Current Harmonics')

xlabel('Frequency [Hz]')

ylabel('Harmonic Amplitude')

xlim([0,900])

The harmonic subgroups calculations are based on IEC TS 62600-30. We can calculate them using our grid frequency and harmonics.

% Calculate Harmonic Subgroups

h_s = harmonic_subgroups(h,grid_freq)

Compute the THCD from harmonic subgroups and rated current for the device.

% Finally we can compute the total harmonic current distortion as a percentage

% for each channel

THCD = total_harmonic_current_distortion(h_s,rated_current)