How can I create left shifted discrete time signal in Matlab

4.2k Views Asked by At
 x[n]=n if 0<= n <=10 else x[n]=0;

I am able to plot x[n+3] and x[n-3] using stem. but I need to sum these two signals.During my trials I can t overcome the problem of negative indices.Is there anyway to do y[n]= x[n+3]+x[n-3] ?

In similar topics only right shift which is not causing negative indices has been answered.

2

There are 2 best solutions below

0
On

Solution : creating appropriate functions instead of arrays.

function O=Y(n)
if n<-3 && n>13
    O=0;
else
    O=X(n-3)+X(n+3);
end

And

function O=X(n)
 if n>=0 && n<=10
     O=n;
 else
     O=0;
 end;
1
On

MATLAB requires you to have each logic case stored uniquely. The way you'd write it is probably:

if (0 <= n) && (n <= 10)
    x(n) = n;
else
    x(n) = 0;
end

Combining it into one longer expression:

if (0 <= n 0 <= 10)

Wouldn't work, and would always return true.