Error using vertcat Dimensions of arrays being concatenated are not consistent..
1 次查看(过去 30 天)
显示 更早的评论
The code below is showing the following error
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in Waveform_Partition_Reconstruction (line 83)
second_derivative = diff([0; diff(Ida_normalized(i:window_end))]);
I can't solve it, any suggestions?
clear all;
close all;
clc;
warning off;
caso=input('Which case do you want to analyze? ');
if caso == 1
h=input('Which run do you want to analyze? ');
N=input('For which sampling do you want to analyze? ');
[Ip_phaseA, Ip_phaseB, Ip_phaseC, Is_phaseA, Is_phaseB, Is_phaseC, T, switchingInstant] = PSCAD_1(h, N);
elseif caso == 2
h = input('Enter the percentage of transmission line where the fault occurs (0, 25, 50, 75, or 100): ');
N = input('Enter the value of N: ');
fault_type = input('Enter the fault type (A, B, C, AB, BC, CA, or ABC): ', 's');
run = input('Enter the run number (from 1 to 9): ');
[Ip_phaseA, Ip_phaseB, Ip_phaseC, Is_phaseA, Is_phaseB, Is_phaseC, If_phaseA, If_phaseB, If_phaseC, T, switchingInstant] = PSCAD_2(h, N, fault_type, run);
else
disp('Invalid option. Please choose 1, 2, or 3.');
return;
end
if caso == 1
Ida = Ip_phaseA - Is_phaseA;
Idb = Ip_phaseB - Is_phaseB;
Idc = Ip_phaseC - Is_phaseC;
else
Ida = If_phaseA / 100;
Idb = If_phaseB / 100;
Idc = If_phaseC / 100;
end
% Assuming Ida, Idb, and Idc are your current signals for phases A, B, and C
% Normalize the current signals
Ida_normalized = Ida / max(abs(Ida));
Idb_normalized = Idb / max(abs(Idb));
Idc_normalized = Idc / max(abs(Idc));
% Wavelet decomposition parameters
wavelet = 'db3';
level = 3;
k = 8; % Window length
% Define the thresholds
T1 = 0.1e-4;
% Initialize energy arrays with zero
n = length(Ida_normalized); % Number of sampling points
Ea = zeros(1, n);
Eb = zeros(1, n);
Ec = zeros(1, n);
% Initialize the combined criteria
Li1 = zeros(1, n);
Li2 = zeros(1, n);
L = zeros(1, n); % The combined criterion
% Decompose and calculate energy for each phase
for i = 1:(n-k+1)
window_end = i + k - 1; % Define the end of the current window
% Decompose and calculate energy for Ida_normalized
[cA, cD] = dwt(Ida_normalized(i:window_end), wavelet);
for j = 1:level-1
[cA, cD] = dwt(cA, wavelet); % Further decomposition
end
Ea(i) = sum(cD.^2);
% Decompose and calculate energy for Idb_normalized
[cA, cD] = dwt(Idb_normalized(i:window_end), wavelet);
for j = 1:level-1
[cA, cD] = dwt(cA, wavelet); % Further decomposition
end
Eb(i) = sum(cD.^2);
% Decompose and calculate energy for Idc_normalized
[cA, cD] = dwt(Idc_normalized(i:window_end), wavelet);
for j = 1:level-1
[cA, cD] = dwt(cA, wavelet); % Further decomposition
end
Ec(i) = sum(cD.^2);
% Calculate the second derivative of the current signal
second_derivative = diff([0; diff(Ida_normalized(i:window_end))]); % LINE ERROR
% Calculate the energy of the second derivative
E2 = second_derivative.^2;
E2_energy = sum(E2);
% Criteria for wavelet energy
Li1(i) = (Ea(i) > T1) || (Eb(i) > T1) || (Ec(i) > T1);
% Dynamic thresholding based on maximum energy observed
T2 = T1; % Initialize T2 with the default threshold
if (max(E2) > 0.3 * T1)
T2 = 5e-4; % High threshold for fault current
elseif (max(E2) >= 5e-3 * T1)
T2 = 5e-3; % Low threshold for inrush current
end
% Criteria for second derivative energy
Li2(i) = E2_energy > T2;
% Combined criterion
L(i) = Li1(i) || Li2(i);
end
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Signal Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!