# Wavelet Decomposition

`D09-F05-A06` · Statistical Time Series → Decomposition and Cycles · archetype `record-transform` · difficulty 4/5 · verification **contract**

Full page: https://docs.thefintechbuilder.com/statistical-time-series/decomposition-and-cycles/wavelet-decomposition/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

```ts
import { haarWavelet } from "fintech-algorithms/statistical-time-series/decomposition-and-cycles/wavelet-decomposition";
```

## Signature

```ts
haarWavelet(values, levels)
```

Haar wavelet decomposition: splits the series into detail at successive scales plus a residual approximation. Unlike Fourier it localises in *time* as well as frequency, so it can say when a frequency was present.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `values` | `number[]` | yes | Observation series. Haar works on powers of two; a shorter series is padded. |
| `levels` | `number` | yes | Number of decomposition levels. Each halves the resolution of the approximation. · min: 1, integer: true |

## Returns

`{ details, approximation, levels }`

Detail coefficients per level plus the final approximation.

## Errors

- When levels exceeds what the series length supports — throws

## Complexity

Time `O(n)`, space `O(n)`.

## Worked example

Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

### Input

`values`:

```json
[
  100.0901805654,
  101.3367333472,
  102.4083163971,
  102.9128416721,
  103.198587938,
  102.4311805579
]
```

Showing 6 of 192 elements.

`levels`:

```json
4
```

### Call

```ts
haarWavelet(values, levels)
```

### Returns

object with 11 fields: approximation_coefficients, detail_coefficients, approximation_component, detail_components, reconstructed, levels, wavelet, boundary_mode, …

```json
{
  "approximation_coefficients": [
    406.2370710410249,
    400.6458644165249,
    408.18250013307494,
    406.58956430514996,
    415.4042925955248,
    408.8285391202
  ],
  "detail_coefficients": [
    [
      -0.8814459251177285,
      -0.35675324323251195,
      0.5426389624013097,
      0.7206078638433713,
      0.22202008434506101,
      -0.6488746408711917
    ],
    [
      -1.9471220782999858,
      1.5938553549500085,
      -0.32437943830000726,
      -0.7441778894000111,
      2.4193453339000146,
      -0.5144175941000312
    ],
    [
      -0.46801782111276313,
      -3.419692948980583,
      4.169455460606318,
      0.2223496978931099,
      -5.578639117285321,
      3.8376397376595466
    ]
  ],
  "approximation_component": [
    101.55926776025618,
    101.55926776025618,
    101.55926776025618,
    101.55926776025618,
    101.55926776025618,
    101.55926776025618
  ],
  "detail_components": [
    [
      -0.6232763908999955,
      0.6232763908999955,
      -0.252262637500003,
      0.252262637500003,
      0.38370369004999805,
      -0.38370369004999805
    ],
    [
      -0.9735610391499928,
      -0.9735610391499928,
      0.9735610391499928,
      0.9735610391499928,
      0.7969276774750041,
      0.7969276774750041
    ],
    [
      -0.16546928751249362,
      -0.16546928751249362,
      -0.16546928751249362,
      -0.16546928751249362,
      0.16546928751249362,
      0.16546928751249362
    ]
  ],
  "reconstructed": [
    100.09018056539995,
    101.33673334719994,
    102.40831639709995,
    102.91284167209994,
    103.19858793799993,
    102.43118055789995
  ],
  "levels": 4,
  "wavelet": "haar",
  "boundary_mode": "periodization",
  "approximation_energy_fraction": 0.999765090759817,
  "detail_energy_fractions": [
    0.000018209004639336907,
    0.00005361952217361794,
    0.0001317428663664597,
    0.00003133784700365802
  ],
  "reconstruction_max_error": 9.947598300641403e-14
}
```

## Other exports

`stlDecompose`, `hpFilter`, `bkFilter`, `cfFilter`, `fftPeriodogram`, `runTopic`. Every module additionally exports `run` as an alias of its primary
function, and a `meta` object carrying its catalog id, domain, family, shape and article URL.

## Verification and provenance

Tier: **contract**.

The module loads, the entry point is callable and its declared signature matches the compiled code. The example below is real captured output, but no independently published figure asserts the numbers.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.1.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/statistical-time-series/decomposition-and-cycles/wavelet-decomposition/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/statistical-time-series/decomposition-and-cycles/wavelet-decomposition/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/statistical-time-series/llms.txt
