shlomi-fish-homepage / t2 / open-source / bits-and-bobs / square-waves-decomposition / index.html.wml

#include '../template.wml'

<latemp_subject "Square Waves Decomposition of a Sine Wave" />

<latemp_meta_desc "Square Waves Decomposition of a Sine Wave" />

I’ve been on <a href="irc://">Freenode’s #math
channel</a> the other day when someone logged in and asked if and how a
sine wave can be decomposed into a series of square waves (with integral
frequencies). I wrote the following programs to investigate this.

They use a greedy algorithm, that tries each frequency and then finds
the amplitude of the corresponding wave that reduces the energy of the total
wave by as much as possible.

There’s what seems to be
<a href="">a
more analytic method of doing the Sine-into-Square-Waves decomposition</a>.
(There’s also
<a href="">more
about it</a>).

<h2 id="download">Downloads</h2>

<a href="">Perl program version 0.1.0</a>
<a href="square-waves-decompose-0.1.0.c">C program version 0.1.0</a>

The C version is faster, but both produce identical results. The Perl version
requires <a href="">PDL - the Perl Data Language</a>.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.