# repeating step signal in real time with a hold value of 5 seconds

조회 수: 3(최근 30일)
Ramón Tamino Uhl 2021년 7월 6일
답변: Peter Perkins 2021년 7월 28일
Hello dear community,
I am working on my Bachelor thesis and have encountered a problem which I could not solve with different methods.
I am building a Robot with a LEGO EV3 Brick and Motor. For modeling purposes I need to gain experimental data to build a function that translates my input u (torque) into power as the Simulink encoder for LEGO works with power values from -100 to 100.
To do so I build an experiment with a digital clock that counts from -100 to 100 and I gave this signal into the motor. I saved the data from the encoder and used polyfit to approximate the data. This worked, but there is a big margin of error.
So I want to build a repeating step signal, that holds the power level for 5 seconds and then makes a step of 1 to the next power level. This way I could calculate the average value over 5 seconds. But I have not been successful in generating a signal like this.
I would appreciate any kind of help.
The signal would look something like this:
_ _ _ _ _| step of 1
_ _ _ _ _|
_ _ _ _ _|
5 seconds
Kind regards,
Ramón

댓글을 달려면 로그인하십시오.

### 답변(2개)

Mathieu NOE 2021년 7월 7일
hello
Fs = 100;
dt = 1/Fs;
duration = 5 ;
nb_steps = 10
%%%%%%%%%%%%%%%
samples = Fs*duration;
y = ones(samples,1);
out = y;
for ci = 2:nb_steps
out = [out; ci*y];
end
plot(out) % time axis in samples
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

Peter Perkins 2021년 7월 28일
Like this?
>> interp1([1 5 6 10 11 15],[1 1 2 2 3 3],1:15,"prev")
ans =
1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
I mean, a signal all by itself seems unusual, so likely if there was a bigger picture I'd recommend using a timetable and retime to do that "prev" interpolation.

댓글을 달려면 로그인하십시오.

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by