spectrum

Transformations of frequency domain information

This module is a collection of functions to work with spectrum of a signal

Before we do anything in the field of spectral modeling, we must be able to competently compute the spectrum of a signal. The spectrum is given by the Fourier transform of a signal, but in virtually all cases, the result from the DFT has to be converted into polar coordinates in order to permit the desired modifications in an appropriate way as magnitudes and phases

npm install dsp-spectrum

This module contains function to work with the result of a DFT (or FFT), the signal in the frequency domain.

This is part of dsp-kit

References

  • Polar notation: http://www.dspguide.com/ch8/8.htm
Source:
Example
const dsp = require('dsp-kit')
dsp.spectrum(dft.fft(signal))

Methods

(static) bandFrequency(index, size, sampleRate) → {Number}

Calculates the center frequency of an DFT band (or bin)

Parameters:
Name Type Description
index Integer

The index of the FFT band.

size Integer

the DFT (or FFT) buffer size

sampleRate Integer

the sample rate of the original signal

Source:
Returns:
  • the center frequency of the DFT band

    Type
    Number
  • The middle frequency in Hz.

(static) bandWidth(size, sampleRate) → {Number}

Get band width of a result of a fourier transformation

It calculates the size of each bin of the spectrum in Hertzs.

Parameters:
Name Type Description
size Integer

the DFT (or FFT) buffer size

sampleRate Integer

the sample rate of the original signal

Source:
Returns:

the frequency width of each bin

Type
Number

(static) polar(freqDomain, output) → {Array}

Convert a signal in frequency domain from rectangular { real, imag } to polar form { magnitudes, phases }

It returns an object with two arrays: { magnitures: <Array>, phases: <Array> } If not provided, the magnitudes and phases lengths will be the same as the real and imaginary parts (you can remove calculations by providing arrays of length = (N / 2) + 1 in real signals because the symetric properties)

Parameters:
Name Type Description
freqDomain Object

the frequency domain data in rectangular notation

output Object

(Optional) the buffers to store the data in polar form if you want to reuse buffers for performance reasons

Source:
Returns:

the frequency domain data in polar notation: an object with the form: { magnitudes: <Array>, phases: <Array> }

Type
Array
Example
const dsp = require('dsp-kit')
dsp.polar(dsp.fft(signal)).magnitudes

(static) rectangular()

Given a spectrum in rectangular form ({ magnitudes, phases }) convert into a spectrum in polar form ({ real, imag }).

This is the inverse operation of polar function

Source:
See:
  • polar

(static) unwrap(data, output) → {Array}

Perfroms a phase-unwrapping of a phase data

Parameters:
Name Type Description
data Array

phase data

output Array

(Optional) the output array to store the unrapped phase data (or a new array will be created if not provided)

Source:
Returns:

the unrapped phase data

Type
Array
Example
// get the spectrum of a 1024 size signal fragment
const spectrum = dsp.spectrum(dsp.fft(1024, signal))
// unwrap the phases
const unwrapped = dsp.unwrap(spectrum.phases)