Skip to content

aicodix/dsp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a work in progress and a long overdue attempt to bring all our DSP code together and make it reusable for our future projects.

Before using any of this you should enter the tests directory and execute "make". This will check if your compiler is able to create binaries that are able to produce correct results when executed.

What we have included so far:

When working with Floating-point arithmetic we soon realize, that addition is not necessarily associative. For example, whenever we need to add values with an ever decreasing magnitude to a running sum with an ever increasing magnitude, the Kahan summation algorithm comes in handy and helps keeping the error growth small.

Implemented are the follwing Window functions:

Implemented are the following finite impulse response filters:

The exponential moving average is an infinite impulse response low-pass filter. There is also support for cascading, to improve roll-off while a correction factor helps to keep the same cutoff frequency.

The following infinite impulse response digital biquad filter implementations are available:

A notch filter at DC helps removing DC bias.

Normalizers for periodic signals.

Numerically controlled oscillator implemented using a phasor and complex multiplication instead of a lookup table.

Fs/4 Complex down conversion

Discrete Hilbert transform

Frequency modulation demodulation with and without atan2.

Amplitude modulation demodulation with automatic gain control.

atan and atan2.

Exponentiation approximations.

When working on a device where multiplication is expensive, the CORDIC comes in handy for computing trigonometric functions.

The following implementations are a good (max 1 LSB error at full range) starting point for your own designs:

Implemented are the following trigger functions:

The simple moving average gives us the mean of the last N data points.

  • SMA1 computes the sum of its internal history buffer at each new input from scratch is and therefore very slow.
  • SMA2 updates its internal sum using only the new input and the oldest value in the history buffer. It is therefore the fastest of all and works perfect with integers but suffers from drift when used with floats on sequences having a high dynamic range.
  • SMA3 is based on SMA2 but uses the Kahan summation algorithm to reduce drift significantly.
  • SMA4 uses a tree and only updates nodes that depend on the new input value and is slower than SMA3 but it has no drift.

The sliding window accelerator uses a tree and only updates nodes that depend on the new input value for the pairwise reduction.

Amortized O(1) moving extrema implementations of:

  • Moving Minimum
  • Moving Maximum

The Bip buffer provides contiguous block access to the last N value stored in a circular buffer.

Example:

DSP::BipBuffer<TYPE, NUM> history;
*snip*
const TYPE *buf = history(new_value);
*snip*
TYPE newest_value = buf[NUM-1];
TYPE previous_value = buf[NUM-2];
TYPE oldest_value = buf[0];
*snip*
DSP::FastFourierTransform<NUM, TYPE, -1> fwd;
TYPE out[NUM];
fwd(out, history(another_value));

A Digital delay line can be used to align signals with different delays - after filtering, for example.

A ring buffer based, fixed-size double-ended queue.

A fixed-size stack with access to the first element.

Some calculus functions:

Some constants we need

Interface for reading and writing PCM data

Read and write WAV files

Interface for reading and writing pixel data

Read and write Netpbm files

Implemented Simple linear regression for Regression analysis of data.

The Theil-Sen estimator is a robust line fitting algorithm.

The repeated median estimator is a robust line fitting algorithm.

Faster alternative (no Inf/NaN handling) to the std::complex implementation.

Mixed-radix decimation-in-time fast Fourier transform

Some everyday helpers:

Decibel calculation helpers.

When working with Analog-to-digital and Digital-to-analog converters, we often face the ugly truth, that we can't always have a precise Sampling rate. But if we can estimate the Sampling frequency offset, we can correct it by Resampling the sampled data.

Interpolation via frequency-domain zero padding.

Sometimes we only need trigonometric functions that stay on the unit circle:

Some least mean squares filter implementations:

  • Normalized Least Mean Squares
  • Normalized Complex Least Mean Squares