28#include <unsupported/Eigen/FFT>
53 const int nChannels =
static_cast<int>(matData.rows());
54 const int nTimes =
static_cast<int>(matData.cols());
59 const int nFreqs = nFft / 2 + 1;
63 const int nTap =
static_cast<int>(dpss.
matTapers.rows());
66 double weightSum = 0.0;
67 for (
int t = 0; t < nTap; ++t)
71 result.
matPsd = MatrixXd::Zero(nChannels, nFreqs);
75 for (
int k = 0; k < nFreqs; ++k)
76 result.
vecFreqs[k] =
static_cast<double>(k) * sfreq /
static_cast<double>(nFft);
78 Eigen::FFT<double> fft;
81 for (
int ch = 0; ch < nChannels; ++ch) {
82 RowVectorXd psd = RowVectorXd::Zero(nFreqs);
84 for (
int t = 0; t < nTap; ++t) {
86 VectorXd tapered = matData.row(ch).transpose().array()
87 * dpss.
matTapers.row(t).transpose().array();
90 VectorXd padded = VectorXd::Zero(nFft);
91 const int copyLen = std::min(nTimes, nFft);
92 padded.head(copyLen) = tapered.head(copyLen);
96 fft.fwd(spec, padded);
100 for (
int k = 0; k < nFreqs; ++k)
101 psd[k] += w * std::norm(spec[k]);
105 const double dNorm = 1.0 / (weightSum * sfreq);
109 for (
int k = 1; k < nFreqs - 1; ++k)
112 result.
matPsd.row(ch) = psd;
Thomson multitaper power-spectral-density estimator.
Discrete Prolate Spheroidal Sequences (Slepian tapers) for multitaper spectral estimation.
Shared utilities (I/O helpers, spectral analysis, layout management, warp algorithms).
Result of a DPSS taper computation.
Eigen::MatrixXd matTapers
nTapers × N, each row is a unit-norm taper
Eigen::VectorXd vecEigenvalues
Concentration ratios, length nTapers.
static DpssResult compute(int N, double halfBandwidth, int nTapers=-1)
Result of a multitaper PSD computation.
Eigen::RowVectorXd vecFreqs
Frequency axis in Hz, length nFft/2+1.
Eigen::MatrixXd matPsd
n_channels × n_freqs; one-sided PSD in unit²/Hz
static MultitaperPsdResult compute(const Eigen::MatrixXd &matData, double sfreq, double halfBandwidth=4.0, int nTapers=-1, int nFft=-1)