liveBook · Manning

Sinusoidal function

As explained in Learn Haskell by Example

A sine wave is a periodic waveform whose value follows the mathematical sine function.

A sinusoidal function generates a repeating sine-wave sample from a position within one period. In Haskell, model a waveform as `Double -> Sample`; `sin t = Prelude.sin (2 * pi * t)` maps an input between 0 and 1 to the wave's sample value, typically between -1 and 1. section 10.1.2

Use the function as part of a digital signal:

  • Scan through positions from 0 to 1 to trace one period of the waveform. section 10.1.2

Generate a tone

A five-second 220 Hz tone can be created with `tone sin 220 5`. Combining it with other waveforms and passing the result to `writeWav` produces an audible WAV file.

How Learn Haskell by Example covers it

How deep it goes
Defines the waveform, explains period scanning and frequency, and implements tone generation without developing further mathematics.
Examples
Uses `sin`, `tone sin 220 5`, and concatenated waveform export as concrete examples.
What you can do after
Builds a sine-wave audio signal and exports it as a WAV file.
How it connects
Connects periodic waveform, frequency, signal, tone, and WAV audio concepts.

Also explained in

Compare how 2 books explain sinusoidal function →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.