Simulink - saw tooth signal minimum counter

8 views (last 30 days)
Hi guys,
I have a sawtooth singal, from which i am trying to create a signal with alternating sing. Meaning after one "tooth" (one rising and one falling edge) i want to change the sign to + or -1. Resulting in a signal alternating from -1 to 1 and so on. I tried using the derivative and then a sign block, but that does not yield a working result. I thought about implementing a counter that counts up as soon as the min value is reached, meaning that the sign of the derivative has changed. So in theory counting the local minima of the sawtooth signal. Do you have an idea how to implement that?
Thanks in advance!
  2 Comments
Dom
Dom on 5 Oct 2021
This is the ideal signal. I want to count the "teeth", meaning I want to count up as soon as the signal reaches a local minimum. The real signals usually dont go to zero or a distinct low value, so a counter that triggers at a specific value does not work, at least while I tried to do so.

Sign in to comment.

Accepted Answer

Paul
Paul on 5 Oct 2021
Assuming that your signal has sharp corners .... One approach may be to:
Input the signal into a Detect Increase block. The output of that block will flip from 0 to 1 at the minimum corner. Feed the ouput of that block into a Triggered Subsystem. By default that subsystem will execute on the rising edge of the input, i.e., when the sawtooth turns the minimum corner. In that subsystem, use a simple loop with memory block that increments a count when the subsystem is triggered.
The accuracy, i.e., the time when the count increments, of this approach will depend on the sample rate of the sawtooth and the step size of the solver, both of which you should have some control over.
A similar, but more robust approach, would be to use a zero crossing or hit detection indicator exactly at the reversal, but nothing obvious comes to mind as to how to implement that.
  1 Comment
Dom
Dom on 6 Oct 2021
The detect increase block was exactly what I was looking for! TY

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!