The Math Forum

Search All of the Math Forum:

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

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

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

Advanced Search

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

Posts: 16
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;
minor_peak_value(end+1) = m;

% 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;

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

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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.