how do i implement y=nx(n-6) in matlab

1 view (last 30 days)
x(n) is a descrete signal. i want to operate on its shifted version by multiplying n. please help

Accepted Answer

John BG
John BG on 8 Aug 2016
Edited: John BG on 8 Aug 2016
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
nx=[1:length(x)]
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)
% decimation y(n)=x(n*M)
% length(y)=length(x)/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)
% interpolation repeating Q times
% i didn't find this interpolation in MATLAB as MATLAB starts
% with linear interpolation
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
  3 Comments
Steven Lord
Steven Lord on 24 Feb 2017
The usage notes for the 500 reputation privilege states "Answers can only be accepted by someone other than the author of the question after 7 days of inactivity from the author." It doesn't prevent someone from accepting their own answer. [If you believe that the privilege should include that restriction, suggest that to the Answers admins.]
I have not checked who accepted the answer or when, but given that the question is several months old and is this poster's only question, I think it unlikely they're going to come back and want to accept the only other answer, the one posted by Azzi several months ago.
If John's answer was completely unrelated to the question that was asked, I would question its acceptance. But it seems from a quick scan to address the question, so it seems to me to be okay as the Accepted answer. [Personally I would have included a concrete example, say shifting the vector (1:10).^2 sampled at times 1:10 in either direction, but that's just my teaching/explanation style.]
Jan
Jan on 24 Feb 2017
Edited: Jan on 25 Feb 2017
@Steven: Thanks for your comment. I agree that this answer is not off-topic and I only care about it, because John has selected 24 of his answers in the last days. The admins have been asked already to think over the self-accepting. See Answers: When to accept an answer for someone.

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 7 Aug 2016
n=0:10
x=@(n) n.^2 % ----Example-----
y=n.*x(n-6)

Categories

Find more on Descriptive Statistics in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!