# Shift a signal by a given number of samples

Is shifting a signal by a given number of samples, say $n$ samples, the same as the following in matlab: signal(n:end) instead of signal(1:end).

That is, if the size of $signal$ is 200x1, does it make sense to remove the first $n$ rows and consider the size of $signal$ at (200-n)x1 for the shifted signal?

No, this is not shifting but windowing by a rectangular window. Shifting will not change the values of the samples, it will just change the relation between the sample values and the corresponding time indices.

In Matlab a (finite length, discrete-time) signal is simply represented by a vector of numbers. There is no relation to time indices. The interpretation which sample value corresponds to the index $n=0$ is up to you. So shifting a signal without any further processing in Matlab (or any other software) is meaningless.

If it's just about plotting, you can use stem(n,x) where x is your signal vector, and n is the corresponding vector of time indices. Shifting just involves specifying a different vector n, the data in x remain of course unchanged.

Shifting becomes important if it is part of some processing involving more than one signal, e.g. the computation of the deterministic auto-correlation or cross-correlation. In such a case you simply have to implement the corresponding formula.

EDIT:

If you have two signal vectors x and y which have the same number of elements N, and you want to add a shifted (e.g., delayed) version of y to the signal x then you can do two things. If y is shifted by M samples, you could define the sum by

z = [x(:),zeros(M,1)]+[zeros(M,1),y];

In this case the indices where only one of the two signals in non-zero (due to the shifting operation) are also taken into account. This may or may not be useful. If you want to disregard these regions and only take into account indices where both signals overlap, you can do this:

z = x[M+1:N]+y[1:N-M];

This is simply the middle region of the other sum vector z defined above.

• My intention is not just to plot the sequence. My requirement is that I have two signals from two transmitters and for one signal, I would like to shift the signal in time by say 3 $\mu s$ while the other signal remains the same and add these two signals at the receiver. I am currently doing the shifting as follows: The sampling rate is 0.083 $\mu s$ and in order to shift the signal by 3 $\mu s$ which is equivalent to ~36 samples, I am considering the signal(37:end) in Matlab. Does this make any sense? @Matt L. Jun 18, 2015 at 12:16
• @smyslov: I've added some information to my answer. Jun 18, 2015 at 12:35