Asses if a signal is within range (with dynamic setpoint) for last 60 seconds.

조회 수: 1 (최근 30일)
Roel Geurts
Roel Geurts 2014년 5월 1일
답변: Prateekshya 2024년 10월 18일
Im looking to build a model to asses if a incoming speed signal is within +/-3 km/h.
There are 2 options that are statisfactory for me: Look back every 60 seconds if the signal was in range (with setpoint speed at t=0s or t=60s) of Look back every sample if the 60 seconds before where within range.
So for example if the speed at 120 seconds is 79 km/h, I want to know if the speed from 60 until 120 was between 76 and 82. But when a 180s it is 90 km/h it has to be between 87 and 93 km/h Can anybody help me with this?
Kind Regards, Roel Geurts

답변 (1개)

Prateekshya
Prateekshya 2024년 10월 18일
Hello Roel,
To achieve your goal of assessing whether an incoming speed signal is within a specified range over a moving window, you can implement a simple algorithm that processes the speed data in real-time. The idea is to maintain a moving window of the last 60 seconds of speed data and check if all values within this window are within the specified range of the current speed.
Here is a step-by-step guide on how to implement this in MATLAB:
  • Collect Speed Data: Assume you have a vector speedData that contains the speed values sampled at regular intervals (e.g., every second).
  • Define Parameters: windowSize (The number of samples corresponding to 60 seconds), tolerance (The allowable deviation from the current speed (e.g., ±3 km/h)).
  • Process Each Sample: For each new speed value, check if all previous values within the window are within the specified range of the current speed.
Here is a MATLAB script to implement this:
% Example speed data (replace with your actual data)
speedData = [78, 79, 80, 81, 82, ... ]; % Extend this with your actual data
% Parameters
samplingRate = 1; % Samples per second
windowSize = 60 * samplingRate; % 60 seconds window
tolerance = 3; % ±3 km/h
% Initialize results
isWithinRange = true(size(speedData)); % Logical array to store results
% Loop over each sample starting from the window size
for t = windowSize:length(speedData)
% Current speed at time t
currentSpeed = speedData(t);
% Extract the window of speeds
speedWindow = speedData((t - windowSize + 1):t);
% Check if all speeds in the window are within the range
lowerBound = currentSpeed - tolerance;
upperBound = currentSpeed + tolerance;
% Check if all values are within the range
isWithinRange(t) = all(speedWindow >= lowerBound & speedWindow <= upperBound);
end
% Display the result
for t = windowSize:length(speedData)
fprintf('At time %d seconds, speed is %d km/h: ', t, speedData(t));
if isWithinRange(t)
fprintf('All speeds in the last 60 seconds are within range.\n');
else
fprintf('Not all speeds in the last 60 seconds are within range.\n');
end
end
I hope this helps!

카테고리

Help CenterFile Exchange에서 Scopes and Data Logging에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by