Detect spikes and mark times

9 views (last 30 days)
Angelos Kampanakis
Angelos Kampanakis on 3 Jun 2014
Commented: Image Analyst on 7 Jun 2014
Hi.
I am trying to detect a spike in simulink for a signal (by spike I mean when the signal exceeds a certain value with a defined height). Futhermore, because I want to do an integration of this spike I need to have the two time values. Does anybody know how this can be achieved in matlab?
Thank you very much, Angel

Answers (1)

Sebastian Castro
Sebastian Castro on 5 Jun 2014
You can pick out the values of these spikes using a Triggered Subsystem.
What I've done in the screenshot below is:
  • Use a Compare to Constant block to create a logical signal. This tells me whether or not the signal is above the spike
  • Use a Triggered Subsystem that, when triggered, picks the current simulation time. This time is supplied with a Clock block.
  • To pick out t1, you can configure your Triggered Subsystem to find the RISING EDGE (i.e. when the logical signal goes from 0 to 1).
  • To pick out t2, you can configure another Triggered Subsystem to find the FALLING EDGE (i.e. when the logical signal goes from 1 to 0).
If you have multiple peaks in your signal, your algorithm may have to be a little "smarter" than this. However, this should give a good start for how you can use Triggered Subsystems to capture "snapshots" in your model.
  1 Comment
Image Analyst
Image Analyst on 7 Jun 2014
Angelos's "Answer" moved here since it's really a reply to Sebastian, not an answer to the original question:
Thank you very much.
Angelos, you can "thank" him also by accepting his answer and voting for it.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!