This program references the ChineseEIJournal“Power Grid Technology” online publication, literature: “Classification Method of Power Quality Disturbances Based on Markov Transition Field and Multi-Head Attention Mechanism“. The program is well-commented and full of valuable content. Below is a brief introduction to the article and the program!

Principle: Markov Transition Field (Markov transition field, MTF) is a method for transforming time-series data into spatial image data. This method extends the Markov state transition matrix by sequentially expressing the state transition matrix, fully preserving the dynamic information of the discretized time domain, and ultimately generating a two-dimensional image using fuzzy kernel aggregation. For example, the schematic diagram ofMTF is shown below.

The MTF-CNN-Attention method for fault recognition has several innovative aspects:
Input Data Format:(One sample per line, the last column indicates the fault category label)


Training Curve: Accuracy and Loss Variation Chart

% Load data
data = xlsread('FeatureDataWithLabels.xlsx');
% Get the number of samples and the length of each sample
[numSamples, sampleLength] = size(data);
% Loop through each sample data
for sampleIdx = 1:numSamples %% Generate data % Get current sample data from data featureData = data(sampleIdx, 1:end - 1);
X = featureData; m = length(X); % Normalize data to [0, 1] X_normalized = (X - min(X)) / (max(X) - min(X)); %% Construct transition matrix W numDataPoints = length(X); % Divide into Q quantile bins (by count), from small to large: 1, 2, 3, 4 Q = 4; % Map each element to quantile bins 1, 2, 3, 4 X_Q = ones(1, numDataPoints); threshold = 0; % Initialize threshold thresholds = ones(1, Q + 1); for i = 2 : Q + 1 % Loop to calculate the number of data points less than the current threshold, exit loop when threshold is reached while sum(X_normalized < threshold) < numDataPoints * (i - 1) / Q threshold = threshold + 0.0001; end % Record the threshold for each quantile bin thresholds(i) = threshold; % Transform original data vector into corresponding quantile order vector X_Q(find(X_normalized < thresholds(i) & X_normalized > thresholds(i - 1))) = i - 1; end %% Calculate Markov matrix % Initialize state transition counts sum_11 = 0; sum_12 = 0; sum_13 = 0; sum_14 = 0; sum_21 = 0; sum_22 = 0; sum_23 = 0; sum_24 = 0; sum_31 = 0; sum_32 = 0; sum_33 = 0; sum_34 = 0; sum_41 = 0; sum_42 = 0; sum_43 = 0; sum_44 = 0;
Welcome to interested friends to click “Read the Original“ or the link above to obtain the complete code~, follow the editor for more quality learning materials and article program codes~