MEMBERS
TOOLS
COMPUTER CODE

Square Wave Transform source code



     Square Wave Transform Tool for MATLAB
Skliar O., Monge R. E., Oviedo G. and Gapper S. (2016). A New Method for the Analysis of Signals: The Square Wave Transform, Revista de Matemática: Teoría y Aplicaciones 2016, Vol. 23(1), pp. 85-110.
Skliar O., Monge R. E. and Gapper S. (2016). Analysis of time series and signals using the Square Wave Method. arXiv:1608.02166 [cs.NA].

Usage

swt is a user-defined function that requires three parameters to work properly. The first parameter V corresponds to the time series to be analyzed, input as a standard MATLAB vector. The second parameter f corresponds to the sampling frequency in Hz of the data in parameter V. Finally, the third parameter Dt corresponds to the time interval in seconds of the entire data set.

The outputs are a two-column matrix S, and a single numerical value that indicates the approximation quality, referred to as Dm. The matrix S will have a row for each data value in the input data set, in which the value in the first column correspond to the square wave frequency (fi in the published paper) and the value in the second column corresponds to the square wave coefficient (Ci in the published paper).

If, within a certain time interval, a given time series is an adequate representation of a signal, then the SWM analysis of that time series, in that same time interval, can also be considered an analysis of that signal in that interval.

The approximation obtained with the SWM for each of the numerical values in the time series analyzed is outstanding. Let Vi (for i = 1,2,…,n) be the i th value of the time series analyzed, and Vicomp, the corresponding approximation computed by adding all the square waves (whose coefficients and frequencies were computed by the SWM implementation) for that point. Thus, |Vi - Vicomp| is the modulus (absolute value) of the difference between those two values. There will be a modulus of this type for each data point in the time series. We can, therefore, compute a maximum of this difference between the time series:

Dm=max |Vi - Vicomp|.

Therefore, each computation using the swt function defined here will have the following outputs:

  1. The sequence of dyads, in the form of “frequencies - coefficients” (fi - Ci) for each of the values in the time series being analyzed. This sequence provides a detailed view of the time series in the frequency domain. This representation is known as Square Wave Transform (SWT) and its acronym is used for the MATLAB command (swt).
  2. The computed value for Dm.

      Download swt.m

     Square Wave Transform Tool for C
Skliar O., Monge R. E., Oviedo G. and Gapper S. (2016). A New Method for the Analysis of Signals: The Square Wave Transform, Revista de Matemática: Teoría y Aplicaciones 2016, Vol. 23(1), pp. 85-110.
Skliar O., Monge R. E. and Gapper S. (2016). Analysis of time series and signals using the Square Wave Method. arXiv:1608.02166 [cs.NA].

Usage

The C source code (which has a dependency on BLAS and LAPACK–standard linear algebra routines) implements the basic functionality of the SWM as a simple command line program that requires three arguments. The first parameter corresponds to the sampling frequency in Hz of the data to be analyzed. The second parameter corresponds to the time interval in seconds of the entire data set. Finally, the third parameter must reference a text file with one line per data point to be analyzed.

The code is clearly commented and each important step in the calculation has been placed in separate functions to make it easy to adapt to other hardware environments.

The outputs are a list of dyads in standard output (which can be redirected using shell features) and a single numerical value that indicates the approximation quality, referred to as Dm. Each dyad will contain the data value corresponding to the square wave frequency (fi in the published paper) and the value that corresponds to the square wave coefficient (Ci in the published paper).

If, within a certain time interval, a given time series is an adequate representation of a signal, then the SWM analysis of that time series, in that same time interval, can also be considered an analysis of that signal in that interval.

The approximation obtained with the SWM for each of the numerical values in the time series analyzed is outstanding. Let Vi (for i = 1,2,…,n) be the i th value of the time series analyzed, and Vicomp, the corresponding approximation computed by adding all the square waves (whose coefficients and frequencies were computed by the SWM implementation) for that point. Thus, |Vi - Vicomp| is the modulus (absolute value) of the difference between those two values. There will be a modulus of this type for each data point in the time series. We can, therefore, compute a maximum of this difference between the time series:

Dm=max |Vi - Vicomp|.

Therefore, each computation using the C code defined here will have the following outputs:

  1. The sequence of dyads, in the form of “(frequency, coefficient)” (fi, Ci) for each of the values in the time series being analyzed. This sequence provides a detailed view of the time series in the frequency domain. This representation is known as Square Wave Transform (SWT) and its acronym is used for the name of the binary file once it is compiled and linked).
  2. The computed value for Dm.

      Download swt.c


Back to publications