在matlab中进行卷积

时间:2013-09-22 06:18:28

标签: matlab

我正在尝试计算这个卷积:

x [n] =δ[n + 1] +δ[n] - δ[n-1]

h [n] =(1/2)^ n * u [n]。 u [n]是阶梯函数。

这是我的代码:

>> n=[-10:10];
>> x=zeros(1,length(n));
>> x(n==-1)=1;
>> x(n==0)=1;
>> x(n==1)=-1;
>> u=heaviside(n);
>> h=(1/2).^n * u;
??? Error using ==> mtimes
Inner matrix dimensions must agree.

你如何确切地输入我的h [n]?如果它是你[n-1]会怎么样?

1 个答案:

答案 0 :(得分:1)

>>  n=[-10:10];
>> x=zeros(1,length(n));
>> x(n==-1)=1;
>> x(n==0)=1;
>> x(n==1)=-1;
>> u=heaviside(n);
>> h=(1/2).^n .* u; %Note the element wise operation .*
>> conv(x,h)