I've a square wave function that is equal to $q$ when $0<t<T_1$ and it is equal to $z$ when $T_1<t<T_2$ and we know that $T=T_1+T_2$ where $T$ is one period. I want to find the fourier series of that function using:
$$f(t)=a_0+\sum_{n=1}^\infty(a_n\cdot\cos(nwt)+b_n\cdot\sin(nwt))$$
And I know that $w=\frac{2\pi}{T}=\frac{2\pi}{T_1+T_2}$.
I know that:
- $$a_0=\frac{1}{T}\int_0^Tf(t)\space dt=\frac{1}{T_1+T_2}\cdot\left(\int_0^{T_1}q\space dt+\int_{T_1}^{T_2}z\space dt\right)$$
- $$a_n=\frac{2}{T}\int_0^Tf(t)\cos(nwt)\space dt=\frac{2}{T_1+T_2}\cdot\left(\int_0^{T_1}q\cos(nwt)\space dt+\int_{T_1}^{T_2}z\cos(nwt)\space dt\right)$$
- $$b_n=\frac{2}{T}\int_0^Tf(t)\sin(nwt)\space dt=\frac{2}{T_1+T_2}\cdot\left(\int_0^{T_1}q\sin(nwt)\space dt+\int_{T_1}^{T_2}z\sin(nwt)\space dt\right)$$
Is there something wrong in my analysis because when I plot the function I get nothing :(
Your wave is defined for $t\in(0,T_1),(T_1,T_2)$ but it's undefined over $(T_2,T)$, which might be where you're getting confused. I've found the coefficients for the wave $f(t)=q$ for $t\in(0,T_1)$, $f(t)=z$ for $t\in(T_1,T)$, with period $T$. I'm not sure where your mistake is but perhaps you can compare your coefficients with mine.
Define $f$ as the original function, then scale the $x$ co-ordinate by $\frac{T}{2\pi}$, so that the wave has a full period inside $(-\pi,\pi)$. Label this re-scaled function $g$. Then, $g$ takes three values over the interval $(-\pi,\pi)$; either $z,q,z$ or $q,z,q$, depending on the values of $T_1$ and $T_2$. The wave has two discontinuities in the interval $(-\pi,\pi)$; one at $t=0$ and one at $\alpha=2\pi\left(\frac{T_1}{T}-\left\lfloor\frac{T_1}{T}\right\rfloor\right)$. If $T_1<T_2$, then $\alpha\in(0,\pi)$, otherwise $\alpha\in(-\pi,0)$.
$$\begin{aligned} &f(t)=\begin{cases} q:&\frac{t}{T}-\lfloor\frac{t}{T}\rfloor<\frac{T_1}{T}-\lfloor\frac{T_1}{T}\rfloor \\ z:&\text{else} \end{cases} \\ &g(t)=f\left(\frac{T}{2\pi}t\right) \\ &T_2>T_1\quad\Rightarrow\quad g(t)=\begin{cases} z:&t\in(-\pi,0) \\ q:&t\in(0,\alpha) \\ z:&t\in(\alpha,\pi) \end{cases} \end{aligned}$$
Find the coefficients of $g(t)$ by integrating over the intervals $(-\pi,0),(0,\alpha),(\alpha,\pi)$.
$$\begin{aligned} a_0&=\frac{1}{2\pi}\left[z\pi+\alpha q+(\pi-\alpha)z\right] \\ a_n&=\frac1\pi\left(z\int_{-\pi}^0 \cos(nt)+q\int_{0}^\alpha \cos(nt)+z\int_{\alpha}^\pi \cos(nt)\right) \\ &=\frac{1}{n\pi}\left[{z\sin(\pi n)}+{(q-z)\sin(\alpha n)}\right] \\ b_n&=\frac{1}{n\pi}\left[q-z+(z-q)\cos(\alpha n)\right] \\ \end{aligned}$$
The figure below is the square wave, in black, for $q=4.4,z=-3.6,T_1=3.85,T=12.9$, with the Fourier series, in red, up to and including $n=13$.