shift signal in matlab

To shift a signal in Matlab, you can use the circshift function. This function circularly shifts the elements in the input array by a specified number of positions. The shift can be in the forward or backward direction.

Here is an example code snippet that shows how to use the circshift function to shift a signal by a given number of samples:

main.m
% create a signal
t = linspace(0, 2*pi, 100);
x = sin(t);

% shift the signal by 10 samples
y = circshift(x, 10);

% plot the original and shifted signals
plot(t, x, 'r', t, y, 'b--');
legend('Original signal', 'Shifted signal');
230 chars
11 lines

In the above code, we first create a signal x using the sin function. We then use the circshift function to shift the signal x by 10 samples to obtain the shifted signal y. Finally, we plot both signals on the same figure using the plot function, and use the legend function to label the plots.

gistlibby LogSnag