dsplib 1.1.0
C++ DSP library for MATLAB-like coding
Loading...
Searching...
No Matches
spectrum.h
1#pragma once
2
3#include "dsplib/array.h"
4#include "dsplib/keywords.h"
5
6namespace dsplib {
7
8//Welch’s power spectral density estimate
9//win: nfft size window
10//nfft: number of DFT points (only 2^K support)
11//type: power spectrum scaling (dencity/power)
12
13//note: PSD unit is `Hz`, the `fs` is assumed to be 1.0
14//todo: add min/max/mean/median average
15
17{
18 WelchResult(const arr_real& pxx_, const arr_real& f_)
19 : pxx{pxx_}
20 , f{f_} {
21 }
24};
25
26//real spectrum (one-sided)
27
28//use hamming window with winlen/2 overlaping
29WelchResult welch(const arr_real& x, int winlen, SpectrumType scale = SpectrumType::Psd);
30
31//use custom window with winlen/2 overlaping
32WelchResult welch(const arr_real& x, const arr_real& win, SpectrumType scale = SpectrumType::Psd);
33
34WelchResult welch(const arr_real& x, int winlen, int noverlap, int nfft, SpectrumType scale = SpectrumType::Psd);
35
36WelchResult welch(const arr_real& x, const arr_real& win, int noverlap, int nfft,
37 SpectrumType scale = SpectrumType::Psd);
38
39//complex spectrum (two-sided centered)
40
41WelchResult welch(const arr_cmplx& x, int winlen, SpectrumType scale = SpectrumType::Psd);
42
43WelchResult welch(const arr_cmplx& x, const arr_real& win, SpectrumType scale = SpectrumType::Psd);
44
45WelchResult welch(const arr_cmplx& x, int winlen, int noverlap, int nfft, SpectrumType scale = SpectrumType::Psd);
46
47WelchResult welch(const arr_cmplx& x, const arr_real& win, int noverlap, int nfft,
48 SpectrumType scale = SpectrumType::Psd);
49
50//magnitude-squared coherence (real, one-sided)
51arr_real mscohere(const arr_real& x, const arr_real& y, int winlen);
52
53arr_real mscohere(const arr_real& x, const arr_real& y, const arr_real& win);
54
55arr_real mscohere(const arr_real& x, const arr_real& y, int winlen, int noverlap, int nfft);
56
57arr_real mscohere(const arr_real& x, const arr_real& y, const arr_real& win, int noverlap, int nfft);
58
59} // namespace dsplib
Definition spectrum.h:17
arr_real pxx
spectrum estimate
Definition spectrum.h:22
arr_real f
cyclical frequencies
Definition spectrum.h:23