# How to get the sum of unit steps and unit ramps from a discrete signal?

I have the discrete-time signal depicted below.

This signal can be written as follows

$$y[n] = \{0, 0, 2, 4, 6, 6 ,6,0,0,\ldots\}\,,$$

or as the sum of shifted impulses as:

$$y[n] = 2 \delta [n-2] + 4 \delta [n-3] + 6 \delta [n-4] + 6 \delta [n-5] + 6 \delta [n-6]\,.$$

In this case, how can I obtain the sum of steps and ramps from this signal?

The answer is:

$$y[n] = 2r[n-1] - 2r[n-4] - 6u[n–7]$$

• SE.DSP wishes you a happy new year 2017, with a kind reminder that your question and its answers may require some action (update, votes, acceptance, etc.) – Laurent Duval Dec 31 '16 at 18:19

## 3 Answers

For such simple cases you can just use some intuition!

The signal changes behavior at three points and keeps that behavior in the interval until the next point. The points are $n=1$, $n=4$, and $n=6$. Just remember a very important and useful fact:

Adding $u[n-k]$ or $r[n-k]$ to a signal does not change it for $n<k$. It can only affect the signal's behavior for $n\ge k$.

• Before $n=1$, the signal is zero. So we need "something" of $[n-1]$. To see what actually we need, look at the signal within the interval $[1, 4]$. It cannot be a step since it is monotonically increasing with the slope of $2$. It is obviosely $2r[n-1]$.
• At $n=6$, it stops increasing and remains fixed. So we need to subtract a new ramp that cancels the effect of previous ramp right at $n=4$. The result of that is a constant signal for $n>4$. So the new ramp should have the same amplitude, and our signal is $2r[n-1]-2r[n-4]$.
• The constant signal in the previous section was nothing more than a scaled unit step. This unit step is canceled for $n$ values equal or larger than $7$. So we just need to subtract a unit step scaled by $6$, and the overall signal is what you are have wrote.

To avoid mistakes, let us first divide the original sequences by $2$ (for the sake of linearity):

0 0 1 2 3 3 3 0 0 0 0$\ldots$

It can be interpreted as a piecewise linear sequence, so you can expect a solution with about three degrees of freedom with ramps and steps. As these basic primitives are causal, you can use the method of deflation (or successive approximations). This is a quite common approach, used for instance in subspace decomposition, or in basis pursuit in signal processing. The idea is: find a first approximation that matches what you want approximately, subtract it from the data, and re-iterate the processing. The convergence is not always guaranteed, but it can give you insights or heuristics for a deeper approach. Here, it is likely to work fine.

You can start from left to right, build the obvious, remove it from the data, and iterate the process.

The first 0 0 1 2 3 can be approximated with ramp $r(n-1)$. Subtract $r(n-1)$ from the data, and get:

0 0 0 0 0 1 2 6 7 8 9$\ldots$

You can compensate the "novel" left-most positive slope 0 1 2 with $-r(n-4)$. You now get:

0 0 0 0 0 0 0 3 3 3 3$\ldots$

and then the $-3u(n-7)$ finishes the job. Oh no, don't forget to multiply by two again.

Here, the exercise is relatively easy to manage. Such a morphological decomposition can be used on more complicated signals. If you want more details, you can check for instance Automatic decomposition of time series into step, ramp, and impulse primitives, Galati & Simaan, 2006:

Time series data that can be modeled as linear combinations of weighted and shifted primitive functions such as ramps, steps and impulses are representative of many industrial, manufacturing, and business processes. Data of this type also are found in statistical process control, structural health monitoring, and other system diagnosis applications. Often, the existence of one or more of these primitive functions may be indicative of the occurrence of a specific process event, making their detection and interpretation of great interest. The human eye is an exceptional tool at this kind of pattern recognition. However, for processes that generate large amounts of data the human eye encounters difficulties related to speed and consistency necessitating an automated approach.

• Interesting method. But isn't it too complicated for simple signals such as this one? I think sometimes it becomes too difficult to understand (and actually calculate the updates) especially for beginners. Also it becomes even more complicated when dealing with cases with multiple and different scaling factors (here we just had $2$). So as you suggested, I think it would be a good idea to use it for automated calculations only... – msm Nov 8 '16 at 22:40
• @msm Sure. Just trying to answer the question, and then open space for more. For such homework-like questions, people often think they are useless, or just exercices. I like students to understand that, generally, there is something bigger behind that. Time-series simplification or segmentation is an example – Laurent Duval Nov 8 '16 at 22:43

The solution is ambiguous. A straight-forward decomposition of a given signal $y[n]$ is given by the formula

$$y[n] = \sum_{k=0}^\infty (y[k] - y[k-1])u[n-k]$$

I.e. you decompose the signal into time-shifted unit steps. The amplitude of each step is the difference between two adjacent values. Naturally, if $y[k]-y[k-1]=0$, no unit step (or unit step multiplied by zero) occurs at position $k$.

To also include ramp functions, it is possible use the difference function $y'[n]=y[n]-y[n-1]$. A ramp occurs for all samples, where $y'[n]$ is consecutively constant (or $y''[n]$ is zero).