To shift a signal in the time domain using Matlab, you can use the circshift()
function.
The basic syntax for circshift
function is B = circshift(A, K)
where A
is the input signal, K
is the number of positions to shift and B
is the shifted version of A
.
Here is an example code block that shifts a sinusoidal signal by n
samples to the right:
main.m412 chars15 lines
In this code, we first generate a sinusoidal signal with a sampling rate of 100 Hz
and a frequency of 5 Hz
. We define a time vector using the sampling rate and the length of the signal.
We then shift the signal by 10
samples to the right using the circshift()
function and store the result in x_shifted
. Finally, we plot both the original and the shifted signal on the same graph using different line styles and add a legend to the plot.
You can modify the value of n
to shift the signal by a different number of samples.
gistlibby LogSnag