Finding the time duration of an oscillation on a graph
4 views (last 30 days)
Show older comments
% Dear Users,
% I have an oscillating voltage curve depending on time (please see the document on the attachments)
% t_clear= Clerance Time
% t_e=Execution Time
% u_ref=Reference Voltage
% After the t_clear=0.2 s, I want to calculate how long the oscillation stays until t_e
% 1.) out of +10% and -10% of u_ref (depends on u_ref value)
% 2.) out of +10% and -10% of u_ref=1 per unit (that makes u_min=0.9 and u_max=1.10 per unit)
% Thanks in advance!
%The related part of the code as below:
files = {'Test1','Test2','Test3','Test4'};
C = linspecer(4,'qualitative');
path ='...';
xlimup = 1;
xlimlow = 0;
n=2;
windowSize = 100;
b2 = (1/windowSize)*ones(1,windowSize);
windowSize = 10;
b1 = (1/windowSize)*ones(1,windowSize);
dispU = [2 2 2 2];
dval = zeros(101011,4);
i_pos = zeros (1, length(files));
i_neg= zeros (1, length(files));
refval = zeros (1, length(files));
lastval = zeros (1, length(files));
minU = zeros (1, length(files));
ideal = zeros (1, length(files));
t5 = zeros (1, length(files));
t10 = zeros (1, length(files));
for ff = 1:length(files)
val = dlmread(strcat(path,'\',files{ff},'.csv'),'\t',2,0);
% Ideal conditions
refval(ff) = mean(val(1:100,dispU(ff)));
% Time difference, te-tmin
deltaT = te - tc;
% Ideal area
ideal(ff) = refval(ff) * deltaT;
% Deviation
idx = find(val(:,1) > 0.2);
dval = val(idx,dispU(ff))-refval(ff);
i_pos(ff) = trapz(val(idx,1),dval.*(dval>=0));
i_neg(ff) = trapz(val(idx,1),dval.*(dval<0));
% I want to change this part!
[~, idxt10] = min(abs(dval + 0.1));
% I want to change this part!!!!!!!!
t10(ff) = val(idx(1)+idxt10,1);
lastval(ff) = val(end,dispU(ff));
val(:,dispU(ff)) = filter(b2,1,val(:,dispU(ff)));
minU(ff) = min(val(100:end,dispU(ff)));
% Plot the figure
figure(1)
grid on
hold on
busU = plot(val(:,1),val(:,dispU(ff)),'LineWidth',lw,'Color',C(ff,:),'LineStyle','-');
end
0 Comments
Answers (0)
See Also
Categories
Find more on Electrical Block Libraries in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!