convolute two functions(two signals)

6 次查看(过去 30 天)
hi everbody i'd like to make a script file which convolute to two function . so i started to code this but unfortunately it doesn't work can you help me thx in advanced
here is my source code.
function x = conv(t)
% x = 1 pour t compris en -pi/2 et pi/2 et 0 ailleurs
if (t<abs(pi/2))
x=1;
else
x=0;
end
y=conv(x,x);
plot(y)

采纳的回答

taftoof
taftoof 2012-5-26
function x = myconv(t)
x = abs(t) < pi/2;
end
w=conv(x,x);
plot(w)
like that what're you think?
  6 个评论
Walter Roberson
Walter Roberson 2012-5-27
function x = myconv(t)
x = abs(t) < pi/2;
w=conv(x,x);
plot(w)
Image Analyst
Image Analyst 2012-5-27
You can "almost exactly" do what you say like this
function x(t) % Note: no output arguments will be passed out
small_x = abs(t) < pi/2; % Can't also call this x since function name is x.
w = conv(small_x, small_x);
plot(w);
Since, after I asked, you said you don't need any output argument and that you now want the function to be called "x" instead of "myconv." I say "almost" because you can't do exactly what you say because you said the function should be called x but then inside you want x to be convolved (not "covoluted") with x which would be a recursive mess, IF it could even be done at all. But I think Walter's code is better.

请先登录,再进行评论。

更多回答(3 个)

Walter Roberson
Walter Roberson 2012-5-26
What are the two functions? You are convolving something with itself.
Is t a vector or a scalar? "if" applied to a vector is treated as if you had coded "if all(....)" and so is true only if the logical condition applies to all the logical vector values. As it probably does not, you are assigning the scalar 0 to x. Hint: read about logical indexing.

Image Analyst
Image Analyst 2012-5-26
Maybe you mean
x = t < pi/2; % x will be a logical matrix.
y = conv(double(x), double(x));
not really sure -- seems like a weird thing to want to do. You might also be interested in the xcorr() function.

taftoof
taftoof 2012-5-26
hi guys
here is my function
x(t)=1 if -pi/2<t<pi/2 x(t)=0 otherwise
and i'd like to convoluate x(t) with x(t) conv(x(t),x(t)) thx in advanced
  6 个评论
Image Analyst
Image Analyst 2012-5-26
Not to mention the fact that your original code, my code, and your second code here don't do that you asked for. Do you know that abs(pi/2) is the same as pi/2? Do you know that t<abs(pi/2) is the same as t<pi/2? But it appears NOW that you have a different condition and that is "-pi/2<t<pi/2" I hope you can figure out why that is NOT THE SAME as t<abs(pi/2). So, once you've understood that you can do
x = abs(t) < pi/2;
That will set x = 1 even if t = -1, whereas your and my original code won't (it does your original criteria instead, which is different).
Walter Roberson
Walter Roberson 2012-5-26
Change your "function x = conv(t)" line to "function x = myconv(t)" and save the result in the file myconv.m and then delete the conv.m that you created.

请先登录,再进行评论。

类别

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