Abhishek
to 'shift' in time, linearly, it is, to delay or advance in time n, you don't multiply.
To obtain the time base, just build it, like this
and shift both x and nx the same way,
1.- to delay, n1>0
x_delay=x(n-n1);
nx_delay=nx(n-n1);
2.- advance, n2>0
x_advance=x(n+n2);
nx_advance=nx(n+n2);
3.- To 'compress' or accelerate (aka decimate), non-linear time compression or span, then you multiply or divide the time base. For instance to accelerate with factor N>0
x_accelerate=x([1:N1:end]);
nx_accelerate=nx([1:N1:end]);
you may find the following decimation function useful
function [y,m] = dnsample(x,nx,M)
m=1:1:floor(length(x)/M);
y=zeros(1,length(m));
y(1)=x(1);
Lx=length(m);
for q=1:1:Lx,
y(q)=x(q*M);
end
4.- or span in time N2>0
to span the time base
nx_span=[1:1:N2*length(x)]
and to span the signal itself you have to interpolate. MATLAB has different functions to interpolate, because you may want to use a higher polynomial order, or simply go for linear interpolation, or even easier, flat repetition of samples, with for instance the following function
function [y,ny] = insample(x,nx,Q)
Lx=length(x)
ny=1:1:(Lx*(Q+1));Ly=length(ny)
y=upsample(x,(Q+1))
for j=1:(Q+1):(Ly-2)
for i=2:1:(Q+1)
v=floor((i-2)/Q)
y(i+(j-1))=y(v+j)
end
end
n1,n2,N1,N2 integers.
Abhishek, would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John BG