I am trying to plot a discrete convolution:
n = 0:25;
x = 2 * (heaviside(n+2)-heaviside(n-12));
h = 0.9.^n .* (heaviside(n-2)-heaviside(n-13));
y = conv(x, h);
stem(n, y)
But I get a problem because the length of n is 26 and the length of y is 51, but I want to show the plot the convolution from n = 0 to n = 25. How can I modify this code to obtain such result?
答案 0 :(得分:4)
如果您阅读documentation to the conv
function,您将了解到它有第三个参数:一个字符串,告诉您输出应该有多大。
y = conv(x, h, 'same');
将创建一个y
,其大小与x
相同(因此n
)。
答案 1 :(得分:2)
Without deeper knowledge of convolutions or such:
If you are just trying to get the vectors to be similar in size, skip elements of the vector like so:
stem(n, y(1:2:end)) % Take every other element of y
This at least produces some curve with discrete points.
Alternatively, make the n
twice as long:
stem(0:.5:25, y) % Double the amount of elements previously in n