Matlab piecewise function tranformation to step and ramp

9 views (last 30 days)
How can I transform piecewise function into ramp and step function? For example, I program matlab where it asks for piecewise function as input and then it takes these functions and decompose it into ramp and step function so that my output will be like a*x(t+n) +..... , where a is the value of the ramp/step a, n is the shift on the x-axis and x defining either ramp( r ) or step ( u )

Answers (1)

Star Strider
Star Strider on 5 Nov 2020
Experiment with these:
u = @(t) t>0; % Unit Step Function
r = @(t,a,b) (t.*a).*((t>=0) & (t<=b)); % Ramp With Slope ‘a’ And Time Limit ‘b’
t = linspace(0, 5, 250);
figure
subplot(2,1,1)
plot(t, u(t-2.5))
grid
ylim([-1 1]*1.1)
subplot(2,1,2)
plot(t, r(t-0.5, 2, 4-0.5))
grid
ylim([-1 10]*1.1)
.
  2 Comments
Osama Aliwat
Osama Aliwat on 5 Nov 2020
Thank you for your answer, but this answer only gives example on how the ramp and step function looks like for specific time interval and not for a signal wave. here is my original question and expected output in matlab as a picture.
I believe the idea is to make an input where piecewise function should be given and for this example it will be like
x = input ('Enter signal as piecewise function: \n');
and after running the MATLAB, it will ask for input and the input for that example will be
piecewise(t<-1,0,-1<=t<0,(0.5*t)+0.5,0<=t<1,1,1<=t<2,t,2<=t<2.5,(-2*t)+6,2.5<=t<4,0.5,t>=4,0)
and of course the piecewise function varies from one signal to another, however I try to transform any piecewise function into total of ramp and step function ( all piecewise signals can be decomposed into ramp and step function) and I am struggling to form a code that can do such operation.
Star Strider
Star Strider on 5 Nov 2020
Apparently, this is an assignment or exercise. It would be best if you experiment to produce the desired result from my example functions or functions you write.

Sign in to comment.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!