convolution of two unit step functions.

17 次查看(过去 30 天)
alright folks, the issue i am having is that i am trying to use convolution on two step functions but for one i have an odd interval that i cannot figure out how to program in matlab. Here is the set up: x[n]= 1 ; 0<=n<=9 otherwise 0, h[n]= 1; 0<=n<=N where N is <= 9 otherwise 0. my problem in i do not know how to express this extra boundary in matlab. here is the code i have written thus far.
code
end
nx=-1:9;
N<=9;
nh=0:N;
x=usD(n);
h=usD(n);
y=conv(x,h);
ny=(nx(1) + nh(1) + (0:length(nx) + length(nh) - 2));
plot (ny,y);

采纳的回答

Shounak Shastri
Shounak Shastri 2018-2-20
1. The first thing you need to know is that in Matlab, the array index starts from 1 and not from 0. So if you write x(0)=1, you would get an error.
So you need to modify your limits to x[n]= 1 ; 1<=n<=10 and N<=10.
2. The statement
N<=9;
will give you a true or false answer as it is a logical statement. Also, the answer would be of no use as it is not being stored or used as a flag in any way.
3. As for the boundary, you can simply add a if statement inside a for loop.
for ii=1:length(h)
if ii>=1 && ii<=N % considering you have added 1 as described in 1
h(ii)=1;
else
h(ii)=0;
end
end

更多回答(1 个)

justin stephens
justin stephens 2018-2-20
thank you!

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by