Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Area under the curve
Replies: 9   Last Post: Nov 29, 2011 5:47 AM

 Messages: [ Previous | Next ]
 Claudio Posts: 16 Registered: 11/18/11
Re: Area under the curve
Posted: Nov 18, 2011 5:47 AM

> I have used your first few lines of code as below and it shows exactly '7' major peaks in my above input.

The "7" returned by the function "find" is actually the index of the first sample above the threshold.
Try this code, it seems to work with your data (in Matlab! Not sure how to implement it in Simulink).

u_abs = abs(u);
major_th = 1.5e-1;
minor_th = 3e-2;

major_peak_value = [];
minor_peak_value = [];
pos = 1;
pos_max = 1;

while ~isempty(pos)

[m pos_max(end+1)] = max( u_abs( pos : pos + 10) );
pos_max(end) = pos_max(end) + pos - 1;

if m > major_th
major_peak_value(end+1) = m;
else
minor_peak_value(end+1) = m;
end

% Be sure to exit the peak
pos = find(u_abs(pos:end) < minor_th, 1 , 'first') + pos-1;
% Find the beginning of the next peak
pos = find(u_abs(pos:end) > minor_th, 1 , 'first') + pos-1;
end

pos_max(1) = [];
plot(u); hold on;
plot(pos_max,u(pos_max),'ro');

Date Subject Author
10/28/11 Prashant
11/16/11 Prashant
11/17/11 Prashant
11/18/11 Claudio
11/18/11 Prashant
11/18/11 Claudio
11/18/11 Prashant
11/18/11 Claudio
11/24/11 Prashant
11/29/11 Prashant