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_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.531216.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 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
power_factor = 0.96;
 
% Compute the instantaneous AC power in watts
ac_power = ac_power_three_phase(voltage, current, power_factor);
 
% Display the result
figure('Position', [100, 100, 1600, 600]);
plot(datetime(ac_power.time, "ConvertFrom", "posixtime"), ac_power.power);
title('AC Power');
ylabel('Power [W]');
xlabel('Time');
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)
 
% STFT method:
% Check for Signal Processing Toolbox
if license('test', 'Signal_Toolbox')
% Set up method options
methodopts = {
'Window', int32(5000), ...
'OverlapLength', 3750, ...
'FFTLength', 50e3, ...
'FrequencyRange', 'onesided'
};
 
% Prep input and output
u_m = struct();
u_m.time = voltage.time;
fund_freq = struct();
fund_freq.time = voltage.time;
fund_freq.data = zeros(size(voltage.voltage));
 
for i = 1:3
u_m.data = voltage.voltage(:,i);
[~, freq] = calc_fundamental_freq(u_m, 'stft', methodopts);
fund_freq.data(:,i) = freq.data;
end
fund_freq
 
% Display the result
hold off;
figure('Position', [100, 100, 1600, 600]);
plot(datetime(fund_freq.time, "ConvertFrom", "posixtime"), fund_freq.data);
title('Fundamental Frequency: STFT');
ylabel('Frequency [Hz]');
xlabel('Time');
ylim([50, 70]);
else
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.
% ZCD method:
% Prep input and output
u_m = struct();
u_m.time = voltage.time;
fund_freq = struct();
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
methodopts = {};
 
for i = 1:3
u_m.data = voltage.voltage(:,i);
[~, freq] = calc_fundamental_freq(u_m, 'zcd', methodopts);
fund_freq.data(:,i) = freq.data;
end
fund_freq
fund_freq = struct with fields:
time: [8000×1 double] data: [8000×3 double]
 
hold off;
 
figure('Position', [100, 100, 1600, 600]);
plot(datetime(fund_freq.time, "ConvertFrom", "posixtime"), fund_freq.data);
title('Fundamental Frequency: ZCD');
ylabel('Frequency [Hz]');
xlabel('Time');
ylim([50, 70]);

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
grid_freq = 60; % [Hz]
 
% Set the rated current of the device
rated_current = 18.8; % [Amps]
 
% Calculate the current harmonics
h = harmonics(current, sample_freq, grid_freq);
 
% Display the results
figure('Position', [100, 100, 1600, 600]);
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 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
% for each channel
 
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 = struct();
u_m.time = voltage.time;
u_m.data = voltage.voltage(:,1);
i_m = struct();
i_m.time = current.time;
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
% of u_m, see above
method = 'zcd';
methodopts = {};
 
out = flicker_ufic_workflow(Sr, Un, SCR, fg, ...
u_m, i_m, method, methodopts);
u0 = out.u0;
out
out = struct with fields:
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.
% Check u0
hold off;
figure('Position', [100, 100, 1600, 600]);
plot(datetime(u_m.time, "ConvertFrom", "posixtime"), u_m.data);
hold on;
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')
method = 'stft';
methodopts = {
'Window', rectwin(5000), ...
'OverlapLength', 3750, ...
'FFTLength', 50e3, ...
'FrequencyRange', 'onesided'
};
else
warning('Signal Processing Toolbox is not installed. Using ZCD method...');
method = 'ZCD';
methodopts = {};
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);
disp(size(u_fic));
8000 4
Again, we check our derived u0 to see if it fulfills the requirements.
% Check u0
hold off;
figure('Position', [100, 100, 1600, 600]);
plot(datetime(u_m.time, "ConvertFrom", "posixtime"), u_m.data);
hold on;
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.
% S5 = out.S5;
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
P_stfic = 0.10016;
Xfic = 2*pi*fg*Lfic;
S_kfic = (Un^2)./sqrt(Rfic.^2 + Xfic.^2);
coef_flicker = calc_flicker_coefficient(P_stfic, S_kfic(1), Sr);
coef_flicker
coef_flicker = 2.0032
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
opt = 3; T=10;
% rated parameters:
Un=12e3; In=144; fs=50e3; Sr = 3e6;
% other parameters for generating distorted data
fg=60; SCR=20; fm=25;
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 = struct with fields:
time: [500000×1 double] data: [500000×4 double]
u_m = struct with fields:
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]);
hold off;
plot(i_m.time, i_m.data(:,1));
xlim([0 1]);
xlabel("Time");
ylabel("i_m");
 
figure('Position', [100, 100, 1600, 600]);
plot(u_m.time, u_m.data);
xlim([0 0.1]);
xlabel("Time");
ylabel("u_m");
grid on;