How to plot upper and lower bounds in graph with 95% confidence.
7 views (last 30 days)
Show older comments
% preallocate output variables
n_files = 2;
Time = cell(n_files, 1);
Veloc = cell(n_files, 1);
Ypk_plot = cell(n_files, 1);
Xpk_plot = cell(n_files, 1);
Y = cell(n_files, 1);
X = cell(n_files, 1);
P = cell(n_files, 1);
damp_ratio = zeros(1, n_files);
wd = zeros(1, n_files);
wn = zeros(1, n_files);
K_ex = zeros(1, n_files);
% read Data from files and process each file
for j = 1:n_files
% read Data from file
z1 = importdata("Xxsv0000"+num2str(j)+".txt");
% extract time and velocity Data
Time{j} = z1.data(:,1);
Veloc{j} = z1.data(:,2);
% find local maxima in velocity Data within the range of indices
[Ypk, Xpk] = findpeaks(Veloc{j}(1:550));
Ypk_plot{j} = Ypk(11:35);
Xpk_plot{j} = Xpk(11:35);
Y{j} = Ypk;
X{j} = Xpk;
P{j} = zeros(size(Ypk));
% plot Data against time Data and mark the locations of the peaks found
figure
plot(Time{j}, Veloc{j}, 'DisplayName', 'Data')
hold on
plot(Time{j}(Xpk_plot{j}), Ypk_plot{j}, 'dr', 'DisplayName', 'Pick points')
grid on
legend('Data','Pick Points','FontSize',12)
xlabel('Time','FontSize',12)
ylabel("Voltage (V/V)",'FontSize',12)
sgtitle(['K', num2str(j)])
% calculate logarithmic decrement, damping ratio, and natural frequency
t_new = Time{j}(X{j});
y_new = Y{j};
Log_Dec = abs(log(y_new(1:end-1) ./ y_new(2:end)));
Mean_dec = mean(Log_Dec);
Damp_period = (t_new(end) - t_new(1)) / length(t_new);
wd(j) = 2*pi / Damp_period;
damp_ratio(j) = Mean_dec / sqrt((2*pi)^2 + Mean_dec^2);
wn(j) = wd(j) * sqrt(1 - damp_ratio(j)^2);
% calculate spring constant
K_ex(1,j) = m_for_k(1,j) * wn(1,j)^2;
end
clear j n_files t_new Time Veloc X Xpk Xpk_plot Y;
clear y_new Ypk_plot z1 Damp_period Log_Dec Mean_dec Ypk P;
0 Comments
Answers (1)
See Also
Categories
Find more on Surrogate Optimization 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!