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.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
%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;
Time=1:length(PercentLoad);
meanPercentLoad = movmean(PercentLoad,window);
figure(1)
plot(Time,PercentLoad,Time,meanPercentLoad);
xlabel('time in sec')
ylabel('PercentLoad')
legend('PercentLoad vs Time','Average PercentLoad over 30 sec Window','location','best');
axis tight
figure(2)
plot(Time,meanPercentLoad);
axis tight
legend('Average PercentLoad over 30 sec Window','location','best');
xlabel('Time')
ylabel('PercentLoad')
%Define initial values
current_steady = 1;
current_transient = 1;
% Pre-Allocate Transient and steady Load Segments
transient_segment{1,current_transient} = [];
steady_segment{1,current_steady} = [];
% Scan through the meanPercentLoad
mpl = meanPercentLoad;
mpl_length=length(meanPercentLoad);
moving_mean = movmean(meanPercentLoad, window);
close all
figure(1)
plot(mpl, 'b')
hold on
plot(moving_mean, 'r')
xlabel('time in sec')
ylabel('mean percent Load')
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_steady_segment = steady_segment{1,current_steady};
current_transient_segment = transient_segment{1,current_transient};
% Get the current point in the load array
current_load = mpl(i);
current_mean = moving_mean(i);
abs_diff_mean = abs((current_load/current_mean)-1);
point = [i, current_load];
if current_load >= 50 && current_load < 60 && abs_diff_mean <=0.03
% this is considered steady state operation
if isempty(current_steady_segment)
steady_segment{1,current_steady} = ...
cat(1,steady_segment{1,current_steady}, point);
if ~isempty(transient_segment{1,current_transient})
current_transient = current_transient + 1;
transient_segment{1,current_transient} = [];
end
else
steady_segment{1,current_steady} = ...
cat(1,steady_segment{1,current_steady}, point);
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);
if ~isempty(steady_segment{1,current_steady})
current_steady = current_steady + 1;
steady_segment{1,current_steady} = [];
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
%steady_period=120;
end
figure;
for j = 1:length(steady_segment)
figure(2)
plot(steady_segment{1,j}(:,1), steady_segment{1,j}(:,2))
hold on
xlabel('time in sec')
ylabel('mean percent Load')
legend('steady state segments','location','best');
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')
ylabel('mean percent Load')
legend('transient state segments','location','best');
axis tight
end
end
Any ideas are welcome! thanks
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!