# How can I decompose a signal into square waves?

I am dealing with signals that are a superposition of different square waves with different amplitudes and phases. Normally, one would decompose a signal into sine waves with help of the Fourier transform, but in this particular case a decomposition into square waves would be much more effective. A Fourier transform would produce a very complicated spectrum, while a square wave decomposition should give just a few clear lines.

I know that such a decomposition is possible. In fact, I could use any periodic function as a basis for the decomposition and this is mentioned in many texts on the subject. But I could never find a formula or an explicit example for a decomposition into a non-sinusoidal basis.

My approach to decompose a signal consisting of the $N$ samples $x_k$, was to use a DFT-like formula $$u_k = \sum_{n=0}^{N-1} x_n \, \mathcal{R}_k(n)$$ where $\mathcal{R}_k$ is a real-valued square wave with a frequency $k$ times the base frequency. But this is certainly not complete, since I do not obtain any phase information for the constituent square waves, and I couldn't invert the procedure.

How can I decompose my signals into square waves with well-defined amplitude and phase?

• a serious decomposition would start by finding (or defining) a base of N signal vectors, which would span the signal vector space of your interest. Then you would youse an inner product measure to compute the coefficients of those signal decompositions in terms of base vectors. – Fat32 Aug 3 '16 at 17:54
• Fat32 is right: you want to be sure the signals you're interested in are spanned by the set of square waves you've choses. In general you'll also want the basis to be orthonormal. – MBaz Aug 3 '16 at 18:54
• "But this is certainly not complete, since I do not obtain any phase information for the constituent square waves" : In a Fourier transform for a single frequency you need two reals(or one complex) coefficients, the first one is the result of the convolution with a cosine and the second one with a sine (which is just a $\frac{\pi}{2}$ shifted cosine). So I guess that for squares and for a given period $T$ you also need to decompose on a $\frac{T}{2}$ shifted square wave. – agemO Jun 30 '17 at 6:28