# helia_edge.layers.spectral

## Spectral Layers API

**Classes**

| Name | Description |
| --- | --- |
| `StftMagnitude` | Magnitude of a short-time Fourier transform with a fixed, stored basis |

**Functions**

| Name | Description |
| --- | --- |
| `max_projection` | Magnitude of complex values without a square root, within 0.25% |

## helia_edge.layers.spectral.DIRECTIONS

`constant` · `python`

```python
DIRECTIONS = 9
```

Source: `helia_edge/layers/spectral.py:16`

## helia_edge.layers.spectral.max_projection

`function` · `python`

```python
max_projection(pairs)
```

Magnitude of complex values as the largest of 9 projections of (|re|, |im|), within 0.25% in float32.

The directions are spread from 0 to 90 degrees and scaled so the error is centred: the result is
within -0.25% and +0.25% of ``sqrt(re**2 + im**2)``. It needs no square root, so integer kernels
run it.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| pairs |  | Required | Real and imaginary parts on the last axis, ``(..., 2)``, rank 4. |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
|  |  | The magnitudes, ``(...)``. |

Source: `helia_edge/layers/spectral.py:19`

## helia_edge.layers.spectral.StftMagnitude

`class` · `python`

```python
StftMagnitude(
    frame_length: int,
    frame_step: int,
    bins: int,
    padding: tuple[int, int] = (0, 0),
    magnitude: str = 'sqrt',
    **kwargs={},
)
```

Magnitude of a short-time Fourier transform computed as a strided convolution with a stored basis.

The input ``(batch, samples)`` is reflect-padded by ``padding`` (start, end) samples and convolved
with ``basis`` (``frame_length`` taps, ``frame_step`` stride, ``2 * bins`` filters: the real parts of
every bin, then the imaginary parts). The output is the magnitude of shape ``(batch, frames, bins)``:
``sqrt(re**2 + im**2)``, or ``max_projection`` of (re, im). The basis is a non-trainable weight, so a
model's window and transform travel with its weights.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| frame_length | int | Required | Samples per frame. |
| frame_step | int | Required | Samples between frames. |
| bins | int | Required | Frequency bins. |
| padding | tuple[int, int] | (0, 0) | Samples of reflect padding before the first and after the last sample. |
| magnitude | str | 'sqrt' | ``sqrt`` (exact) or ``max_projection`` (no square root, within 0.25%). |

Source: `helia_edge/layers/spectral.py:39`

### helia_edge.layers.spectral.StftMagnitude.frame_length

`attribute` · `python`

```python
frame_length = frame_length
```

Source: `helia_edge/layers/spectral.py:69`

### helia_edge.layers.spectral.StftMagnitude.frame_step

`attribute` · `python`

```python
frame_step = frame_step
```

Source: `helia_edge/layers/spectral.py:70`

### helia_edge.layers.spectral.StftMagnitude.bins

`attribute` · `python`

```python
bins = bins
```

Source: `helia_edge/layers/spectral.py:71`

### helia_edge.layers.spectral.StftMagnitude.padding

`attribute` · `python`

```python
padding = tuple(padding)
```

Source: `helia_edge/layers/spectral.py:72`

### helia_edge.layers.spectral.StftMagnitude.magnitude

`attribute` · `python`

```python
magnitude = magnitude
```

Source: `helia_edge/layers/spectral.py:73`

### helia_edge.layers.spectral.StftMagnitude.build

`method` · `python`

```python
build(input_shape)
```

Source: `helia_edge/layers/spectral.py:75`

### helia_edge.layers.spectral.StftMagnitude.call

`method` · `python`

```python
call(x)
```

Source: `helia_edge/layers/spectral.py:80`

### helia_edge.layers.spectral.StftMagnitude.compute_output_shape

`method` · `python`

```python
compute_output_shape(input_shape)
```

Source: `helia_edge/layers/spectral.py:89`

### helia_edge.layers.spectral.StftMagnitude.get_config

`method` · `python`

```python
get_config()
```

Source: `helia_edge/layers/spectral.py:95`
