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?

  • 1
    $\begingroup$ 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. $\endgroup$
    – Fat32
    Aug 3, 2016 at 17:54
  • $\begingroup$ 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. $\endgroup$
    – MBaz
    Aug 3, 2016 at 18:54
  • $\begingroup$ "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. $\endgroup$
    – agemO
    Jun 30, 2017 at 6:28

1 Answer 1


What is described in the question is very near the Discrete Wavelet Transform (DWT) with the use of the Haar Wavelet.

The DWT decomposes a signal into a sum of dilated and translated orthogonal functions that do not necessarily have to be trigonometric. The DWT does not transform a signal from the time domain to a frequency domain but to a scale space where the "time" dimension is preserved. The Haar wavelet is effectively just one period of a square wave and due to its dilation and replication as the transform progresses it would appear as occurring at different frequencies. For more information on the link between decomposition level and frequency please see this link

Another transform that might be of help here, is the Walsh-Hadamard transform which does exactly that, decompose a signal into a sum of square waveforms which are orthogonal (Please note the sequency there as well).

For a brief example that seems to be near what you are after, please see this link

Hope this helps.

  • $\begingroup$ I vote for Walsh! $\endgroup$
    – rrogers
    Aug 9, 2016 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.