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

%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.

 Accepted Answer

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 Comments

@Paul, When writting in mathematical expression, h(t) = 𝛿(t-0.02). I expect the impulse signal to shift right by 0.02 seconds after plotting it.
Symbolic Math Toolbox version of fplot ignores the presence of dirac functions in the expression to be plotted. So with h(t) defined like this:
syms t
h(t) = dirac(t-0.02);
the fplot of h(t) is zero, because that's all that's left if the dirac is ignored
fplot(h(t))
But h(t) can still be used mathematically, for example
2*(h(t))
ans = 
@Paul, is there any method to plot the dirac h(t) function provided that I am using Symbolic Math Toolbox? That's because I'd need to present the h(t) function graphically. Thanks.
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...
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.

Sign in to comment.

More Answers (0)

Asked:

on 5 Dec 2022

Edited:

on 5 Dec 2022

Community Treasure Hunt

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

Start Hunting!