# Crate spectrum_analyzer[−][src]

## Expand description

A simple and fast `no_std`

library to get the frequency spectrum of a digital signal
(e.g. audio) using FFT. It follows the KISS principle and consists of simple building
blocks/optional features.

In short, this is a convenient wrapper around a FFT implementation. You choose the implementation at compile time via Cargo features. This crate uses “microfft” by default for FFT. See README for more advise.

## Examples

### Scaling via dynamic closure

```
use spectrum_analyzer::{samples_fft_to_spectrum, FrequencyLimit};
// get data from audio source
let samples = vec![0.0, 1.1, 5.5, -5.5];
let res = samples_fft_to_spectrum(
&samples,
44100,
FrequencyLimit::All,
Some(&|val, info| val - info.min),
);
```

### Scaling via static function

```
use spectrum_analyzer::{samples_fft_to_spectrum, FrequencyLimit};
use spectrum_analyzer::scaling::scale_to_zero_to_one;
// get data from audio source
let samples = vec![0.0, 1.1, 5.5, -5.5];
let res = samples_fft_to_spectrum(
&samples,
44100,
FrequencyLimit::All,
Some(&scale_to_zero_to_one),
);
```

## Modules

Errors related to the spectrum analysis via FFT. Most probably, the errors will result in wrong input data, before the actual calculation has begun.

This module contains convenient public transform functions that you can use
as parameters in `crate::samples_fft_to_spectrum`

for scaling the
frequency value (the FFT result). They act as “idea/inspiration”. Feel free
to either compose them or create your own derivation from them.

Several window functions which you can apply before doing the FFT. For more information:

## Structs

Convenient wrapper around the processed FFT result which describes each frequency and
its value/amplitude in the analyzed slice of samples. It only consists of the frequencies
which were desired, e.g. specified via
`crate::limit::FrequencyLimit`

when `crate::samples_fft_to_spectrum`

was called.

## Enums

Can be used to specify a desired frequency limit. If you know that you only
need frequencies `f <= 1000Hz`

, `1000 <= f <= 6777`

, or `10000 <= f`

, then this
can help you to accelerate overall computation speed and memory usage.

Possible errors when creating a `FrequencyLimit`

-object.

## Functions

Takes an array of samples (length must be a power of 2), e.g. 2048, applies an FFT (using the specified FFT implementation) on it and returns all frequencies with their volume/magnitude.

## Type Definitions

A frequency. A convenient wrapper type around `f32`

.

The value of a frequency in a frequency spectrum. Convenient wrapper around `f32`

.
Not necessarily the magnitude of the complex numbers because scaling/normalization
functions could have been applied.