not able to calculate convolution sum properly without convolution command

not able to calculate convolution sum properly. i have writen the following code but it is giving me wrong answer. close all clear all step=0.001 th=0:step:10 th1=0:step:1 th2=1:step:2 th3=2:step:10 th=[th1 th2 th3] x1=zeros(size(th1)) x2=ones(size(th2)) x3=zeros(size(th3)) x=[x1 x2 x3] step=0.001 m=0:step:10 m1=0:step:1 m2=1:step:2 m3=2:step:10 m=[m1 m2 m3] y1=zeros(size(m1)) y2=ones(size(m2)) y3=zeros(size(m3)) z=[y1 y2 y3] t=-1 subplot(6,1,1) plot(th,x,-m+t,z,'r') legend('x(\tau)','h(t-\tau)'); t=2.5 subplot(6,1,2) plot(th,x,-m+t,z,'r') legend('x(\tau)','h(t-\tau)'); t=3 subplot(6,1,3) plot(th,x,-m+t,z,'r') legend('x(\tau)','h(t-\tau)'); t=3.5 subplot(6,1,4) plot(th,x,-m+t,z,'r') legend('x(\tau)','h(t-\tau)'); t=4.5 subplot(6,1,5) plot(th,x,-m+t,z,'r') legend('x(\tau)','h(t-\tau)'); syms t r f=1; j1=int(f,r,1,t-1) j2=int(f,r,1,2) j3=int(f,r,t-2,2) j=[j1 j2 j3] b1=2:0.1:3 b2=3 b3=3:0.1:4
y1=b1-2 y2=1*ones(size(b2)) y3=4-b3
subplot(6,1,6) plot(b1,y1,b2,y2,b3,y3,'g')

2 件のコメント

irtaza anwar
irtaza anwar 2015 年 4 月 23 日
now i have used the conv command but it gives error"Error using plot Vectors must be the same lengths.
Error in cov (line 23) plot(ty,k)" the code is step=0.01 th=0:step:10
th1=0:step:1 th2=1+step:step:2 th3=2+step:step:10 th=[th1 th2 th3] x1=zeros(size(th1)) x2=ones(size(th2)) x3=zeros(size(th3)) x=[x1 x2 x3] m=0:step:10 m1=0+step:step:1 m2=1+step:step:2 m3=2+step:step:10 m=[m1 m2 m3] y1=zeros(size(m1)) y2=ones(size(m2)) y3=zeros(size(m3)) y=[y1 y2 y3] k=conv(x,y)*step ty=0:step:20 plot(ty,k)
Image Analyst
Image Analyst 2015 年 4 月 23 日
Try using the 'same' option of conv().

サインインしてコメントする。

 採用された回答

Image Analyst
Image Analyst 2015 年 4 月 23 日

0 投票

Well, then, I'd say that's a good reason to use the conv() function.
By the way, read http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup to learn how to format your code so it appears correctly here.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNumber games についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by