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" />

<p>
I’ve been on <a href="irc://irc.freenode.net/#math">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.
</p>

<p>
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.
</p>

<p>
There’s what seems to be
<a href="http://en.wikipedia.org/wiki/User:Kieff/Sine_from_square_waves">a
more analytic method of doing the Sine-into-Square-Waves decomposition</a>.
(There’s also
<a href="http://en.wikipedia.org/wiki/User_talk:Kieff#sines">more
about it</a>).
</p>

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

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

<p>
The C version is faster, but both produce identical results. The Perl version
requires <a href="http://pdl.perl.org">PDL - the Perl Data Language</a>.
</p>
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 ProjectModifiedEvent.java.
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.