22SCENARIO(
"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 )
94SCENARIO(
"augmenting a 1 sided PSD",
"[sigproc::psdUtils]" )
96 GIVEN(
"a 1 sided PSD, with a 0 freq value" )
100 std::vector<double> f( 5 ), psd( 5 );
102 for(
size_t n = 0; n < psd.size(); ++n )
105 psd[n] = pow( f[n], -2. );
114 std::vector<double> f2s, psd2s;
118 REQUIRE( f2s.size() == 8 );
119 REQUIRE( psd2s.size() == 8 );
121 REQUIRE( f2s[0] == 0 );
122 REQUIRE( f2s[1] == 1 );
123 REQUIRE( f2s[2] == 2 );
124 REQUIRE( f2s[3] == 3 );
125 REQUIRE( f2s[4] == 4 );
126 REQUIRE( f2s[5] == -3 );
127 REQUIRE( f2s[6] == -2 );
128 REQUIRE( f2s[7] == -1 );
131 REQUIRE( psd2s[0] == psd[0] );
132 REQUIRE( psd2s[1] == 0.5 * psd[1] );
133 REQUIRE( psd2s[2] == 0.5 * psd[2] );
134 REQUIRE( psd2s[3] == 0.5 * psd[3] );
135 REQUIRE( psd2s[4] == psd[4] );
136 REQUIRE( psd2s[5] == 0.5 * psd[3] );
137 REQUIRE( psd2s[6] == 0.5 * psd[2] );
138 REQUIRE( psd2s[7] == 0.5 * psd[1] );
150SCENARIO(
"creating a 1D frequency grid",
"[sigproc::psdUtils]" )
152 GIVEN(
"2 sided FFT-order frequency grid" )
156 std::vector<double> f( 10 );
160 REQUIRE( fabs( f[0] - 0 ) < 1e-10 );
161 REQUIRE( fabs( f[1] - 0.1 ) < 1e-10 );
162 REQUIRE( fabs( f[2] - 0.2 ) < 1e-10 );
163 REQUIRE( fabs( f[3] - 0.3 ) < 1e-10 );
164 REQUIRE( fabs( f[4] - 0.4 ) < 1e-10 );
165 REQUIRE( fabs( f[5] - 0.5 ) < 1e-10 );
166 REQUIRE( fabs( f[6] - -0.4 ) < 1e-10 );
167 REQUIRE( fabs( f[7] - -0.3 ) < 1e-10 );
168 REQUIRE( fabs( f[8] - -0.2 ) < 1e-10 );
169 REQUIRE( fabs( f[9] - -0.1 ) < 1e-10 );
174 std::vector<double> f( 10 );
178 REQUIRE( fabs( f[0] - 0 ) < 1e-10 );
179 REQUIRE( fabs( f[1] - 0.04 ) < 1e-10 );
180 REQUIRE( fabs( f[2] - 0.08 ) < 1e-10 );
181 REQUIRE( fabs( f[3] - 0.12 ) < 1e-10 );
182 REQUIRE( fabs( f[4] - 0.16 ) < 1e-10 );
183 REQUIRE( fabs( f[5] - 0.2 ) < 1e-10 );
184 REQUIRE( fabs( f[6] - -0.16 ) < 1e-10 );
185 REQUIRE( fabs( f[7] - -0.12 ) < 1e-10 );
186 REQUIRE( fabs( f[8] - -0.08 ) < 1e-10 );
187 REQUIRE( fabs( f[9] - -0.04 ) < 1e-10 );
191 GIVEN(
"1 sided frequency grid" )
193 WHEN(
"dt = 1, odd size" )
195 std::vector<double> f( 5 );
199 REQUIRE( fabs( f[0] - 0.1 ) < 1e-10 );
200 REQUIRE( fabs( f[1] - 0.2 ) < 1e-10 );
201 REQUIRE( fabs( f[2] - 0.3 ) < 1e-10 );
202 REQUIRE( fabs( f[3] - 0.4 ) < 1e-10 );
203 REQUIRE( fabs( f[4] - 0.5 ) < 1e-10 );
206 WHEN(
"dt = 1, even size" )
208 std::vector<double> f( 6 );
212 REQUIRE( fabs( f[0] - 0.0 ) < 1e-10 );
213 REQUIRE( fabs( f[1] - 0.1 ) < 1e-10 );
214 REQUIRE( fabs( f[2] - 0.2 ) < 1e-10 );
215 REQUIRE( fabs( f[3] - 0.3 ) < 1e-10 );
216 REQUIRE( fabs( f[4] - 0.4 ) < 1e-10 );
217 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.
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.