How can i plot the sum of two discrete signal?

ε祈祈猫儿з 提交于 2020-01-06 16:21:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!