# Laplace transform of a square wave function

What is the right way to find the Laplace transform of this function:

The thing I noticed was:

$$f(t)=\text{A}\space\space\space\space\space\space\space\space\space\space 0\le t<\frac{\text{T}}{2}\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space f(t)=-\text{A}\space\space\space\space\space\space\space\space\space\space \frac{\text{T}}{2}

But how do find the complete Laplace transform of this function?

We can write the square wave function as $$f(t)=A\sum_{k=0}^{\infty} \left[u\left(t-kT\right)-2u\left(t-\frac{2k+1}{2}T\right)+u\left(t-(k+1)T\right)\right]$$ where $u(t)$ is the Heaviside's function. So the Laplace transform of $f(t)$ is \begin{align} F(s)&=A\sum_{k=0}^{\infty} \frac{1}{s}\left[\mathrm e^{-kTs}-2\mathrm e^{-\frac{2k+1}{2}Ts}+\mathrm e^{-(k+1)Ts}\right]\\ &=A\sum_{k=0}^{\infty} \frac{\mathrm e^{-kTs}}{s}\left[1-\mathrm e^{-\frac{Ts}{2}}\right]^2\\ &=\frac{A}{s}\left(1-\mathrm e^{-\frac{Ts}{2}}\right)^2\sum_{k=0}^{\infty} \mathrm e^{-kTs}\\ &=\frac{A}{s}\left(1-\mathrm e^{-\frac{Ts}{2}}\right)^2\frac{1}{1-\mathrm e^{-sT}}\\ &=\frac{A}{s}\frac{1-\mathrm e^{-\frac{Ts}{2}}}{1+\mathrm e^{-\frac{Ts}{2}}}\\ &=\frac{A}{s}\tanh\left(\frac{sT}{4}\right) \end{align}
$$\newcommand{\lap}{\mathscr{L}}\newcommand{\dd}{\mathrm{d}}$$ Let us use $$A=1$$. Function $$f$$ is periodic with period $$T$$. In fact, it suffices to defive this function over the interval $$[0, T]$$ $$$$f(t) = \begin{cases} 1,&\text{ for } 0 \leq t < \tfrac{T}{2} \\ -1, &\text{ for } \tfrac{T}{2} < t \leq T \end{cases}.$$$$ As a result, the Laplace transform of $$f$$ exists and it is given by \begin{align*} \lap\{f\}(s) {}={}& \frac{1}{1-e^{-Ts}}\int_0^{T}e^{-s\tau}f(\tau)\dd\tau \\ {}={}& \frac{1}{1-e^{-2Ts}} \left(\int_0^{\tfrac{T}{2}}e^{-s\tau}\dd\tau - \int_{\tfrac{T}{2}}^{T}e^{-s\tau}\dd\tau \right) \\ {}={}& \frac{1}{1-e^{-2Ts}} \left( \left.-\tfrac{1}{s}e^{-s\tau}\right|_0^{\tfrac{T}{2}} {}+{} \left.\tfrac{1}{s}e^{-s\tau}\right|_{\tfrac{T}{2}}^{T} \right) \\ {}={}& \ldots \\ {}={}& \frac{1}{s}\frac{e^{\tfrac{Ts}{2}}-1}{e^{\tfrac{Ts}{2}}+1} {}={} \frac{1}{s}\tanh\left(\tfrac{Ts}{4}\right). \end{align*}