I am using findpeaks (data,locations) func to find time period of trigonometric function. Values(max,location) for only one peak are getting stored, hence time period is coming out to be zero. please help.

1 view (last 30 days)
m= 750; % mass of the system in kg
k= 50000; % Stiffness of system in N/m
c= 1000; % damping coefficient Ns/m
time= 0:0.01:1; %time in sec
x_0=0.01; % displacement intial condition
x_dot_0=0;
syms x(t)
D1x= diff(x,1); % differentiation
D2x= diff(x,2);
x= dsolve(m*D2x+k*x==0,x(0)==x_0, D1x(0)==x_dot_0,'t');
x_fun=matlabFunction(x) % to save solved function values
x_dot_fun = matlabFunction(diff(x));
x_t=x_fun(time);
[maxima,maxima_location]= findpeaks(x_t,time);
time_period= diff(maxima_location);

Accepted Answer

Luuk van Oosten
Luuk van Oosten on 5 Jun 2019
Dear Abhijeet,
I am not sure what you mean with "hence time period is coming out to be zero", but I do believe I can be of some assistance:
If you plot your signal
plot(time, x_t)
You will see that there seem to be two peaks, one at time point zero and one at time point 0.77.
But... If you use findpeaks, the documentation states that it finds local peaks, but only if
"a data sample that is either larger than its two neighboring samples or is equal to Inf. Non-Inf signal endpoints are excluded."
I believe in your case it does not come up with the local maxima at time=0, due to that reason (if that is what you mean).
  1 Comment
Abhijeet Vishwasrao
Abhijeet Vishwasrao on 6 Jun 2019
thank you for your answer....it helped a lot. Previously as I was getting only one maxima_location (0 was excluded as you rightly said) so time period was a null matrix(as it is difference between 2 maxia_locations). Now i just increased 'time' and it helped.

Sign in to comment.

More Answers (0)

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!