Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Claudio

Posts: 11
Registered: 11/18/11
Re: Area under the curve
Posted: Nov 18, 2011 5:47 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


> 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');



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.