Ramp a variable with 63 elements

4 次查看(过去 30 天)
David Cole
David Cole 2024-8-23
回答: Sam Chak 2024-8-24
I have a simulink variable that has 63 elements. I would like to ramp each element in the variable proportionally from 0 to the value of the variable.
For example
A = [22 17 39 ...]
B = [0 0 0 ...]
Sample time = Ts = 1e-6
B = Ramp A
Maybe I need a toolkit that has a premade ramp block that takes an input and sets upper and lower limits.
Thanks,
David
  2 个评论
Walter Roberson
Walter Roberson 2024-8-24
To check:
Do you want B to start with 0 and proceed to 22 over a fixed time, with a timestep of 1e-6? And then B should start over from 0 and proceed to 17 over a fixed time, with a timestep of 1e-6? Then B should start at 0 and proceed to 39 over a fixed time, with a timestep of 1e-6 ?
Or do you want B to start with 0 and ramp to 22 over a fixed time, with a timestep of 1e-6, followed by ramping from 22 to 17 over a fixed time with a timestep of 1e-6, then ramping from 17 to 39 over a fixed time with a timestep of 1e-6 ?
Or do you want B to become a 2D array, in which the first colum ramps from 0 to 22, the second column ramps from 0 to 17, the third column ramps from 0 to 39, all over a fixed time, so the last row would be 22 17 39 ?
David Cole
David Cole 2024-8-24
Thanks for the help. I am using Specialized Power System blocks. My sample rate Ts = 1e-6. I have 63 elements that represent harmonic currents. I need to ramp the value from 0 to its maximum. The picture below is what I am trying to do. Once the values have ramped from zero to their value, the signal needs to stay at its value until I am ready to ramp it to zero at a later time. The first element will have a frequency of 60 Hz, with a period of 1/60 = 16.666e-3 second. I would like the ramp to last at least three cycles of the slowest frequency; therefore 3*16.666-3 = 49.999e-3 seconds.

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2024-8-24
First option:
Use a Simulink ramp block with a vector of slopes, and with the setting of "Interpret vector parameters as 1-D" set to on (on is the default.) You might need to combine it with if/elseif and a zero-order hold block and a ramp-down block in order to get the ramp-down effect.
Second option:
Use a MATLAB Function Block with Clock as the input. Have the MATLAB Function Block implement the ramp/hold/ramp-down behaviour.

Sam Chak
Sam Chak 2024-8-24
If you do not need a smooth differentiable Ramp function, then use this math function:
where is the saturation value in the 63-element array S.
Note: The maximum saturation value in the array must be known.
S = [17, 22, 39]; % Saturation values
t = linspace(0, 0.1, 1001);
f = @(t) min(1, max(0, max(S)*t)); % Saturating Ramp function
for i = 1:numel(S)
plot(t, S(i)*f(t))
hold on
end
grid on, grid minor
xlabel('Time, t'), ylabel('f(t)')
title('Saturating Ramp function')

标签

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by