Error using sym/subsindex when doing convolution of two signals (cosine function and impulse function) in MATLAB.

1 次查看(过去 30 天)
%create symbolic functions x, a, b, c, d, e, f_c with independent variable t
syms x a h b c d e f_c t tau
x(t) = cos(100*pi*t);
a(t) = x(0.4*t);
%plot signal a(t)
figure
fplot(a)
xlim([-0.5 0.5]),ylim([-2 2])
title ('Time domain of signal a(t)')
xlabel('Time, t')
ylabel('Amplitude, a(t)')
grid on
%plot signal h(t)
figure
h = stem([0]+0.02,[1]);
%plot(h.XData,h.YData)
xlim([-0.5 0.5]),ylim([-2 2])
title ('Time domain of signal h(t)')
xlabel('Time, t')
ylabel('Amplitude, h(t)')
grid on
fplot(int(a(tau)*h(t-tau), 'tau', -inf, inf))
xlim([-1 1]),ylim([-5 5])
title ('Time domain of signal a(t)')
xlabel('Time, t')
ylabel('Amplitude, b(t)')
grid on
% In Line 26, it shows an error where it mentioned Invalid indexing or function definition. I would like to integrate the signal by switching t to tau domain to solve the convolution and the code is written above.

采纳的回答

Paul
Paul 2022-12-5
As written, h is Stem object. However, to use int, h(t) needs to be defined as a symbolic function of t (in the same manner as x(t) and a(t)). From looking at the code, maybe h(t) should be defined as
h(t) = dirac(t-0.02);
but that's just an educated guess on my part.
If that's not what's needed, can you describe h(t) in mathematical terms?
  5 个评论
Walter Roberson
Walter Roberson 2022-12-5
Dirac Delta is not a function: it is a distribution. It is something whose infinitely-thin integral is 1, but which is everywhere zero everywhere else. Take a box with area 1 and squeeze it taller and thinner, the limit of a box from to with height as epsilon goes to 0 so that the area is --> 1. No function can have that property.
If you evaluate
dirac(-eps(0))
ans = 0
dirac(0)
ans = Inf
dirac(eps(0))
ans = 0
and plotting cannot draw something that is infinitely tall so plotting has to leave it out.
If you have an expression that includes a dirac() that is not inside an int(), then that expression is not technically a function.
In order to plot something like this, you would have to use findSymType or similar to locate the dirac() expressions, and then you would have to solve() to figure out the conditions under which the expression was 0, and evaluate the overall expression at those locations but with the dirac() substituted as 1. Unfortunately, there might not be a closed form expression for the situations under which the expression inside the dirac is 0...
Paul
Paul 2022-12-5
编辑:Paul 2022-12-5
No, there's no function that will plot a representation of the Dirac delta (dirac) as far as I know. You'd have to do it by hand. For example
syms t
h(t) = sin(t) + 2*dirac(t-1);
hax = gca;
hold on
fplot(hax,h(t))
stem(hax,1,2,'^')
I don't think it would be too hard to automate a process to represent the impulses by scaled, vertical arrrows that would be applicable to many cases of interest.

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by