Error in convolution and i need someone to help me .
Show older comments
Now this is the code but when i run this code it keeps give me this error :- In an assignment A(I) = B, the number of elements in B and I must be the same. so please help me to find the problem. and thanks in advanced .
clear all;
t=-5:0.001:5;
x= zeros(size(t));
x(t>=0 & t<=5)=exp(-t);
subplot(3,1,1),plot(t,x);
h= zeros(size(t));
h(t>=0 & t<=5)=exp(-2*t);
subplot(3,1,2),plot(t,h);
a=conv(x,h);
tt=t(1)+t(1):0.001:t(end)+t(end);
subplot(3,1,3),plot(tt,a*0.001)
hold on
b=conv(h,x);
plot(tt,b*0.001)
hold off
Accepted Answer
More Answers (1)
Wayne King
on 30 Nov 2013
Edited: Wayne King
on 30 Nov 2013
I'm assuming you want this:
x(t>=0 & t<=5)=exp(-t(t>=0 & t<=5));
h(t>=0 & t<=5) = exp(-2*t(t>=0 & t<=5));
Your mistake is in trying this:
h(t>=0 & t<=5) = exp(-2*t);
You can't restrict the range of the t elements and then try to assign all the elements to h.
So to fix your code:
t=-5:0.001:5;
x= zeros(size(t));
x(t>=0 & t<=5)=exp(-t(t>=0 & t<=5));
subplot(3,1,1),plot(t,x);
h= zeros(size(t));
h(t>=0 & t<=5) = exp(-2*t(t>=0 & t<=5));
subplot(3,1,2),plot(t,h);
a=conv(x,h);
tt=t(1)+t(1):0.001:t(end)+t(end);
subplot(3,1,3),plot(tt,a*0.001)
hold on
b=conv(h,x);
plot(tt,b*0.001)
hold off
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!