0
votes

OK let me cut to the chase.

I am trying to use MATLAB to (i)generate the fourier series based on known coefficients and thereafter (ii) determine the output function when the impulse is known.

So far I used this code to obtain the fourier series:

clear all
syms x k L n
evalin(symengine,'assume(k,Type::Integer)');
a = @(f,x,k,L) (2/(pi*k))* sin((pi*k)/(2 * L));
fs = @(f,x,n,L) (1/2*L) + symsum(a(f,x,k,L)*cos(k*2*pi*x/L),k,1,n);
f = x;
pretty(fs(f,x,11,1))

This works as desired. Now the impulse response is as follows:

h = heaviside(x) * exp(-5*x);

Now, in order to obtain the function, we need to perform the convolution with the respective functions.But when I input the following, I get the error:

x1 = fs(f,x,1,1);
conv(h,x1)

Undefined function 'conv2' for input arguments of type 'sym'.
Error in conv (line 38) 
c = conv2(a(:),b(:),shape);

Any help would be appreciated

1

1 Answers

0
votes

That is because conv is only defined for numeric inputs. If you want to find the convolution symbolically, you'll have to input the equation yourself symbolically using integration.

If you recall, the convolution integral is defined as:

Source: Wikipedia

Therefore, you would do this:

syms x tau;
F = int(h(tau)*x1(x-tau),'tau',-inf,+inf);

int is a function in MATLAB that does symbolic integration for you. Also note that the convolution integral is commutative, and so this also works:

Source: Wikipedia

Therefore, you should also get the same answer if you did:

syms x tau;
F = int(h(x-tau)*x1(tau),'tau',-inf,+inf);

Hope this helps!