问题
I have a discrete signal
x = [ 1 2 3 4 5 6 ] with n = [ -2 -1 0 1 2 3 ]
How can i plot y[n] = x[n-1] + x[n-2] + x[n] ? Thanks.
回答1:
You can do the following:
y = x(1:end-2) + x(2:end-1) + x(3:end);
plot(n(3:end), y)
回答2:
This looks like a filter... You should consider using the filter
function to calculate y
:
x = [...whatever...];
% Filter coefficients from your difference equation.
b = [1 1 1];
a = 1;
y = filter(b, a, x);
plot(n, y);
This will handle initial conditions more appropriately than naive approaches, so you will get a 6-element vector out with your given input (although note that your data is liable to be partly garbage for the first three samples).
来源:https://stackoverflow.com/questions/16051407/how-can-i-plot-the-sum-of-two-discrete-signal