22SCENARIO(
"compiling psdFilter",
"[sigproc::psdFilter]" )
24 GIVEN(
"a psdFilter, sqrt pointer" )
28 mx::sigproc::psdFilter<double, 1> psdF;
30 std::vector<double> psdSqrt( 1024, 1 );
32 int rv = psdF.psdSqrt( &psdSqrt, 1 );
35 REQUIRE( psdF.rows() == 1024 );
36 REQUIRE( psdF.cols() == 1 );
37 REQUIRE( psdF.planes() == 1 );
40 REQUIRE( psdF.rows() == 0 );
41 REQUIRE( psdF.cols() == 0 );
42 REQUIRE( psdF.planes() == 0 );
46 mx::sigproc::psdFilter<double, 2> psdF;
48 Eigen::Array<double, -1, -1> psdSqrt;
49 psdSqrt.resize( 256, 256 );
50 psdSqrt.setConstant( 1 );
52 int rv = psdF.psdSqrt( &psdSqrt, 1, 1 );
55 REQUIRE( psdF.rows() == 256 );
56 REQUIRE( psdF.cols() == 256 );
57 REQUIRE( psdF.planes() == 1 );
60 REQUIRE( psdF.rows() == 0 );
61 REQUIRE( psdF.cols() == 0 );
62 REQUIRE( psdF.planes() == 0 );
66 mx::sigproc::psdFilter<double, 3> psdF;
69 psdSqrt.resize( 128, 128, 256 );
72 int rv = psdF.psdSqrt( &psdSqrt, 1, 1, 1 );
75 REQUIRE( psdF.rows() == 128 );
76 REQUIRE( psdF.cols() == 128 );
77 REQUIRE( psdF.planes() == 256 );
80 REQUIRE( psdF.rows() == 0 );
81 REQUIRE( psdF.cols() == 0 );
82 REQUIRE( psdF.planes() == 0 );
86 GIVEN(
"a psdFilter, sqrt reference" )
90 mx::sigproc::psdFilter<double, 1> psdF;
92 std::vector<double> psdSqrt( 1024, 1 );
94 int rv = psdF.psdSqrt( psdSqrt, 1 );
97 REQUIRE( psdF.rows() == 1024 );
98 REQUIRE( psdF.cols() == 1 );
99 REQUIRE( psdF.planes() == 1 );
102 REQUIRE( psdF.rows() == 0 );
103 REQUIRE( psdF.cols() == 0 );
104 REQUIRE( psdF.planes() == 0 );
108 mx::sigproc::psdFilter<double, 2> psdF;
110 Eigen::Array<double, -1, -1> psdSqrt;
111 psdSqrt.resize( 256, 256 );
112 psdSqrt.setConstant( 1 );
114 int rv = psdF.psdSqrt( psdSqrt, 1, 1 );
117 REQUIRE( psdF.rows() == 256 );
118 REQUIRE( psdF.cols() == 256 );
119 REQUIRE( psdF.planes() == 1 );
122 REQUIRE( psdF.rows() == 0 );
123 REQUIRE( psdF.cols() == 0 );
124 REQUIRE( psdF.planes() == 0 );
128 mx::sigproc::psdFilter<double, 3> psdF;
131 psdSqrt.resize( 128, 128, 256 );
134 int rv = psdF.psdSqrt( psdSqrt, 1, 1, 1 );
137 REQUIRE( psdF.rows() == 128 );
138 REQUIRE( psdF.cols() == 128 );
139 REQUIRE( psdF.planes() == 256 );
142 REQUIRE( psdF.rows() == 0 );
143 REQUIRE( psdF.cols() == 0 );
144 REQUIRE( psdF.planes() == 0 );
148 GIVEN(
"a psdFilter, psd reference" )
152 mx::sigproc::psdFilter<double, 1> psdF;
154 std::vector<double> psd( 1024, 1 );
156 int rv = psdF.psd( psd, 1.0 );
159 REQUIRE( psdF.rows() == 1024 );
160 REQUIRE( psdF.cols() == 1 );
161 REQUIRE( psdF.planes() == 1 );
164 REQUIRE( psdF.rows() == 0 );
165 REQUIRE( psdF.cols() == 0 );
166 REQUIRE( psdF.planes() == 0 );
170 mx::sigproc::psdFilter<double, 2> psdF;
172 Eigen::Array<double, -1, -1> psd;
173 psd.resize( 256, 256 );
174 psd.setConstant( 1 );
176 int rv = psdF.psd( psd, 1.0, 1.0 );
179 REQUIRE( psdF.rows() == 256 );
180 REQUIRE( psdF.cols() == 256 );
181 REQUIRE( psdF.planes() == 1 );
184 REQUIRE( psdF.rows() == 0 );
185 REQUIRE( psdF.cols() == 0 );
186 REQUIRE( psdF.planes() == 0 );
190 mx::sigproc::psdFilter<double, 3> psdF;
193 psd.resize( 128, 128, 256 );
196 int rv = psdF.psd( psd, 1, 1, 1 );
199 REQUIRE( psdF.rows() == 128 );
200 REQUIRE( psdF.cols() == 128 );
201 REQUIRE( psdF.planes() == 256 );
204 REQUIRE( psdF.rows() == 0 );
205 REQUIRE( psdF.cols() == 0 );
206 REQUIRE( psdF.planes() == 0 );
217SCENARIO(
"filtering with psdFilter",
"[sigproc::psdFilter]" )
219 GIVEN(
"a rank 1 psd" )
221 WHEN(
"alpha=-2.5, df Nyquist matched to array size, var=1" )
223 mx::sigproc::psdFilter<double, 1> psdF;
225 std::vector<double> f( 2049 ), psd( 2049 );
227 for(
size_t n = 0; n < psd.size(); ++n )
228 f[n] = n * 1.0 / 4096.;
230 for(
size_t n = 1; n < psd.size(); ++n )
231 psd[n] = pow( f[n], -2.5 );
236 std::vector<double> f2s, psd2s;
240 double df = f2s[1] - f2s[0];
242 int rv = psdF.psd( psd2s, df );
245 REQUIRE( psdF.rows() == 2. * psd.size() - 2 );
246 REQUIRE( psdF.cols() == 1 );
247 REQUIRE( psdF.planes() == 1 );
249 std::vector<double> noise( psdF.rows() );
255 for(
int k = 0; k < 10000; ++k )
257 for(
size_t n = 0; n < noise.size(); ++n )
263 avgRms = sqrt( avgRms / 10000 );
265 REQUIRE( fabs( avgRms - 1.0 ) < 0.02 );
267 WHEN(
"alpha=-1.5, df arbitrary, var = 2.2" )
269 mx::sigproc::psdFilter<double, 1> psdF;
271 std::vector<double> f( 1025 ), psd( 1025 );
273 for(
size_t n = 0; n < psd.size(); ++n )
274 f[n] = n * 1.0 / 7000.;
276 for(
size_t n = 1; n < psd.size(); ++n )
277 psd[n] = pow( f[n], -1.5 );
280 std::vector<double> f2s, psd2s;
284 double df = f2s[1] - f2s[0];
287 int rv = psdF.psd( psd2s, df );
290 REQUIRE( psdF.rows() == 2. * psd.size() - 2 );
291 REQUIRE( psdF.cols() == 1 );
292 REQUIRE( psdF.planes() == 1 );
294 std::vector<double> noise( psdF.rows() );
300 for(
int k = 0; k < 10000; ++k )
302 for(
size_t n = 0; n < noise.size(); ++n )
308 avgRms = sqrt( avgRms / 10000 );
310 REQUIRE( fabs( avgRms - sqrt( 2.2 ) ) < 0.02 * sqrt( 2.2 ) );
313 GIVEN(
"a rank 2 psd" )
315 WHEN(
"alpha=-2.5, dk Nyquist matched to array size, var=1" )
317 mx::sigproc::psdFilter<double, 2> psdF;
319 Eigen::Array<double, -1, -1> k, psd;
322 psd.resize( 64, 64 );
325 for(
int cc = 0; cc < psd.cols(); ++cc )
327 for(
int rr = 0; rr < psd.rows(); ++rr )
329 if( k( rr, cc ) == 0 )
332 psd( rr, cc ) = pow( k( rr, cc ), -2.5 );
336 double dk = k( 0, 1 ) - k( 0, 0 );
340 int rv = psdF.psd( psd, dk, dk );
343 REQUIRE( psdF.rows() == psd.rows() );
344 REQUIRE( psdF.cols() == psd.cols() );
345 REQUIRE( psdF.planes() == 1 );
347 Eigen::Array<double, -1, -1> noise( psdF.rows(), psdF.cols() );
353 for(
int k = 0; k < 10000; ++k )
355 for(
int cc = 0; cc < psd.cols(); ++cc )
357 for(
int rr = 0; rr < psd.rows(); ++rr )
359 noise( rr, cc ) = normVar;
364 avgRms += noise.square().sum();
367 avgRms = sqrt( avgRms / ( psd.rows() * psd.cols() ) / 10000 );
369 REQUIRE( fabs( avgRms - 1.0 ) < 0.02 );
371 WHEN(
"alpha=-1.5, dk arb, var=2.2" )
373 mx::sigproc::psdFilter<double, 2> psdF;
375 Eigen::Array<double, -1, -1> k, psd;
378 psd.resize( 64, 64 );
381 for(
int cc = 0; cc < psd.cols(); ++cc )
383 for(
int rr = 0; rr < psd.rows(); ++rr )
385 if( k( rr, cc ) == 0 )
388 psd( rr, cc ) = pow( k( rr, cc ), -1.5 );
392 double dk = k( 0, 1 ) - k( 0, 0 );
396 int rv = psdF.psd( psd, dk, dk );
399 REQUIRE( psdF.rows() == psd.rows() );
400 REQUIRE( psdF.cols() == psd.cols() );
401 REQUIRE( psdF.planes() == 1 );
403 Eigen::Array<double, -1, -1> noise( psdF.rows(), psdF.cols() );
409 for(
int k = 0; k < 10000; ++k )
411 for(
int cc = 0; cc < psd.cols(); ++cc )
413 for(
int rr = 0; rr < psd.rows(); ++rr )
415 noise( rr, cc ) = normVar;
420 avgRms += noise.square().sum();
423 avgRms = sqrt( avgRms / ( psd.rows() * psd.cols() ) / 10000 );
425 REQUIRE( fabs( avgRms - sqrt( 2.2 ) ) < 0.02 * sqrt( 2.2 ) );
428 GIVEN(
"a rank 3 psd" )
430 WHEN(
"k-alpha=-2.5, f-alph=-2.5, dk Nyquist matched to array size, df Nyquist matched to array size, var=1" )
432 mx::sigproc::psdFilter<double, 3> psdF;
434 Eigen::Array<double, -1, -1> k, psdk;
435 std::vector<double> f, f2s, psd2s;
443 psdk.resize( k.rows(), k.cols() );
444 for(
int cc = 0; cc < psdk.cols(); ++cc )
446 for(
int rr = 0; rr < psdk.rows(); ++rr )
448 if( k( rr, cc ) == 0 )
451 psdk( rr, cc ) = pow( k( rr, cc ), -2.5 );
456 for(
size_t n = 0; n < f.size(); ++n )
457 f[n] = n * 1.0 / 64.;
459 psd2s.resize( f2s.size() );
460 for(
size_t n = 0; n < psd2s.size(); ++n )
461 psd2s[n] = pow( fabs( f2s[n] ), -2.5 );
464 psd.resize( k.rows(), k.cols(), f2s.size() );
466 for(
int cc = 0; cc < psd.cols(); ++cc )
468 for(
int rr = 0; rr < psd.rows(); ++rr )
470 if( k( rr, cc ) == 0 )
471 psd.
pixel( rr, cc ).setZero();
474 double p = psdk( rr, cc );
477 for(
int pp = 0; pp < psd.planes(); ++pp )
478 psd.
image( pp )( rr, cc ) = psd2s[pp];
483 double dk = k( 0, 1 ) - k( 0, 0 );
484 double df = f[1] - f[0];
486 int rv = psdF.psd( psd, dk, dk, df );
489 REQUIRE( psdF.rows() == psd.rows() );
490 REQUIRE( psdF.cols() == psd.cols() );
491 REQUIRE( psdF.planes() == psd.planes() );
499 for(
int k = 0; k < 10000; ++k )
501 for(
int pp = 0; pp < psd.planes(); ++pp )
503 for(
int cc = 0; cc < psd.cols(); ++cc )
505 for(
int rr = 0; rr < psd.rows(); ++rr )
507 noise.
image( pp )( rr, cc ) = normVar;
513 for(
int pp = 0; pp < noise.planes(); ++pp )
514 avgRms += noise.
image( pp ).square().sum();
517 avgRms = sqrt( avgRms / ( psd.rows() * psd.cols() * psd.planes() ) / 10000 );
519 REQUIRE( fabs( avgRms - 1.0 ) < 0.02 );
521 WHEN(
"k-alpha=-3.5, f-alph=-1.5, dk arb, df arb, var=2" )
523 mx::sigproc::psdFilter<double, 3> psdF;
525 Eigen::Array<double, -1, -1> k, psdk;
526 std::vector<double> f, f2s, psd2s;
534 psdk.resize( k.rows(), k.cols() );
535 for(
int cc = 0; cc < psdk.cols(); ++cc )
537 for(
int rr = 0; rr < psdk.rows(); ++rr )
539 if( k( rr, cc ) == 0 )
542 psdk( rr, cc ) = pow( k( rr, cc ), -3.5 );
547 for(
size_t n = 0; n < f.size(); ++n )
548 f[n] = n * 1.0 / 78.;
550 psd2s.resize( f2s.size() );
551 for(
size_t n = 0; n < psd2s.size(); ++n )
552 psd2s[n] = pow( fabs( f2s[n] ), -1.5 );
555 psd.resize( k.rows(), k.cols(), f2s.size() );
557 for(
int cc = 0; cc < psd.cols(); ++cc )
559 for(
int rr = 0; rr < psd.rows(); ++rr )
561 if( k( rr, cc ) == 0 )
562 psd.
pixel( rr, cc ).setZero();
565 double p = psdk( rr, cc );
568 for(
int pp = 0; pp < psd.planes(); ++pp )
569 psd.
image( pp )( rr, cc ) = psd2s[pp];
574 double dk = k( 0, 1 ) - k( 0, 0 );
575 double df = f[1] - f[0];
577 int rv = psdF.psd( psd, dk, dk, df );
580 REQUIRE( psdF.rows() == psd.rows() );
581 REQUIRE( psdF.cols() == psd.cols() );
582 REQUIRE( psdF.planes() == psd.planes() );
590 for(
int k = 0; k < 10000; ++k )
592 for(
int pp = 0; pp < psd.planes(); ++pp )
594 for(
int cc = 0; cc < psd.cols(); ++cc )
596 for(
int rr = 0; rr < psd.rows(); ++rr )
598 noise.
image( pp )( rr, cc ) = normVar;
604 for(
int pp = 0; pp < noise.planes(); ++pp )
605 avgRms += noise.
image( pp ).square().sum();
608 avgRms = sqrt( avgRms / ( psd.rows() * psd.cols() * psd.planes() ) / 10000 );
610 REQUIRE( fabs( avgRms - sqrt( 2.0 ) ) < 0.02 * sqrt( 2 ) );