how to create a ramp signal with limits at 1 in matlab

Here is a code snippet in Matlab to create a ramp signal with limits at 1:

main.m
function rampSignal = createRampSignal(numSamples)
    increment = 2 / (numSamples - 1);
    rampSignal = -1:increment:1;
    rampSignal(rampSignal > 1) = 1;
    rampSignal(rampSignal < -1) = -1;
end
200 chars
7 lines

The createRampSignal function takes in the number of desired samples as input and returns a ramp signal that starts at -1 and ends at 1. The signal is created by incrementing from -1 to 1 in equal steps. Then, any values above 1 or below -1 are constrained to 1 and -1, respectively.

You can modify the function to change the minimum and maximum limits as needed.

gistlibby LogSnag