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 time-series 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 time-series data, but for this example we will only look at a fraction of that.
% Read in time-series 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_UTC | MODAQ_Va_V | MODAQ_Vb_V | MODAQ_Vc_V | MODAQ_Ia_I | MODAQ_Ib_I | MODAQ_Ic_I |
|---|
| 1 | 2020-02-24 18:15:21.499 | 1.0653e+04 | -8.4994e+03 | -1.8502e+03 | -23.2137 | 19.2197 | 4.0234 |
|---|
| 2 | 2020-02-24 18:15:21.500 | 1.0691e+04 | -8.4287e+03 | -1.9276e+03 | -23.4048 | 19.1817 | 4.2899 |
|---|
| 3 | 2020-02-24 18:15:21.500 | 1.0733e+04 | -8.3650e+03 | -2.0013e+03 | -23.4930 | 19.0340 | 4.4789 |
|---|
| 4 | 2020-02-24 18:15:21.500 | 1.0776e+04 | -8.3046e+03 | -2.0712e+03 | -23.6801 | 18.9178 | 4.8582 |
|---|
| 5 | 2020-02-24 18:15:21.500 | 1.0818e+04 | -8.2481e+03 | -2.1380e+03 | -23.7379 | 18.7021 | 5.0925 |
|---|
| 6 | 2020-02-24 18:15:21.500 | 1.0865e+04 | -8.2000e+03 | -2.2037e+03 | -23.8255 | 18.5588 | 5.3690 |
|---|
| 7 | 2020-02-24 18:15:21.500 | 1.0912e+04 | -8.1529e+03 | -2.2702e+03 | -23.9285 | 18.4013 | 5.5463 |
|---|
| 8 | 2020-02-24 18:15:21.500 | 1.0957e+04 | -8.1069e+03 | -2.3400e+03 | -24.0253 | 18.1902 | 5.9492 |
|---|
| 9 | 2020-02-24 18:15:21.500 | 1.1005e+04 | -8.0655e+03 | -2.4124e+03 | -24.1026 | 17.9961 | 6.1678 |
|---|
| 10 | 2020-02-24 18:15:21.500 | 1.1046e+04 | -8.0207e+03 | -2.4863e+03 | -24.1380 | 17.7797 | 6.3429 |
|---|
| 11 | 2020-02-24 18:15:21.500 | 1.1086e+04 | -7.9779e+03 | -2.5630e+03 | -24.2041 | 17.5941 | 6.6670 |
|---|
| 12 | 2020-02-24 18:15:21.500 | 1.1124e+04 | -7.9373e+03 | -2.6405e+03 | -24.2233 | 17.4030 | 6.9188 |
|---|
| 13 | 2020-02-24 18:15:21.500 | 1.1158e+04 | -7.8944e+03 | -2.7206e+03 | -24.3034 | 17.1805 | 7.1620 |
|---|
| 14 | 2020-02-24 18:15:21.500 | 1.1190e+04 | -7.8541e+03 | -2.8018e+03 | -24.3639 | 16.9292 | 7.4295 |
|---|
| 15 | 2020-02-24 18:15:21.500 | 1.1220e+04 | -7.8125e+03 | -2.8836e+03 | -24.3866 | 16.7073 | 7.6768 |
|---|
| 16 | 2020-02-24 18:15:21.500 | 1.1245e+04 | -7.7690e+03 | -2.9660e+03 | -24.3852 | 16.5311 | 7.8596 |
|---|
| 17 | 2020-02-24 18:15:21.500 | 1.1269e+04 | -7.7270e+03 | -3.0465e+03 | -24.4783 | 16.2772 | 8.1371 |
|---|
| 18 | 2020-02-24 18:15:21.500 | 1.1286e+04 | -7.6829e+03 | -3.1233e+03 | -24.5312 | 16.1343 | 8.3932 |
|---|
| 19 | 2020-02-24 18:15:21.500 | 1.1298e+04 | -7.6355e+03 | -3.1966e+03 | -24.4632 | 15.8577 | 8.6317 |
|---|
| 20 | 2020-02-24 18:15:21.500 | 1.1306e+04 | -7.5866e+03 | -3.2670e+03 | -24.4673 | 15.5556 | 8.8440 |
|---|
| 21 | 2020-02-24 18:15:21.500 | 1.1312e+04 | -7.5334e+03 | -3.3364e+03 | -24.5271 | 15.3632 | 9.2194 |
|---|
| 22 | 2020-02-24 18:15:21.500 | 1.1320e+04 | -7.4791e+03 | -3.4058e+03 | -24.5714 | 15.1576 | 9.3591 |
|---|
| 23 | 2020-02-24 18:15:21.500 | 1.1329e+04 | -7.4227e+03 | -3.4750e+03 | -24.5924 | 14.9664 | 9.6088 |
|---|
| 24 | 2020-02-24 18:15:21.500 | 1.1339e+04 | -7.3639e+03 | -3.5441e+03 | -24.6593 | 14.7874 | 9.8116 |
|---|
| 25 | 2020-02-24 18:15:21.500 | 1.1353e+04 | -7.3021e+03 | -3.6155e+03 | -24.6576 | 14.5781 | 10.1309 |
|---|
| 26 | 2020-02-24 18:15:21.500 | 1.1368e+04 | -7.2339e+03 | -3.6905e+03 | -24.6800 | 14.4530 | 10.2914 |
|---|
| 27 | 2020-02-24 18:15:21.500 | 1.1382e+04 | -7.1585e+03 | -3.7691e+03 | -24.6663 | 14.2062 | 10.5458 |
|---|
| 28 | 2020-02-24 18:15:21.500 | 1.1398e+04 | -7.0780e+03 | -3.8488e+03 | -24.7044 | 13.9978 | 10.7152 |
|---|
| 29 | 2020-02-24 18:15:21.500 | 1.1411e+04 | -6.9911e+03 | -3.9284e+03 | -24.7113 | 13.7608 | 10.9294 |
|---|
| 30 | 2020-02-24 18:15:21.500 | 1.1423e+04 | -6.9018e+03 | -4.0053e+03 | -24.7412 | 13.5648 | 11.1732 |
|---|
| 31 | 2020-02-24 18:15:21.500 | 1.1434e+04 | -6.8092e+03 | -4.0801e+03 | -24.7795 | 13.3661 | 11.4186 |
|---|
| 32 | 2020-02-24 18:15:21.500 | 1.1443e+04 | -6.7119e+03 | -4.1541e+03 | -24.8048 | 13.2915 | 11.5779 |
|---|
| 33 | 2020-02-24 18:15:21.500 | 1.1451e+04 | -6.6147e+03 | -4.2247e+03 | -24.8155 | 13.1482 | 11.7207 |
|---|
| 34 | 2020-02-24 18:15:21.500 | 1.1458e+04 | -6.5160e+03 | -4.2930e+03 | -24.8331 | 12.9767 | 11.8729 |
|---|
| 35 | 2020-02-24 18:15:21.500 | 1.1464e+04 | -6.4165e+03 | -4.3596e+03 | -24.8225 | 12.9315 | 11.9789 |
|---|
| 36 | 2020-02-24 18:15:21.500 | 1.1471e+04 | -6.3188e+03 | -4.4246e+03 | -24.9471 | 12.8848 | 12.0869 |
|---|
| 37 | 2020-02-24 18:15:21.500 | 1.1479e+04 | -6.2206e+03 | -4.4902e+03 | -24.9574 | 12.8230 | 12.1796 |
|---|
| 38 | 2020-02-24 18:15:21.500 | 1.1487e+04 | -6.1235e+03 | -4.5561e+03 | -25.0012 | 12.7254 | 12.2717 |
|---|
| 39 | 2020-02-24 18:15:21.500 | 1.1495e+04 | -6.0297e+03 | -4.6208e+03 | -25.0470 | 12.7530 | 12.3463 |
|---|
| 40 | 2020-02-24 18:15:21.500 | 1.1503e+04 | -5.9405e+03 | -4.6845e+03 | -25.1340 | 12.6402 | 12.4178 |
|---|
| 41 | 2020-02-24 18:15:21.500 | 1.1513e+04 | -5.8587e+03 | -4.7460e+03 | -25.1572 | 12.5868 | 12.5110 |
|---|
| 42 | 2020-02-24 18:15:21.500 | 1.1522e+04 | -5.7844e+03 | -4.8040e+03 | -25.1878 | 12.6369 | 12.6082 |
|---|
| 43 | 2020-02-24 18:15:21.500 | 1.1531e+04 | -5.7181e+03 | -4.8606e+03 | -25.2837 | 12.4632 | 12.7040 |
|---|
| 44 | 2020-02-24 18:15:21.500 | 1.1539e+04 | -5.6561e+03 | -4.9186e+03 | -25.2829 | 12.4249 | 12.7950 |
|---|
| 45 | 2020-02-24 18:15:21.500 | 1.1545e+04 | -5.5974e+03 | -4.9799e+03 | -25.2863 | 12.3474 | 12.9219 |
|---|
| 46 | 2020-02-24 18:15:21.500 | 1.1550e+04 | -5.5418e+03 | -5.0451e+03 | -25.3247 | 12.3506 | 13.0101 |
|---|
| 47 | 2020-02-24 18:15:21.500 | 1.1552e+04 | -5.4872e+03 | -5.1142e+03 | -25.3352 | 12.2270 | 13.1120 |
|---|
| 48 | 2020-02-24 18:15:21.500 | 1.1552e+04 | -5.4355e+03 | -5.1865e+03 | -25.4131 | 12.1126 | 13.1534 |
|---|
| 49 | 2020-02-24 18:15:21.500 | 1.1548e+04 | -5.3851e+03 | -5.2615e+03 | -25.4410 | 12.1295 | 13.2445 |
|---|
| 50 | 2020-02-24 18:15:21.500 | 1.1543e+04 | -5.3367e+03 | -5.3396e+03 | -25.3922 | 12.0868 | 13.2576 |
|---|
| 51 | 2020-02-24 18:15:21.500 | 1.1536e+04 | -5.2901e+03 | -5.4189e+03 | -25.3993 | 11.9983 | 13.3228 |
|---|
| 52 | 2020-02-24 18:15:21.501 | 1.1527e+04 | -5.2451e+03 | -5.4987e+03 | -25.3961 | 11.9615 | 13.3595 |
|---|
| 53 | 2020-02-24 18:15:21.501 | 1.1515e+04 | -5.2010e+03 | -5.5780e+03 | -25.3488 | 11.8523 | 13.4286 |
|---|
| 54 | 2020-02-24 18:15:21.501 | 1.1503e+04 | -5.1600e+03 | -5.6545e+03 | -25.2776 | 11.8304 | 13.4387 |
|---|
| 55 | 2020-02-24 18:15:21.501 | 1.1487e+04 | -5.1195e+03 | -5.7281e+03 | -25.3384 | 11.6582 | 13.5370 |
|---|
| 56 | 2020-02-24 18:15:21.501 | 1.1470e+04 | -5.0791e+03 | -5.7995e+03 | -25.2965 | 11.4764 | 13.6861 |
|---|
| 57 | 2020-02-24 18:15:21.501 | 1.1451e+04 | -5.0381e+03 | -5.8681e+03 | -25.2316 | 11.3341 | 13.8100 |
|---|
| 58 | 2020-02-24 18:15:21.501 | 1.1428e+04 | -4.9938e+03 | -5.9347e+03 | -25.1591 | 11.1462 | 13.8940 |
|---|
| 59 | 2020-02-24 18:15:21.501 | 1.1405e+04 | -4.9482e+03 | -6.0003e+03 | -25.1044 | 10.9505 | 14.0143 |
|---|
| 60 | 2020-02-24 18:15:21.501 | 1.1382e+04 | -4.8997e+03 | -6.0641e+03 | -25.0522 | 10.8389 | 14.2155 |
|---|
| 61 | 2020-02-24 18:15:21.501 | 1.1358e+04 | -4.8487e+03 | -6.1279e+03 | -25.0450 | 10.5214 | 14.3179 |
|---|
| 62 | 2020-02-24 18:15:21.501 | 1.1336e+04 | -4.7959e+03 | -6.1921e+03 | -24.8845 | 10.3387 | 14.5830 |
|---|
| 63 | 2020-02-24 18:15:21.501 | 1.1316e+04 | -4.7395e+03 | -6.2570e+03 | -24.8709 | 10.0383 | 14.7072 |
|---|
| 64 | 2020-02-24 18:15:21.501 | 1.1298e+04 | -4.6811e+03 | -6.3231e+03 | -24.8906 | 9.7798 | 14.9129 |
|---|
| 65 | 2020-02-24 18:15:21.501 | 1.1283e+04 | -4.6197e+03 | -6.3910e+03 | -24.7620 | 9.5245 | 15.1219 |
|---|
| 66 | 2020-02-24 18:15:21.501 | 1.1270e+04 | -4.5532e+03 | -6.4617e+03 | -24.7400 | 9.2636 | 15.3487 |
|---|
| 67 | 2020-02-24 18:15:21.501 | 1.1258e+04 | -4.4823e+03 | -6.5341e+03 | -24.7205 | 9.0465 | 15.6204 |
|---|
| 68 | 2020-02-24 18:15:21.501 | 1.1245e+04 | -4.4063e+03 | -6.6069e+03 | -24.6877 | 8.7715 | 15.7678 |
|---|
| 69 | 2020-02-24 18:15:21.501 | 1.1230e+04 | -4.3255e+03 | -6.6806e+03 | -24.6701 | 8.5896 | 15.9981 |
|---|
| 70 | 2020-02-24 18:15:21.501 | 1.1215e+04 | -4.2392e+03 | -6.7546e+03 | -24.5618 | 8.3488 | 16.1249 |
|---|
| 71 | 2020-02-24 18:15:21.501 | 1.1196e+04 | -4.1451e+03 | -6.8299e+03 | -24.5496 | 8.0986 | 16.2978 |
|---|
| 72 | 2020-02-24 18:15:21.501 | 1.1178e+04 | -4.0475e+03 | -6.9068e+03 | -24.4841 | 7.9041 | 16.5192 |
|---|
| 73 | 2020-02-24 18:15:21.501 | 1.1158e+04 | -3.9455e+03 | -6.9833e+03 | -24.4484 | 7.7031 | 16.6232 |
|---|
| 74 | 2020-02-24 18:15:21.501 | 1.1137e+04 | -3.8386e+03 | -7.0602e+03 | -24.4185 | 7.5519 | 16.7686 |
|---|
| 75 | 2020-02-24 18:15:21.501 | 1.1117e+04 | -3.7316e+03 | -7.1351e+03 | -24.3694 | 7.3689 | 16.9392 |
|---|
| 76 | 2020-02-24 18:15:21.501 | 1.1097e+04 | -3.6247e+03 | -7.2071e+03 | -24.3996 | 7.2142 | 16.9936 |
|---|
| 77 | 2020-02-24 18:15:21.501 | 1.1077e+04 | -3.5178e+03 | -7.2762e+03 | -24.4305 | 7.1471 | 17.1100 |
|---|
| 78 | 2020-02-24 18:15:21.501 | 1.1058e+04 | -3.4132e+03 | -7.3423e+03 | -24.3637 | 7.0398 | 17.2627 |
|---|
| 79 | 2020-02-24 18:15:21.501 | 1.1039e+04 | -3.3109e+03 | -7.4052e+03 | -24.4044 | 6.8951 | 17.3674 |
|---|
| 80 | 2020-02-24 18:15:21.501 | 1.1022e+04 | -3.2103e+03 | -7.4672e+03 | -24.4199 | 6.7506 | 17.5273 |
|---|
| 81 | 2020-02-24 18:15:21.501 | 1.1007e+04 | -3.1120e+03 | -7.5284e+03 | -24.4591 | 6.6541 | 17.6572 |
|---|
| 82 | 2020-02-24 18:15:21.501 | 1.0992e+04 | -3.0154e+03 | -7.5891e+03 | -24.4817 | 6.4963 | 17.8372 |
|---|
| 83 | 2020-02-24 18:15:21.501 | 1.0978e+04 | -2.9224e+03 | -7.6491e+03 | -24.4788 | 6.4018 | 18.0164 |
|---|
| 84 | 2020-02-24 18:15:21.501 | 1.0963e+04 | -2.8329e+03 | -7.7089e+03 | -24.4926 | 6.2221 | 18.1677 |
|---|
| 85 | 2020-02-24 18:15:21.501 | 1.0950e+04 | -2.7473e+03 | -7.7699e+03 | -24.4585 | 6.0551 | 18.2639 |
|---|
| 86 | 2020-02-24 18:15:21.501 | 1.0937e+04 | -2.6644e+03 | -7.8322e+03 | -24.4868 | 5.9528 | 18.4097 |
|---|
| 87 | 2020-02-24 18:15:21.501 | 1.0922e+04 | -2.5838e+03 | -7.8962e+03 | -24.4347 | 5.8057 | 18.5172 |
|---|
| 88 | 2020-02-24 18:15:21.501 | 1.0905e+04 | -2.5051e+03 | -7.9618e+03 | -24.5177 | 5.6882 | 18.6681 |
|---|
| 89 | 2020-02-24 18:15:21.501 | 1.0885e+04 | -2.4257e+03 | -8.0294e+03 | -24.4250 | 5.5626 | 18.6293 |
|---|
| 90 | 2020-02-24 18:15:21.501 | 1.0860e+04 | -2.3456e+03 | -8.0991e+03 | -24.3495 | 5.4526 | 18.8066 |
|---|
| 91 | 2020-02-24 18:15:21.501 | 1.0834e+04 | -2.2666e+03 | -8.1713e+03 | -24.2746 | 5.3285 | 18.8754 |
|---|
| 92 | 2020-02-24 18:15:21.501 | 1.0803e+04 | -2.1851e+03 | -8.2447e+03 | -24.3073 | 5.2042 | 18.8963 |
|---|
| 93 | 2020-02-24 18:15:21.501 | 1.0772e+04 | -2.1036e+03 | -8.3201e+03 | -24.2445 | 5.0792 | 19.0266 |
|---|
| 94 | 2020-02-24 18:15:21.501 | 1.0740e+04 | -2.0236e+03 | -8.3952e+03 | -24.1037 | 4.9120 | 19.1286 |
|---|
| 95 | 2020-02-24 18:15:21.501 | 1.0706e+04 | -1.9445e+03 | -8.4670e+03 | -24.0845 | 4.7478 | 19.2107 |
|---|
| 96 | 2020-02-24 18:15:21.501 | 1.0676e+04 | -1.8700e+03 | -8.5373e+03 | -24.0172 | 4.5410 | 19.2795 |
|---|
| 97 | 2020-02-24 18:15:21.501 | 1.0643e+04 | -1.7965e+03 | -8.6031e+03 | -23.9342 | 4.3517 | 19.3480 |
|---|
| 98 | 2020-02-24 18:15:21.501 | 1.0612e+04 | -1.7260e+03 | -8.6662e+03 | -23.7833 | 4.2329 | 19.4351 |
|---|
| 99 | 2020-02-24 18:15:21.501 | 1.0584e+04 | -1.6566e+03 | -8.7287e+03 | -23.6310 | 3.9442 | 19.5543 |
|---|
| 100 | 2020-02-24 18:15:21.501 | 1.0557e+04 | -1.5868e+03 | -8.7916e+03 | -23.5266 | 3.7112 | 19.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 fundamental frequency, using the loaded voltage and current time-series.
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
% Compute the instantaneous AC power in watts
ac_power = ac_power_three_phase(voltage, current, power_factor);
figure('Position', [100, 100, 1600, 600]);
plot(datetime(ac_power.time, "ConvertFrom", "posixtime"), ac_power.power);
Fundamental Frequency
Using the 3 phase voltage measurements we can compute the fundamental frequency of the voltage time-series. The time-varying fundamental frequency is a required metric for power quality assessments. The function calc_fundamental_freq() provides two options of calculating the fundamental frequency: 1. Short-Time Fourier Transform (STFT) 2. Zero-Crossing Detection (ZCD) Here we illustrate the steps in both ways.
First, let's look at the STFT method. Note that, to obtain an accurate result, window settings for STFT is crucial, the user might need some exploratory analysis and try different sets of parameters.
Note: The STFT method requires the Signal Processing Toolbox
% Hilbert method: instantaneous_frequency
% inst_freq = instantaneous_frequency(voltage)
% Check for Signal Processing Toolbox
if license('test', 'Signal_Toolbox')
'Window', int32(5000), ...
'OverlapLength', 3750, ...
'FrequencyRange', 'onesided'
fund_freq.time = voltage.time;
fund_freq.data = zeros(size(voltage.voltage));
u_m.data = voltage.voltage(:,i);
[~, freq] = calc_fundamental_freq(u_m, 'stft', methodopts);
fund_freq.data(:,i) = freq.data;
figure('Position', [100, 100, 1600, 600]);
plot(datetime(fund_freq.time, "ConvertFrom", "posixtime"), fund_freq.data);
title('Fundamental Frequency: STFT');
ylabel('Frequency [Hz]');
warning('Signal Processing Toolbox is not installed. Skipping STFT analysis...');
end
Warning: Signal Processing Toolbox is not installed. Skipping STFT analysis...
Now, let's look at the ZCD method. Note that, ZCD method may not work for conditions of distorted voltage with multiple zero-crossings, like the one stated in IEC TS 61400-21-1 B.3.3. As stated above, exploratory analysis is needed.
fund_freq.time = voltage.time;
fund_freq.data = zeros(size(voltage.voltage));
% For the zcd method, we don't need to worry about the method options
u_m.data = voltage.voltage(:,i);
[~, freq] = calc_fundamental_freq(u_m, 'zcd', methodopts);
fund_freq.data(:,i) = freq.data;
fund_freq
fund_freq =
time: [8000×1 double]
data: [8000×3 double]
figure('Position', [100, 100, 1600, 600]);
plot(datetime(fund_freq.time, "ConvertFrom", "posixtime"), fund_freq.data);
title('Fundamental Frequency: ZCD');
ylabel('Frequency [Hz]');
Power Quality
The power quality submodule can be used to compute voltage fluctuations, 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. Specifically, we focus on the flicker coefficient for continuous operation (MV connected systems), which is a normalized measure of the flicker emission during continuous operation of the MEC unit.
% Set the sampling frequency of the dataset
sample_freq = 50000; % [Hz]
% Set the frequency of the grid the device would be connected to
% Set the rated current of the device
rated_current = 18.8; % [Amps]
% Calculate the current harmonics
h = harmonics(current, sample_freq, grid_freq);
figure('Position', [100, 100, 1600, 600]);
plot(h.harmonic, h.amplitude);
title('Current Harmonics');
xlabel('Frequency [Hz]');
ylabel('Harmonic Amplitude');
Harmonic Subgroups
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);
Total Harmonic Current Distortion (THCD)
Compute the THCD from harmonic subgroups and rated current for the device.
% Finally we can compute the total harmonic current distortion as a percentage
THCD = total_harmonic_current_distortion(h_s, rated_current);
Flicker Assessment
Calculate the flicker coefficient following the steps in IEC TS 62600-30 section 7.2.1: MV connected marine energy converters.
1. Calculate the simulated voltage of the fictitious grid (u_fic). There are two options for calculation of u_fic.
First, the user can use flicker_ufic_workflow(), which wrapped up all steps needed to the calculation of u_fic from measured voltage (u_m) and current (i_m). All intermediate values can also be outputted for the user to debug.
Or, the user can call the corresponding functions sequentially. For illustration purpose, we show both ways.
Firstly, let's use flicker_ufic_workflow().
% Prep the input: look at the first phase for an example
u_m.data = voltage.voltage(:,1);
i_m.data = current.current(:,1);
Sr = 4.2e5; % rated power
Un = 14e3; % RMS value of the nominal voltage
SCR = 20; % short-circuit ratio
fg = 60; % nominal grid frequency
% Method settings for calculation of fundamental frequency
out = flicker_ufic_workflow(Sr, Un, SCR, fg, ...
u_m, i_m, method, methodopts);
out
out =
time: [8000×1 double]
Rfic: [20.2073 14.9984 7.9805 2.0336]
Lfic: [0.0309 0.0474 0.0582 0.0617]
alpha0: 1.1961
freq: [1×1 struct]
alpha_m: [8000×1 double]
u0: [8000×1 double]
u_fic: [8000×4 double]
Calculating u_fic can be tricky due to the part of calculating the ideal voltage source (u0), as mentioned in the IEC TS 62600-30, u0 should fulfill the following two requirements:
(1) be without any fluctuations (2) have the same electrical angle as the fundamental of u_m
Therefore, here we compare u0 and u_m to check if our output fulfills these requirements.
figure('Position', [100, 100, 1600, 600]);
plot(datetime(u_m.time, "ConvertFrom", "posixtime"), u_m.data);
figure('Position', [100, 100, 1600, 600]);
plot(datetime(u_m.time, "ConvertFrom", "posixtime"), u0);
legend('u_m', 'u_0');
Warning: Ignoring extra legend entries.

Secondly, we can also calculate u_fic step by step. The calculation of u_fic can be achieved sequentially in 5 steps:
Step 1. Construct the fictitious grid: calculate resistance and inductance using calc_Rfic_Lfic().
[Rfic, Lfic] = calc_Rfic_Lfic(Sr, SCR, Un, fg);
Step 2. Calculate the fundamental frequency and alpha_0: -opt1: method ZCD: method = 'ZCD'; methodopts={} -opt2: method STFT: method = 'stft'; methodopts = {'Window',rectwin(M),... 'OverlapLength',L,'FFTLength',128,'FrequencyRange','onesided'}
if license('test', 'Signal_Toolbox')
'Window', rectwin(5000), ...
'OverlapLength', 3750, ...
'FrequencyRange', 'onesided'
warning('Signal Processing Toolbox is not installed. Using ZCD method...');
end
Warning: Signal Processing Toolbox is not installed. Using ZCD method...
[alpha0, freq] = calc_fundamental_freq(u_m, method, methodopts);
Step 3. Calculate the electrical angle (alpha_m) of the fundamental of u_m using calc_electrical_angle().
alpha_m = calc_electrical_angle(freq, alpha0);
Step 4. Calculate u0 from alpha_m and nominal voltage (Un) using calc_ideal_voltage().
u0 = calc_ideal_voltage(Un, alpha_m);
Step 5. Calculate u_fic using calc_simulated_voltage().
u_fic = calc_simulated_voltage(u0, i_m, Rfic, Lfic);
Again, we check our derived u0 to see if it fulfills the requirements.
figure('Position', [100, 100, 1600, 600]);
plot(datetime(u_m.time, "ConvertFrom", "posixtime"), u_m.data);
figure('Position', [100, 100, 1600, 600]);
plot(datetime(u_m.time, "ConvertFrom", "posixtime"), u0);
legend('u_m', 'u_0');
Warning: Ignoring extra legend entries.

Calculate the flicker emission value (P_stfic) from u_fic
Input u_fic into an appropriate digital flickermeter to get the P_stfic.
According to the standard, the evaluation time is 10 min, therefore, to fulfill this requirement, we need data length >= 10min. And note that we may need to discard the first 20s depending on the performance of the flickermeter we choose.
% Prep input for the digital flickermeter
time = u_m.time - u_m.time(1);
u_fic_in = timeseries(u_fic(:,2), time);
u_fic_in
timeseries
Common Properties:
Name: 'unnamed'
Time: [8000x1 double]
TimeInfo: [1x1 tsdata.timemetadata]
Data: [8000x1 double]
DataInfo: [1x1 tsdata.datametadata]
More properties, Methods
A digital flickermeter that also contains an interface of statistical analysis in simulink can be used to generate the instantaneous flicker level (out.S5) and then calculate the Pst using the statistical tool associated with it. More details can be found here. Note that the user needs to specify RMS value for voltage, sampling frequencies, and other parameters to achieve a valid result. In addition, there may be some unreliable peaks in the instantaneous flicker levels derived from this particular flickermeter, when performing statistical analysis, be sure to discard the S5 data at the very beginning of it.
% Prep input for the statistical tool
% out.S5 is the result generated from the digital flickermeter.
After getting the instantaneous flicker levels, double-click the digital flickermeter to open statistical tools to calculate P_stfic.
Calculate the flicker coefficient
Provide a flickermeter output (P_stfic). In this example, data duration is < 1s, so we fake a number here for P_stfic
S_kfic = (Un^2)./sqrt(Rfic.^2 + Xfic.^2);
coef_flicker = calc_flicker_coefficient(P_stfic, S_kfic(1), Sr);
Test the performance of the flicker assessment process
This part of the example illustrates how to test the performance of the user's flicker assessment process, including methods to generate simulated voltage of the fictitious grid and the performance of the (digital) flickermeter, following the guidance provided in the IEC TS 61400-21-1 Annex B.3: Verification test of the measurement procedure for flicker.
The verification is straightforward, we generate testing data with predetermined flicker coefficients and verify the flicker assessment process by comparing the derived flicker coefficient with the predetermined ones. The testing data generated will be measured voltage and current time series (u_m and i_m), and the user can use gen_test_data() to generate test data for five different scenarios: (1) pure sine wave (coef=0) and scenarios (2)-(5) as stated Annex B.3.2 - B.3.5, and test them one by one. Here we illustrate the usage of gen_test_data by generating distorted u_m(t) with multiple zero crossings (see Annex B.3.3 for details).
% Set up proper input parameters:
% scenario 3 with duration of 10s
Un=12e3; In=144; fs=50e3; Sr = 3e6;
% other parameters for generating distorted data
fv=0.5; % fv only needed for scenario B.3.4
% According to IEC TS 61400-21-1 Table B.2:
DeltaI_I = [4.763 5.726 7.640 9.488];
[i_m,u_m]=gen_test_data(Un,In,fg,fs,fm,fv,DeltaI_I,opt,T)
i_m =
time: [500000×1 double]
data: [500000×4 double]
u_m =
time: [500000×1 double]
data: [500000×1 double]
The generated i_m(ntime, nphi_k) has 4 time-series, corresponding to phi_k = 30, 50, 70, 85. While u_m is always the same, thus has only one time series.
figure('Position', [100, 100, 1600, 600]);
plot(i_m.time, i_m.data(:,1));
figure('Position', [100, 100, 1600, 600]);
plot(u_m.time, u_m.data);