liveBook · Manning

Triangle wave

As explained in Learn Haskell by Example

A triangle wave is a periodic waveform formed by two opposing linear slopes.

A triangle wave is a periodic waveform made from two opposing linear slopes. Across one cycle, its value rises from -1 to 1 during the first half, then falls back to -1 during the second. section 10.1.2

Implement one cycle as a Haskell function over a normalized position t:

  • Keep values outside the valid range constant at -1; audio generation normally supplies positions between 0 and 1. section 10.1.2

Turning the wave into a tone

A tone function repeatedly maps normalized positions through the triangle wave. Taking each sample index modulo the number of samples in one period sets the frequency; mapping tri over those positions produces the signal.

How Learn Haskell by Example covers it

How deep it goes
Defines the piecewise slopes and sampling process, while deferring behavior outside the normalized input range.
Examples
Uses a Haskell tri function, tone generation, and exported waveform visualizations.
What it assumes
Assumes basic functions and numeric sampling, while treating the waveform as a callable function from normalized position to sample.
What you can do after
Apply it by mapping a triangle-wave function over periodic sample positions to create an audio tone.
How it connects
Connects waveforms with functions, sampling, frequency, period, signals, and audio output.

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.