Shifting a signal to the right or left

How can I shift a signal to the left or right? Is there any inbuilt command for it?

6 comentarios

Adam
Adam el 1 de Feb. de 2018
Editada: Adam el 1 de Feb. de 2018
A signal defined how? Usually you will have t (time) data and y data for a signal. You can just change the t data to shift it.
SSG_newbiecoder
SSG_newbiecoder el 1 de Feb. de 2018
Editada: SSG_newbiecoder el 6 de Feb. de 2018
I have a signal x[n] I need to shift it to the right by k. Is there any inbuilt commands or do I have to write the code for it?
Jos (10584)
Jos (10584) el 6 de Feb. de 2018
maybe you should give an example of the input and expected output?
SSG_newbiecoder
SSG_newbiecoder el 6 de Feb. de 2018
Editada: SSG_newbiecoder el 6 de Feb. de 2018
The below code works well so problem solved. :)
s = zeros(size(x));
if shift >0
s(shift+1:end) = x(1:end-shift);
elseif shift <0
s(1:end+shift) = x(-shift+1:end);
end
mathematics
mathematics el 15 de Sept. de 2019
Could you please explain how to use this code?
Thank you
Sk Group
Sk Group el 24 de En. de 2021
https://www.swebllc.com/signal-shift-function-in-matlab/

Iniciar sesión para comentar.

Respuestas (6)

Jos (10584)
Jos (10584) el 20 de Sept. de 2019
x = 1:5
shift = 3
x = circshift(x,shift)
N = numel(x)
ix = (1:N) - shift
tf = ix < 1 | ix > N
x(tf) = 0
SSG_newbiecoder
SSG_newbiecoder el 20 de Sept. de 2019

2 votos

I'll try to explain with an example.
Let X={1 2 3 4 5} be our sequence. s = zeros(size(X))
s={0 0 0 0 0}
Right shift
If we want to shift this function to the right by three points,
shift=3 i.e, shift>0
s(shift+1:end) = x(1:end-shift)
ie, s(4,5)=X(1,2)
so shifted output will be s={0 0 0 1 2}
Left shift
If we want to shift this function to the left by three points,
shift=-3 i.e, shift<0
s(1:end+shift) = x(-shift+1:end)
ie, s(1,2)=X(4,5)
so shifted output will be s={4 5 0 0 0}
Hope this makes sense. Please note that this is not the circular shift and we have inbuilt code for circular shift.
Manoj Kumar Koduru
Manoj Kumar Koduru el 23 de Nov. de 2020

0 votos

clc;
close all;
L=input ('Enter the no.: ');
n=-L:L;
y=[zeros(1,L),1,zeros(1,L)];
if n >0
y(L+1:end) = n(1:end-L);
elseif n <0
y(1:end+L) = n(-L+1:end);
end
y
plot(n,y);
Sk Group
Sk Group el 8 de Feb. de 2021

0 votos

MATLAB CODE:
function [n1,x1] = sigshift(x,n,k)
n = 1:10;
k = 2;
x = exp(n);
if k>0
disp(‘Positive’);
n1 = n(1):n(end)+k;
x1 = [zeros(1,k) x];
else
disp(‘Negative’);
n1 = n(1)+k:n(end);
x1 = [x zeros(1,abs(k))]; % abs is for absolute value of (k) because quantity can never be (-ve) negative %
end
Sk Group
Sk Group el 8 de Feb. de 2021

0 votos

MATLAB CODE:
function [n1,x1] = sigshift(x,n,k)
n = 1:10;
k = 2;
x = exp(n);
if k>0
disp(‘Positive’);
n1 = n(1):n(end)+k;
x1 = [zeros(1,k) x];
else
disp(‘Negative’);
n1 = n(1)+k:n(end);
x1 = [x zeros(1,abs(k))]; % abs is for absolute value of (k) because quantity can never be (-ve) negative %
end
MATLAB CODE:
function [y n1] = sigfold(x,n)
n1 = -fliplr(n)
y = fliplr(x)
end

Categorías

Etiquetas

Preguntada:

el 1 de Feb. de 2018

Comentada:

el 10 de Feb. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by