Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Claudio
Posts:
14
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.5e1; minor_th = 3e2;
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') + pos1; % Find the beginning of the next peak pos = find(u_abs(pos:end) > minor_th, 1 , 'first') + pos1; end
pos_max(1) = []; plot(u); hold on; plot(pos_max,u(pos_max),'ro');



