Example: MHKiT-MATLAB Power Module

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

Load Power Data

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 timseries 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
power_table = 8000×7 table
 Time_UTCMODAQ_Va_VMODAQ_Vb_VMODAQ_Vc_VMODAQ_Ia_IMODAQ_Ib_IMODAQ_Ic_I
12020-02-24 18:15:21.4991.0653e+04-8.4994e+03-1.8502e+03-23.213719.21974.0234
22020-02-24 18:15:21.5001.0691e+04-8.4287e+03-1.9276e+03-23.404819.18174.2899
32020-02-24 18:15:21.5001.0733e+04-8.3650e+03-2.0013e+03-23.493019.03404.4789
42020-02-24 18:15:21.5001.0776e+04-8.3046e+03-2.0712e+03-23.680118.91784.8582
52020-02-24 18:15:21.5001.0818e+04-8.2481e+03-2.1380e+03-23.737918.70215.0925
62020-02-24 18:15:21.5001.0865e+04-8.2000e+03-2.2037e+03-23.825518.55885.3690
72020-02-24 18:15:21.5001.0912e+04-8.1529e+03-2.2702e+03-23.928518.40135.5463
82020-02-24 18:15:21.5001.0957e+04-8.1069e+03-2.3400e+03-24.025318.19025.9492
92020-02-24 18:15:21.5001.1005e+04-8.0655e+03-2.4124e+03-24.102617.99616.1678
102020-02-24 18:15:21.5001.1046e+04-8.0207e+03-2.4863e+03-24.138017.77976.3429
112020-02-24 18:15:21.5001.1086e+04-7.9779e+03-2.5630e+03-24.204117.59416.6670
122020-02-24 18:15:21.5001.1124e+04-7.9373e+03-2.6405e+03-24.223317.40306.9188
132020-02-24 18:15:21.5001.1158e+04-7.8944e+03-2.7206e+03-24.303417.18057.1620
142020-02-24 18:15:21.5001.1190e+04-7.8541e+03-2.8018e+03-24.363916.92927.4295
152020-02-24 18:15:21.5001.1220e+04-7.8125e+03-2.8836e+03-24.386616.70737.6768
162020-02-24 18:15:21.5001.1245e+04-7.7690e+03-2.9660e+03-24.385216.53117.8596
172020-02-24 18:15:21.5001.1269e+04-7.7270e+03-3.0465e+03-24.478316.27728.1371
182020-02-24 18:15:21.5001.1286e+04-7.6829e+03-3.1233e+03-24.531316.13438.3932
192020-02-24 18:15:21.5001.1298e+04-7.6355e+03-3.1966e+03-24.463215.85778.6317
202020-02-24 18:15:21.5001.1306e+04-7.5866e+03-3.2670e+03-24.467315.55568.8440
212020-02-24 18:15:21.5001.1312e+04-7.5334e+03-3.3364e+03-24.527115.36329.2194
222020-02-24 18:15:21.5001.1320e+04-7.4791e+03-3.4058e+03-24.571415.15769.3591
232020-02-24 18:15:21.5001.1329e+04-7.4227e+03-3.4750e+03-24.592414.96649.6088
242020-02-24 18:15:21.5001.1339e+04-7.3639e+03-3.5441e+03-24.659314.78749.8116
252020-02-24 18:15:21.5001.1353e+04-7.3021e+03-3.6155e+03-24.657614.578110.1309
262020-02-24 18:15:21.5001.1368e+04-7.2339e+03-3.6905e+03-24.680014.453010.2914
272020-02-24 18:15:21.5001.1382e+04-7.1585e+03-3.7691e+03-24.666314.206210.5458
282020-02-24 18:15:21.5001.1398e+04-7.0780e+03-3.8488e+03-24.704413.997810.7152
292020-02-24 18:15:21.5001.1411e+04-6.9911e+03-3.9284e+03-24.711313.760810.9294
302020-02-24 18:15:21.5001.1423e+04-6.9018e+03-4.0053e+03-24.741213.564811.1732
312020-02-24 18:15:21.5001.1434e+04-6.8092e+03-4.0801e+03-24.779513.366111.4186
322020-02-24 18:15:21.5001.1443e+04-6.7119e+03-4.1541e+03-24.804813.291511.5779
332020-02-24 18:15:21.5001.1451e+04-6.6147e+03-4.2247e+03-24.815513.148211.7207
342020-02-24 18:15:21.5001.1458e+04-6.5160e+03-4.2930e+03-24.833112.976711.8729
352020-02-24 18:15:21.5001.1464e+04-6.4165e+03-4.3596e+03-24.822512.931511.9789
362020-02-24 18:15:21.5001.1471e+04-6.3188e+03-4.4246e+03-24.947112.884812.0869
372020-02-24 18:15:21.5001.1479e+04-6.2206e+03-4.4902e+03-24.957412.823012.1796
382020-02-24 18:15:21.5001.1487e+04-6.1235e+03-4.5561e+03-25.001212.725412.2717
392020-02-24 18:15:21.5001.1495e+04-6.0297e+03-4.6208e+03-25.047012.753012.3463
402020-02-24 18:15:21.5001.1503e+04-5.9405e+03-4.6845e+03-25.134012.640212.4178
412020-02-24 18:15:21.5001.1513e+04-5.8587e+03-4.7460e+03-25.157212.586812.5110
422020-02-24 18:15:21.5001.1522e+04-5.7844e+03-4.8040e+03-25.187812.636912.6082
432020-02-24 18:15:21.5001.1531e+04-5.7181e+03-4.8606e+03-25.283712.463212.7040
442020-02-24 18:15:21.5001.1539e+04-5.6561e+03-4.9186e+03-25.282912.424912.7950
452020-02-24 18:15:21.5001.1545e+04-5.5974e+03-4.9799e+03-25.286312.347412.9219
462020-02-24 18:15:21.5001.1550e+04-5.5418e+03-5.0451e+03-25.324712.350613.0101
472020-02-24 18:15:21.5001.1552e+04-5.4872e+03-5.1142e+03-25.335212.227013.1120
482020-02-24 18:15:21.5001.1552e+04-5.4355e+03-5.1865e+03-25.413112.112613.1534
492020-02-24 18:15:21.5001.1548e+04-5.3851e+03-5.2615e+03-25.441012.129513.2445
502020-02-24 18:15:21.5001.1543e+04-5.3367e+03-5.3396e+03-25.392212.086813.2576
512020-02-24 18:15:21.5001.1536e+04-5.2901e+03-5.4189e+03-25.399311.998313.3228
522020-02-24 18:15:21.5011.1527e+04-5.2451e+03-5.4987e+03-25.396111.961513.3595
532020-02-24 18:15:21.5011.1515e+04-5.2010e+03-5.5780e+03-25.348811.852313.4286
542020-02-24 18:15:21.5011.1503e+04-5.1600e+03-5.6545e+03-25.277611.830413.4387
552020-02-24 18:15:21.5011.1487e+04-5.1195e+03-5.7281e+03-25.338411.658213.5370
562020-02-24 18:15:21.5011.1470e+04-5.0791e+03-5.7995e+03-25.296511.476413.6861
572020-02-24 18:15:21.5011.1451e+04-5.0381e+03-5.8681e+03-25.231611.334113.8100
582020-02-24 18:15:21.5011.1428e+04-4.9938e+03-5.9347e+03-25.159111.146213.8940
592020-02-24 18:15:21.5011.1405e+04-4.9482e+03-6.0003e+03-25.104410.950514.0143
602020-02-24 18:15:21.5011.1382e+04-4.8997e+03-6.0641e+03-25.052210.838914.2155
612020-02-24 18:15:21.5011.1358e+04-4.8487e+03-6.1279e+03-25.045010.521414.3179
622020-02-24 18:15:21.5011.1336e+04-4.7959e+03-6.1921e+03-24.884510.338714.5830
632020-02-24 18:15:21.5011.1316e+04-4.7395e+03-6.2570e+03-24.870910.038314.7072
642020-02-24 18:15:21.5011.1298e+04-4.6811e+03-6.3231e+03-24.89069.779814.9129
652020-02-24 18:15:21.5011.1283e+04-4.6197e+03-6.3910e+03-24.76209.524515.1219
662020-02-24 18:15:21.5011.1270e+04-4.5532e+03-6.4617e+03-24.74009.263615.3487
672020-02-24 18:15:21.5011.1258e+04-4.4823e+03-6.5341e+03-24.72059.046515.6204
682020-02-24 18:15:21.5011.1245e+04-4.4063e+03-6.6069e+03-24.68778.771515.7678
692020-02-24 18:15:21.5011.1230e+04-4.3255e+03-6.6806e+03-24.67018.589615.9981
702020-02-24 18:15:21.5011.1215e+04-4.2392e+03-6.7546e+03-24.56188.348816.1249
712020-02-24 18:15:21.5011.1196e+04-4.1451e+03-6.8299e+03-24.54968.098616.2978
722020-02-24 18:15:21.5011.1178e+04-4.0475e+03-6.9068e+03-24.48417.904116.5192
732020-02-24 18:15:21.5011.1158e+04-3.9455e+03-6.9833e+03-24.44847.703116.6232
742020-02-24 18:15:21.5011.1137e+04-3.8386e+03-7.0602e+03-24.41857.551916.7686
752020-02-24 18:15:21.5011.1117e+04-3.7316e+03-7.1351e+03-24.36947.368916.9392
762020-02-24 18:15:21.5011.1097e+04-3.6247e+03-7.2071e+03-24.39967.214216.9936
772020-02-24 18:15:21.5011.1077e+04-3.5178e+03-7.2762e+03-24.43057.147117.1100
782020-02-24 18:15:21.5011.1058e+04-3.4132e+03-7.3423e+03-24.36377.039817.2627
792020-02-24 18:15:21.5011.1039e+04-3.3109e+03-7.4052e+03-24.40446.895117.3674
802020-02-24 18:15:21.5011.1022e+04-3.2103e+03-7.4672e+03-24.41996.750617.5273
812020-02-24 18:15:21.5011.1007e+04-3.1120e+03-7.5284e+03-24.45916.654117.6572
822020-02-24 18:15:21.5011.0992e+04-3.0154e+03-7.5891e+03-24.48176.496317.8372
832020-02-24 18:15:21.5011.0978e+04-2.9224e+03-7.6491e+03-24.47886.401818.0164
842020-02-24 18:15:21.5011.0963e+04-2.8329e+03-7.7089e+03-24.49266.222118.1677
852020-02-24 18:15:21.5011.0950e+04-2.7473e+03-7.7699e+03-24.45856.055118.2639
862020-02-24 18:15:21.5011.0937e+04-2.6644e+03-7.8322e+03-24.48685.952818.4097
872020-02-24 18:15:21.5011.0922e+04-2.5838e+03-7.8962e+03-24.43475.805718.5172
882020-02-24 18:15:21.5011.0905e+04-2.5051e+03-7.9618e+03-24.51775.688218.6681
892020-02-24 18:15:21.5011.0885e+04-2.4257e+03-8.0294e+03-24.42505.562618.6293
902020-02-24 18:15:21.5011.0860e+04-2.3456e+03-8.0991e+03-24.34955.452618.8066
912020-02-24 18:15:21.5011.0834e+04-2.2666e+03-8.1713e+03-24.27465.328518.8754
922020-02-24 18:15:21.5011.0803e+04-2.1851e+03-8.2447e+03-24.30735.204218.8963
932020-02-24 18:15:21.5011.0772e+04-2.1036e+03-8.3201e+03-24.24455.079219.0266
942020-02-24 18:15:21.5011.0740e+04-2.0236e+03-8.3952e+03-24.10374.912019.1286
952020-02-24 18:15:21.5011.0706e+04-1.9445e+03-8.4670e+03-24.08454.747819.2107
962020-02-24 18:15:21.5011.0676e+04-1.8700e+03-8.5373e+03-24.01724.541019.2795
972020-02-24 18:15:21.5011.0643e+04-1.7965e+03-8.6031e+03-23.93424.351719.3480
982020-02-24 18:15:21.5011.0612e+04-1.7260e+03-8.6662e+03-23.78334.232919.4351
992020-02-24 18:15:21.5011.0584e+04-1.6566e+03-8.7287e+03-23.63103.944219.5543
1002020-02-24 18:15:21.5011.0557e+04-1.5868e+03-8.7916e+03-23.52663.711219.5857
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;

Power Characteristics

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 instantneous frequency, using the loaded voltage and current timeseries.
To compute the active AC power, we will need the power factor. Power factor describes the efficency 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')

Instantaneous Frequency

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)
inst_freq = struct with fields:
frequency: [7999×3 double] time: [7999×1 double]
%Display the result
plot(inst_freq.time,inst_freq.frequency);
title('Instantaneous Frequency')
ylabel('Frequency [Hz]')
xlabel('Time')
ylim([0,100])

Power Quality

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 conected 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])

Harmonic Subgroups

The harmonic subgroups calculations are based on IEC TS 62600-30. We can clculate them using our grid frequency and harmonics.
% Calcualte Harmonic Subgroups
h_s = harmonic_subgroups(h,grid_freq)
h_s = struct with fields:
amplitude: [51×3 double] harmonic: [0 60 120 180 240 300 360 420 480 540 600 660 720 780 840 900 960 1020 1080 1140 1200 1260 1320 1380 1440 1500 1560 1620 1680 1740 1800 1860 1920 1980 2040 2100 2160 2220 2280 2340 2400 2460 2520 2580 2640 2700 2760 2820 2880 2940 3000]

Total Harmonic Current Distortion

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)
THCD = 1×3
8.9725 6.0966 5.9295