I am trying to determine the approximation of the following function as a ctfs:
x(t) = exp(-7|t|)*cos(10*pi*t)
for -0.5 <= t < 0.5
I was told to use trigonometric form of continuous time Fourier series (CTFS) to calculate a[k]
and b[k]
of x(t)
, where k
is harmonic number. Kmax = 4
.
I have the following code, and while it doesn't give me any errors. I don't know how to check if it is right, or what I am doing in general. This is my first time using matlab. Can someone please help me?
fun = @(t) exp((-7).*abs(t)).*cos(10.*pi.*t);
a = @(k, T, t) fun(t).*cos((2.*pi.*k.*t)./(T));
b = @(k, T, t) fun(t).*sin((2.*pi.*k.*t)./(T));
T = 1; %T =0.5 - (-0.5) where T is fundamental period of x(t)
t = -0.5: T/1000: 0.5;
Kmax = 4; % part a
for k=1:Kmax
ax = (2./T).*integral(@(t)a(k,T,t),0,T)
end
for k=1:Kmax
a0 = (1./T).*integral(@(t)fun(t),0,T)
end
for k=1:Kmax
bx = (2./T).*integral(@(t)b(k,T,t),0,T)
end
% Calcultating x_aprox
x_approx = a0;
for k=1:Kmax
x_approx = x_approx + ax*cos(2*pi*k*t/T) + bx*sin(2*pi*k*t/T);
end