# How can I code so if there is a transient segment, then a steady segment, and a transient segment again, and the timelapse is less than 120 seconds, then make that steady segment transient.

1 view (last 30 days)
Diego Dranuta on 18 Sep 2019
%Determine Segments of percent load devided in Transient and Steady
clearvars -except PercentLoad Time
%Get rid of noise by using mean pn a 30s time window
window = 30;
figure(1)
xlabel('time in sec')
legend('PercentLoad vs Time','Average PercentLoad over 30 sec Window','location','best');
axis tight
figure(2)
axis tight
legend('Average PercentLoad over 30 sec Window','location','best');
xlabel('Time')
%Define initial values
current_transient = 1;
% Pre-Allocate Transient and steady Load Segments
transient_segment{1,current_transient} = [];
% Scan through the meanPercentLoad
moving_mean = movmean(meanPercentLoad, window);
close all
figure(1)
plot(mpl, 'b')
hold on
plot(moving_mean, 'r')
xlabel('time in sec')
legend('Percent Load','Average PercentLoad over 30 sec Window','location','best');
axis tight
% Scan through the points of the meanPercentLoad
for i = 1:mpl_length
current_transient_segment = transient_segment{1,current_transient};
% Get the current point in the load array
current_mean = moving_mean(i);
point = [i, current_load];
if current_load >= 50 && current_load < 60 && abs_diff_mean <=0.03
% this is considered steady state operation
if ~isempty(transient_segment{1,current_transient})
current_transient = current_transient + 1;
transient_segment{1,current_transient} = [];
end
else
end
else
% this should be transient operation
if isempty(current_transient_segment)
transient_segment{1,current_transient} = ...
cat(1,transient_segment{1,current_transient}, point);
end
else
transient_segment{1,current_transient} = ...
cat(1,transient_segment{1,current_transient}, point);
end
end
%If it is steady but on a window of 120s is transient from both sides
%then is also transient
end
figure;
for j = 1:length(steady_segment)
figure(2)
hold on
xlabel('time in sec')
axis tight
end
figure;
for j = 1:length(transient_segment)
if ~isempty(transient_segment{1,j})
figure(3)
plot(transient_segment{1,j}(:,1), transient_segment{1,j}(:,2))
hold on
xlabel('time in sec')
legend('transient state segments','location','best');
axis tight
end
end
Any ideas are welcome! thanks