0
$\begingroup$

I'm reading this book and I came across a function to shift sequences. Mathematically,

$$ y(n) = \{x(n-k) \} $$

if $m = n-k$, then $$ y(m+k) = \{ x(m) \} $$

function [y,n] = sigshift(x,m,k)
n = m + k;
y = x;
end

This function shifts nothing. I've tried to find errata list of the book, but I couldn't find it. Is this function correct?

$\endgroup$
1
$\begingroup$

This function just changes the x-axis for plotting signals. It's indeed pretty trivial but the idea is to use it like this:

n = 0:4;
x = [1 2 3 2 1];           % some signal
[y,m] = sigshift(x,n,3);   % shift to the right by 3 samples
subplot(2,1,1), stem(n,x)
subplot(2,1,2), stem(m,y)

enter image description here

$\endgroup$
2
$\begingroup$

In order to shift in MATLAB you need to play with the indices of the signal vector. for example, given vector x - vX of length L, to shift it in time such that the first sample is the fifth you'll do this:

vXShifted = x(5:L);

Pay attention that the signal is shorter by 4 samples.

Now, sometimes, for periodic signals, a cyclic shifting is required which can be done using circshift.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.