Spectral
Namespace: UTILSLIB · Library: Utilities Library
#include <utils/spectral.h>
class UTILSLIB::Spectral
Static multi-taper spectral estimator producing tapered spectra, PSDs and cross-spectral density matrices over Eigen row inputs.
Designed for fan-out across channels via QtConcurrent and feeding CONNECTIVITYLIB's coherence / phase estimators.
Static multi-taper spectra, PSD and CSD estimator for MEG/EEG time series.
const int nSamples = 200;
const double sFreq = 100.0;
RowVectorXd signal(nSamples);
for (int t = 0; t < nSamples; ++t) {
signal(t) = 2.0 * std::sin(2.0 * kPi * 10.0 * t / sFreq); // 10 Hz, amplitude 2
}
const auto [tapers, weights] = Spectral::generateTapers(nSamples, std::string("hanning"));
const MatrixXcd spectra = Spectral::computeTaperedSpectraRow(signal, tapers, nSamples);
const RowVectorXd psd = Spectral::psdFromTaperedSpectra(spectra, weights, nSamples, sFreq);
const VectorXd freqs = Spectral::calculateFFTFreqs(nSamples, sFreq);
Public Methods
Spectral()
deleted default constructor (static class).
Static Methods
computeTaperedSpectraRow(vecData, matTaper, iNfft)
Calculates the full tapered spectra of a given input row data.
Parameters:
-
vecData : const Eigen::RowVectorXd & input roww data (time domain), for which the spectrum is computed.
-
matTaper : const Eigen::MatrixXd & tapers used to compute the spectra.
-
iNfft : int FFT length.
Returns:
- Eigen::MatrixXcd — tapered spectra of the input data.
computeTaperedSpectraMatrix(matData, matTaper, iNfft, bUseThreads)
Calculates the full tapered spectra of a given input matrix data.
This function calculates each row in parallel.
Parameters:
-
matData : const Eigen::MatrixXd & input matrix data (time domain), for which the spectrum is computed.
-
matTaper : const Eigen::MatrixXd & tapers used to compute the spectra.
-
iNfft : int FFT length.
-
bUseThreads : bool Whether to use multiple threads.
Returns:
- QVector< Eigen::MatrixXcd > — tapered spectra of the input data.
compute(inputData)
Computes the tapered spectra for a row vector.
This function gets called in parallel.
Parameters:
- inputData : const TaperedSpectraInputData & The input data.
Returns:
- Eigen::MatrixXcd — The tapered spectra for one data row.
reduce(finalData, resultData)
Reduces the taperedSpectra results to a final result.
This function gets called in parallel.
Parameters:
-
finalData : QVector< Eigen::MatrixXcd > & The final data data.
-
resultData : const Eigen::MatrixXcd & The resulting data from the computation step.
psdFromTaperedSpectra(matTapSpectrum, vecTapWeights, iNfft, dSampFreq)
Calculates the power spectral density of given tapered spectrum.
Parameters:
-
matTapSpectrum : const Eigen::MatrixXcd & tapered spectrum, for which the PSD is calculated.
-
vecTapWeights : const Eigen::VectorXd & taper weights.
-
iNfft : int FFT length.
-
dSampFreq : double sampling frequency of the input data.
Returns:
- Eigen::RowVectorXd — power spectral density of a given tapered spectrum.