简体   繁体   中英

Calculating time of first and last value above threshold

I have a signal in Simulink (R2015b) that corresponds to a Power output. The signal is a discrete scalar in 1 minute intervals. Every day at a certain Time (ie 00:00) i want to calculate the times of the day before (or index since values are discrete in 1 min intervals) where the signal crossed a certain threshold for the first and last time (see image).

I would like to implement this in a Simulink function block if possible unless there is a more simple solution.

Thanks!

图片

You can use the find function for this. I don't know if this can be implemented as a Simulink function block, I have no clue about Simulink:

% fake some data
t = 0:200;
signal = 100*exp(-((t - 100)/50).^2) + randn(1,201)*10;

% plot signal
plot(t, signal);

threshold = 50;

% find first above threshold
ind1 = find(signal > threshold, 1, 'first');

% find last above threshold
ind2 = find(signal > threshold, 1, 'last');

% plot it
hold on;
plot([1 1] * t(ind1), [0 100], 'r-', [1 1] * t(ind2), [0 100], 'r-');

在此处输入图像描述

Given that t , signal and threshold have the data you talk about, another option is:

getfield(t(signal>threshold),{[1 sum(signal>threshold)]})

this will give you the first and last values of time t where signal>threshold ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM