Problem with findpeaks function

12 vues (au cours des 30 derniers jours)
Juan Lasso Velasco
Juan Lasso Velasco le 15 Avr 2019
Hey! I'm trying to find the natural frequency of a swinging pendullum in a few different states (with springs, without springs, with forcing, without forcing) and I need to find the natural frequency of the system from experimental data that I gathered from tests in a lab. I'm using the findpeaks function in matlab to get the peaks of data sets from 10 different trials, but I have a problem. The find peaks function is supposed to find local maxima, but my find peaks function continues to give me negative values interspersed with a few of the actual maxima of the data. I tried using the 'MinPeakHeight' feature to get rid of these values but I still kept getting negative values! Can someone help me? I would greatly appreciate any input anyone can give! My code is below.
clear;
close all
format short e
%% Call upon all data files
SpringNoForce = { '2S0.lvm';
'2S1.lvm';
'2S2.lvm';
'2S3.lvm';
'2S4.lvm';
'2S5.lvm';
'2S6.lvm';
'2S7.lvm';
'2S8.lvm';
'2S9.lvm'};
SpringForce = { 'F2.0.lvm';
'F3.5.lvm';
'F3.6.lvm';
'F3.7.lvm';
'F3.8.lvm';
'F3.9.lvm';
'F4.0.lvm';
'F4.1.lvm';
'F4.2.lvm';
'F4.3.lvm';
'F4.4.lvm';
'4.5.lvm';
'F4.6.lvm';
'F4.7.lvm';
'F6.0.lvm'};
NoSpring = { '0S0.lvm';
'0S1.lvm';
'0S2.lvm';
'0S3.lvm';
'0S4.lvm';
'0S5.lvm';
'0S6.lvm';
'0S7.lvm';
'0S8.lvm';
'0S9.lvm'};
%% Organize data
g = 9.81;
mc = 0.0503;
L = 0.4778375;
mw = 0.01;
mr = 0.0532;
lc = 0.33734375-(L/2);
lb = 0.3048;
Ir = (1/3)*mr*L^2;
xm = [.05,0.10,0.20,0.30];
Nm = [3.95,6.2,11.05,15.85];
kf = polyfit(xm,Nm,1);
k = kf(1);
sx = linspace(0,0.4,1000);
Ns = k.*sx+kf(2);
figure(1);
clf;
plot(sx,Ns)
hold on
plot(xm,Nm,'o')
for i = 1:length(NoSpring)
figure
hold on
data1 = load(NoSpring{i});
tns = data1(:,1);
yns = data1(:,2);
plot(tns,yns)
[dpk,loc] = findpeaks(yns,tns,'MinPeakHeight',1);
chloc = gradient(loc);
wa(i) = mean(chloc);
wde(i) = (2*pi)./wa(i);
lw = (0.4429125+(0.001190625*(i-1))/2);
Io(i) = Ir+mc*(lc-(L/2))^2+mw*(lw-(L/2))^2;
for q = 2:(length(dpk)-1)
delta(q-1) = (1/q)*log(dpk(q)/dpk(q+1));
end
ddel = mean(delta);
ksee(i) = ddel/(sqrt(4*(pi)^2+ddel^2));
wne1(i) = wde(i)/(sqrt(1-(ksee(i))^2));
wnt(i) = sqrt((g*(mr*(L/2)+mc*(lc)+mw*(i-1)*lw))/Io(i));
end
  1 commentaire
Juan Lasso Velasco
Juan Lasso Velasco le 16 Avr 2019
Nevermind I found the problem. I left an extra loop at the end that was overwriting the values. I forget to include that in the code.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Time-Frequency Analysis dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by