How to hold maximum value of one signal for maximum value in seconds?

Hi all,
I have a signal that indicates time difference between sequences. That value is calculated for few samples, then evalues back to zero. I'd like to catch those calculated sequence changing times and implement in other calculations. I can't use zero order hold block since I have fixed sample time for my Simulink model. Do you have any other suggestions?
Thank you.

6 commentaires

Hi @Hasan Kaan Tuna, I'm unsure if I interpreted the problem correctly. Can you sketch the signal and the expected outcome of "holding" the maximum value of the signal for [a duration of time] in unit [seconds]?
Hasan Kaan Tuna
Hasan Kaan Tuna le 6 Déc 2023
Modifié(e) : Sam Chak le 6 Déc 2023
Hey @Sam Chak! Thank you for replying. I have the following scope output. As you can see, there are some local maximum values. I'd like to keep those local maximum values for duration of that "maximum value" in seconds. For example, if the local max val is 1.2, I'd like to have that 1.2 value as output for 1.2 seconds. Do you have any idead about how to build such algorithm?
Thanks. So, you need the algorithm to continuously detect the maximum value of the signal without any knowledge of the future. For example, the first local maximum is approximately . Do you want to hold this value for seconds?
I think tracking can be done by comparing the current value with the previously sampled value and then evaluating which one is greater. If the current value is greater, then take it as and set it to hold for a duration equivalent to its value.
However, I'm unsure of how you want the algorithm to work. After holding the value for a period of time, what specific actions do you want the algorithm to take next? Can you sketch the task flow diagram and update your question? This will allow other users to gain a better understanding of your problem without scrolling down to read other comments.
@Hasan Kaan Tuna, can you take this cosine signal as an example?
n = 0:0.5:15;
y = cos(2*pi*n/10);
stem(n, y), grid on
ylim([-1.5 1.5])
xlabel t, ylabel y

Connectez-vous pour commenter.

 Réponse acceptée

Tushar
Tushar le 12 Déc 2023
Hi Hasan,
I understand that you want to hold the maximum value of a signal for “a duration of the maximum value” in seconds.
Firstly, to achieve this, you would need to find the local maxima of the signal in Simulink. You can use the MinMax Running Resettable block for this purpose, which outputs the minimum or maximum of all past inputsu’. Have a look at the below documentation, it also includes an example displaying how to use the MinMax Running Resettable block to calculate the running minimum value.
After finding the local maxima, you need to hold that value of the signal when the local maxima occur. I found a similar MATLAB Answer, which is linked below. It recommends using an Enabled Subsystem to hold the value of a signal.
Alternatively, if you access to the DSP System Toolbox, you can use the Sample and Hold a Signal” block which samples an input signal when a trigger event occurs and holds the value until the next trigger. I have provided the documentation link for this block below.
I hope these resources are useful.
Best,
Tushar

Plus de réponses (0)

Produits

Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by