3 #include "../../catch2/catch.hpp"
8 #define MX_NO_ERROR_REPORTS
10 #include "../../../include/sigproc/psdFilter.hpp"
11 #include "../../../include/sigproc/psdUtils.hpp"
12 #include "../../../include/improc/eigenCube.hpp"
13 #include "../../../include/math/randomT.hpp"
14 #include "../../../include/math/vectorUtils.hpp"
22 SCENARIO(
"calculating variance from a 1D PSD",
"[sigproc::psdUtils]" )
24 GIVEN(
"a 1 sided PSD,")
26 WHEN(
"a flat PSD, midpoint rule")
28 std::vector<double> f(5), psd(5);
29 for(
size_t n=0;n<f.size(); ++n)
37 WHEN(
"a flat PSD, trapezoid rule by default")
39 std::vector<double> f(5), psd(5);
40 for(
size_t n=0;n<f.size(); ++n)
49 GIVEN(
"a 2 sided PSD,")
51 WHEN(
"a flat PSD, midpoint rule")
53 std::vector<double> f(6), psd(6);
61 for(
size_t n=0;n<f.size(); ++n)
69 WHEN(
"a flat PSD, trapezoid rule by default")
71 std::vector<double> f(6), psd(6);
79 for(
size_t n=0;n<f.size(); ++n)
95 SCENARIO(
"augmenting a 1 sided PSD",
"[sigproc::psdUtils]" )
97 GIVEN(
"a 1 sided PSD, with a 0 freq value")
101 std::vector<double> f(5), psd(5);
103 for(
size_t n=0;n<psd.size();++n)
106 psd[n] = pow(f[n], -2.);
115 std::vector<double> f2s, psd2s;
119 REQUIRE(f2s.size()==8);
120 REQUIRE(psd2s.size()==8);
132 REQUIRE(psd2s[0] == psd[0]);
133 REQUIRE(psd2s[1] == 0.5*psd[1]);
134 REQUIRE(psd2s[2] == 0.5*psd[2]);
135 REQUIRE(psd2s[3] == 0.5*psd[3]);
136 REQUIRE(psd2s[4] == psd[4]);
137 REQUIRE(psd2s[5] == 0.5*psd[3]);
138 REQUIRE(psd2s[6] == 0.5*psd[2]);
139 REQUIRE(psd2s[7] == 0.5*psd[1]);
151 SCENARIO(
"creating a 1D frequency grid",
"[sigproc::psdUtils]" )
153 GIVEN(
"2 sided FFT-order frequency grid")
157 std::vector<double> f(10);
161 REQUIRE(fabs(f[0] - 0) < 1e-10);
162 REQUIRE(fabs(f[1] - 0.1) < 1e-10);
163 REQUIRE(fabs(f[2] - 0.2) < 1e-10);
164 REQUIRE(fabs(f[3] - 0.3) < 1e-10);
165 REQUIRE(fabs(f[4] - 0.4) < 1e-10);
166 REQUIRE(fabs(f[5] - 0.5) < 1e-10);
167 REQUIRE(fabs(f[6] - -0.4) < 1e-10);
168 REQUIRE(fabs(f[7] - -0.3) < 1e-10);
169 REQUIRE(fabs(f[8] - -0.2) < 1e-10);
170 REQUIRE(fabs(f[9] - -0.1) < 1e-10);
175 std::vector<double> f(10);
179 REQUIRE(fabs(f[0] - 0) < 1e-10);
180 REQUIRE(fabs(f[1] - 0.04) < 1e-10);
181 REQUIRE(fabs(f[2] - 0.08) < 1e-10);
182 REQUIRE(fabs(f[3] - 0.12) < 1e-10);
183 REQUIRE(fabs(f[4] - 0.16) < 1e-10);
184 REQUIRE(fabs(f[5] - 0.2) < 1e-10);
185 REQUIRE(fabs(f[6] - -0.16) < 1e-10);
186 REQUIRE(fabs(f[7] - -0.12) < 1e-10);
187 REQUIRE(fabs(f[8] - -0.08) < 1e-10);
188 REQUIRE(fabs(f[9] - -0.04) < 1e-10);
192 GIVEN(
"1 sided frequency grid")
194 WHEN(
"dt = 1, odd size")
196 std::vector<double> f(5);
200 REQUIRE(fabs(f[0] - 0.1) < 1e-10);
201 REQUIRE(fabs(f[1] - 0.2) < 1e-10);
202 REQUIRE(fabs(f[2] - 0.3) < 1e-10);
203 REQUIRE(fabs(f[3] - 0.4) < 1e-10);
204 REQUIRE(fabs(f[4] - 0.5) < 1e-10);
207 WHEN(
"dt = 1, even size")
209 std::vector<double> f(6);
213 REQUIRE(fabs(f[0] - 0.0) < 1e-10);
214 REQUIRE(fabs(f[1] - 0.1) < 1e-10);
215 REQUIRE(fabs(f[2] - 0.2) < 1e-10);
216 REQUIRE(fabs(f[3] - 0.3) < 1e-10);
217 REQUIRE(fabs(f[4] - 0.4) < 1e-10);
218 REQUIRE(fabs(f[5] - 0.5) < 1e-10);
void augment1SidedPSD(vectorTout &psdTwoSided, vectorTin &psdOneSided, bool addZeroFreq=false, typename vectorTin::value_type scale=0.5)
Augment a 1-sided PSD to standard 2-sided FFT form.
void augment1SidedPSDFreq(std::vector< T > &freqTwoSided, std::vector< T > &freqOneSided)
Augment a 1-sided frequency scale to standard FFT form.
realT psdVar(const std::vector< realT > &f, const std::vector< realT > &PSD, realT half=0.5)
Calculate the variance of a 1-D PSD.
int normPSD(std::vector< floatT > &psd, std::vector< floatT > &f, floatParamT normT, floatT fmin=std::numeric_limits< floatT >::min(), floatT fmax=std::numeric_limits< floatT >::max())
Normalize a 1-D PSD to have a given variance.
int frequencyGrid(std::vector< realT > &vec, realParamT dt, bool fftOrder=true)
Create a 1-D frequency grid.
SCENARIO("calculating variance from a 1D PSD", "[sigproc::psdUtils]")