Effacer les filtres
Effacer les filtres

How to find (x,y) for peaks of a plot?

5 vues (au cours des 30 derniers jours)
Neil Solan
Neil Solan le 9 Avr 2018
I am using findpeaks() to get the (x,y) coordinates of the peaks of my plot, but it is giving me the x value in weird numbers. Some research has me thinking that it's giving me the x's in an index(?) but I do not know what that means and how to get it into a usable form. Thanks.
UPDATE:
I think I may understand. When I run the code, it is telling my that my locations of peaks are [180,301]. This number should be closer to 1. Is this telling me that my locations are the 180th and 301st term of the r vector? Is that what indexing means?
Code:
clear
clc
close all
%Constants:
M = 3.98*10^7; %[kg]
m = 6.6*10^5; %[kg]
k_f = 35*10^6; %[N/m]
k_d1 = 580.4*10^3; %[N/m]
k_d2 = 546.1*10^3; %[N/m]
c_d = 37.135*10^3; %[N*s/m]
F_0 = 50*10^3; %[N]
omega = 0.7:0.001:1.2; %[rad/s]
omega_1 = sqrt(k_f/M); %[rad/s]
omega_2_1 = sqrt(k_d1/m); %[rad/s]
omega_2_2 = sqrt(k_d2/m); %[rad/s]
r = omega/omega_1;
alpha1 = omega_2_1/omega_1;
alpha2 = omega_2_2/omega_1;
mu = m/M;
delta_st = F_0/k_f; %[m]
zeta = c_d/(2*m*omega_1);
%Case 1:
for i = 1:length(omega)
X_M1(i) = F_0/(sqrt((k_f-(M*omega(i)^2))^2));
end
X_m1 = 0;
%Case 2:
for i = 1:length(omega)
X_M2(i) = abs((alpha1^2-r(i)^2)/(((1-r(i)^2)*(alpha1^2-r(i)^2))-(mu*alpha1^2*r(i)^2)))*delta_st;
end
for i = 1:length(omega)
X_m2(i) = abs((alpha1^2)/((1-r(i)^2)*(alpha1^2-r(i)^2)-(mu*alpha1^2*r(i)^2)))*delta_st;
end
%Case 3:
for i = 1:length(omega)
X_M3(i) = sqrt(((alpha2^2-r(i)^2)^2+(2*zeta*r(i))^2)/((((1-r(i)^2)*(alpha2^2-r(i)^2))-(mu*alpha2^2*r(i)^2))^2+((2*zeta*r(i))*(1-r(i)^2-mu*r(i)^2))^2))*delta_st;
end
for i = 1:length(omega)
X_m3(i) = sqrt(((alpha2^2)^2+(2*zeta*r(i))^2)/(((1-r(i)^2)*(alpha2^2-r(i)^2)-(mu*alpha2^2*r(i)^2))^2+((2*zeta*r(i))*(1-r(i)^2-mu*r(i)^2))^2))*delta_st;
end
%Case 4:
zeta_optimal = sqrt((mu*(3-(sqrt(mu/(mu+2)))))/(8*(1+mu)^3));
tuned_alpha = 1/(1+mu);
for i = 1:length(omega)
X_M4(i) = sqrt(((tuned_alpha^2-r(i)^2)^2+(2*zeta_optimal*r(i))^2)/((((1-r(i)^2)*(tuned_alpha^2-r(i)^2))-(mu*tuned_alpha^2*r(i)^2))^2+((2*zeta_optimal*r(i))*(1-r(i)^2-mu*r(i)^2))^2))*delta_st;
end
for i = 1:length(omega)
X_m4(i) = sqrt(((tuned_alpha^2)^2+(2*zeta_optimal*r(i))^2)/(((1-r(i)^2)*(tuned_alpha^2-r(i)^2)-(mu*tuned_alpha^2*r(i)^2))^2+((2*zeta_optimal*r(i))*(1-r(i)^2-mu*r(i)^2))^2))*delta_st;
end
subplot(2,1,1)
plot(r,X_M1,'LineWidth',2)
hold on
plot(r,X_M2,'-.r','LineWidth',2)
hold on
plot(r,X_M3,'.g','LineWidth',1)
hold on
plot(r,X_M4,'--b','LineWidth',1)
axis([0.5 1.5 0 0.05])
ylabel('X_M')
xlabel('r')
legend('Skyscraper w/ no mass damper','Skyscraper w/ undamped mass','Skyscraper w/ damped mass','Optimally Tuned')
subplot(2,1,2)
plot(r,X_m1,'LineWidth',2)
hold on
plot(r,X_m2,'-.r','LineWidth',2)
hold on
plot(r,X_m3,'.g','LineWidth',2)
hold on
plot(r,X_m4,'--b','LineWidth',1)
axis([0.5 1.5 0 0.25])
ylabel('X_m')
xlabel('r')
[pksM1,locsM1] = findpeaks(X_M1);
[pksM2,locsM2] = findpeaks(X_M2);
[pksM3,locsM3] = findpeaks(X_M3);
[pksM4,locsM4] = findpeaks(X_M4);

Réponses (1)

Star Strider
Star Strider le 9 Avr 2018
The second output are the vector indices corresponding to the identified peaks. If you want to find the ‘r’ coordinate corresponding the ‘pksM1’, for example in this findpeaks call:
[pksM1,locsM1] = findpeaks(X_M1);
it would be:
rM1 = r(locsM1);
You could then plot the peaks with a marker, for example as:
plot(rM1, pksM1, 'p')
to plot a star at each peak.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by