I've been working with Fourier Series last weeks and I haven't found a solution for the problem I'm doing. I have the following function
It is defined as piecewise for the following intervals.
f(t) = sin(w*x) when 0 <= x <= Ts
f(t) = 0 when Ts < x <= T
where w= pi/Ts, T = 60/72 = 0.8333, and Ts= 2T/5 = 0.333 so, the intervals are [0,0.333] and (0.333,0.8333)
I had found the fourier series in Matlab when the intervals are symmetricals , lets say [0,0.333] and (0.333,0.666] but when I try to do any function with nonsymmetrical intervals I'm not able to find the correct solution.
I give another example of what I'm trying to find.
Lets suppose I have a square signal with amplitude $\pi$.
I obtained this when doing a symmetrical interval. Sym Interval
and this when non-symmetrical
I'm using the regular equations of Fourier Series to find Ao, Ak and Bk.4 considering that my input function is both even and odd I'm obtaining both coefficients Bk and Ak as well as Ao.
On matlab I'm obtaining my intervals by separated as follows:
T=60/72; %seconds
time=linspace(0,T,200);
Ts=2*T/5;
w1=pi/Ts;
Input=sin(w1*(time)).*(time <= Ts);
plot(time,Input,'-b','LineWidth',4) %Input Function to use
hold on
grid on
%% Fourier Series
syms t n x
k=15; %Number of Fourier Coefficients
f1=sin(w1*x);
f2=0;
lim_inf_1=0;
lim_sup_1=Ts;
lim_inf_2=Ts;
lim_sup_2=T;
Ao= (1/(lim_sup_1))*(double(int(f1,x,lim_inf_1,lim_sup_1))) + (1/(lim_sup_2))*double(int(f2,x,lim_inf_2,lim_sup_2))
A=(1/(lim_sup_1))*(int(f1.*cos(n*w1*x),x,lim_inf_1,lim_sup_1)) + (1/(lim_sup_2))*int(f2.*cos(n*w1*x),x,lim_inf_2,lim_sup_2);
B=(1/(lim_sup_1))*(int(f1.*sin(n*w1*x),x,lim_inf_1,lim_sup_1)) + (1/(lim_sup_2))*int(f2.*sin(n*w1*x),x,lim_inf_2,lim_sup_2);
time=linspace(-Ts,2.5*Ts,200);
for n=1:k
Ak(n,1)= double(subs(A));
Bk(n,1)= double(subs(B));
SF(:,n)=Ak(n)*cos(n*w1*(time)) + Bk(n)*sin(n*w1*(time));
end
Ak
Bk
SignalFourier = sum(SF,2) + Ao/2;
plot(time,SignalFourier,'-g','LineWidth',2)
I hope there is enough information so you can understand my problem, thanks everyone in advance for reading and spending your time on helping me.
It looks like your equations for $a$ and $b$ are wrong. You have
$$a_n=\frac1{T_s}\int_0^{T_s}\sin\frac{\pi x}{T_s}\cos\frac{n\pi x}{T_s}\,dx+\frac1T\int_{T_s}^T0\cos\frac{n\pi x}{T_s}\,dx$$
instead of
$$a_n=\frac2T\int_0^{T_s}\sin\frac{\pi x}{T_s}\cos\frac{2n\pi x}T\,dx+\frac2T\int_{T_s}^T0\cos\frac{2n\pi x}T\,dx.$$
Note that Wolfram uses period $T=2L$, and that the factors of $\cos$ (for $a$, and $\sin$ for $b$) use $T$, not $T_s$.