SBB Host
Host communication with the self balancing bike.
Loading...
Searching...
No Matches
spectra Namespace Reference

A namespace providing wrappers for FFTW library. More...

Functions

std::vector< double > abs (std::vector< fftw_complex > vals)
 Compute the magnitute. More...
 
std::vector< double > abs2 (std::vector< fftw_complex > vals)
 Compute the magnitute squared. More...
 
std::vector< double > arg (std::vector< fftw_complex > vals)
 Compute the phase in radiants. More...
 
std::vector< double > argd (std::vector< fftw_complex > vals)
 Compute the phase in degrees. More...
 
void polar (std::vector< fftw_complex > vals, std::vector< double > *mag, std::vector< double > *phase)
 Compute the polar coordinates. More...
 
void polard (std::vector< fftw_complex > vals, std::vector< double > *mag, std::vector< double > *phase)
 Compute the polar coordinates. More...
 
void bode (std::vector< fftw_complex > vals, std::vector< double > *mag, std::vector< double > *phase)
 Compute the bode coordinates. More...
 
void boded (std::vector< fftw_complex > vals, std::vector< double > *mag, std::vector< double > *phase)
 Compute the bode coordinates. More...
 
std::vector< double > frequency (size_t size, double fmax=0.5)
 Compute the frequency vector. More...
 
std::vector< fftw_complex > fft (std::vector< double > vals)
 Compute the spectra. More...
 
std::vector< double > psd (std::vector< double > vals)
 Compute the power-spectra-density. More...
 

Variables

constexpr int REAL = 0
 Position of the real part in fftw_complex type. More...
 
constexpr int IMAG = 1
 Position of the imag part in fftw_complex type. More...
 

Detailed Description

A namespace providing wrappers for FFTW library.

Namespace providing wrapper function and utilities for spectral analysis using the FFTW library and the std::vector library.

Author
Stefano Lovato
Date
2022

Function Documentation

◆ abs()

std::vector< double > spectra::abs ( std::vector< fftw_complex >  vals)

Compute the magnitute.

Function to compute the magnitude of a complex vector.

Parameters
valsA std::vector<fftw_complex> used to compute the magnitude.
Returns
A std::vector<double> containing the maginutude.

◆ abs2()

std::vector< double > spectra::abs2 ( std::vector< fftw_complex >  vals)

Compute the magnitute squared.

Function to compute the magnitude of a complex vector.

Parameters
valsA std::vector<fftw_complex> used to compute the magnitude squared.
Returns
A std::vector<double> containing the maginutude squared.

◆ arg()

std::vector< double > spectra::arg ( std::vector< fftw_complex >  vals)

Compute the phase in radiants.

Function to compute the phase in radiants of a complex vector.

Parameters
valsA std::vector<fftw_complex> used to compute the phase.
Returns
A std::vector<double> containing the phase in radiants.

◆ argd()

std::vector< double > spectra::argd ( std::vector< fftw_complex >  vals)

Compute the phase in degrees.

Function to compute the phase in degrees of a complex vector.

Parameters
valsA std::vector<fftw_complex> used to compute the phase.
Returns
A std::vector<double> containing the phase in degrees.

◆ bode()

void spectra::bode ( std::vector< fftw_complex >  vals,
std::vector< double > *  mag,
std::vector< double > *  phase 
)

Compute the bode coordinates.

Function to compute the bode coordinates (decibel and phase in radians) of a complex vector.

Parameters
valsA std::vector<fftw_complex> used to compute the phase.
magA pointer to a std::vector<double> to store the computed decibel.
phaseA pointer to a std::vector<double> to store the computed phase (in radians).

◆ boded()

void spectra::boded ( std::vector< fftw_complex >  vals,
std::vector< double > *  mag,
std::vector< double > *  phase 
)

Compute the bode coordinates.

Function to compute the bode coordinates (decibel and phase in degrees) of a complex vector.

Parameters
valsA std::vector<fftw_complex> used to compute the phase.
magA pointer to a std::vector<double> to store the computed decibel.
phaseA pointer to a std::vector<double> to store the computed phase (in degrees).

◆ fft()

std::vector< fftw_complex > spectra::fft ( std::vector< double >  vals)

Compute the spectra.

Function to compute the complex spectra of a real signal using the discrete-fourier-transform with the FFTW library.

Parameters
valsA std::vector<double> containing the values of the signal.
Returns
A std::vector<fftw_complex> containing the complex spectra of the signal.

◆ frequency()

std::vector< double > spectra::frequency ( size_t  size,
double  fmax = 0.5 
)

Compute the frequency vector.

Function to compute the frequency vector with given size and maximum frequency.

Parameters
sizeThe size of the resulting vector.
fmaxThe maximum frequency.
Returns
A std::vector<double> containing size frequency from 0 to fmax.

◆ polar()

void spectra::polar ( std::vector< fftw_complex >  vals,
std::vector< double > *  mag,
std::vector< double > *  phase 
)

Compute the polar coordinates.

Function to compute the polar coordinates (magnitude and phase in radians) of a complex vector.

Parameters
valsA std::vector<fftw_complex> used to compute the phase.
magA pointer to a std::vector<double> to store the computed magnitude.
phaseA pointer to a std::vector<double> to store the computed phase (in radians).

◆ polard()

void spectra::polard ( std::vector< fftw_complex >  vals,
std::vector< double > *  mag,
std::vector< double > *  phase 
)

Compute the polar coordinates.

Function to compute the polar coordinates (magnitude and phase in degrees) of a complex vector.

Parameters
valsA std::vector<fftw_complex> used to compute the phase.
magA pointer to a std::vector<double> to store the computed magnitude.
phaseA pointer to a std::vector<double> to store the computed phase (in degrees).

◆ psd()

std::vector< double > spectra::psd ( std::vector< double >  vals)

Compute the power-spectra-density.

Function to compute the power-spectra-density of a real signal using the discrete-fourier-transform with the FFTW library.

Parameters
valsA std::vector<double> containing the values of the signal.
Returns
A A std::vector<double> containing the power-spectra-density of the signal.

Variable Documentation

◆ IMAG

constexpr int spectra::IMAG = 1
constexpr

Position of the imag part in fftw_complex type.

◆ REAL

constexpr int spectra::REAL = 0
constexpr

Position of the real part in fftw_complex type.