MCPcopy Create free account
hub / github.com/davisking/dlib / test_good_stft

Function test_good_stft

dlib/test/fft.cpp:561–629  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

559
560 template<typename R>
561 void test_good_stft()
562 {
563 constexpr R tol = std::is_same<R,float>::value ? 1e-5 : 1e-12;
564 matrix<R> tone = sin(2 * pi * matrix_cast<R>(range(0, 511)) / 512.0f);
565
566 {
567 matrix<complex<R>> m_stft = stft(tone, make_hann(), 128, 64, 64/2);
568 DLIB_TEST(m_stft.nr() == 17 && m_stft.nc() == 128);
569 for (long i = 0 ; i < m_stft.nr() ; ++i)
570 for (long j = 0 ; j < m_stft.nc() ; ++j)
571 DLIB_TEST(std::abs(m_stft(i,j) - complex_cast<R>(STFT_FFT_128_WLEN_64_TONE_512[i][j])) < tol);
572
573 matrix<complex<R>> tone2 = istft(m_stft, make_hann(), 64, 64/2);
574 DLIB_TEST(tone.nc() == tone2.nc());
575 DLIB_TEST(tone.nr() == tone2.nr());
576 for (long i = 0 ; i < tone.nc() ; ++i)
577 DLIB_TEST(abs(tone(0,i) - tone2(0, i)) < tol);
578 }
579
580 print_spinner();
581
582 {
583 matrix<complex<R>> m_stft = stft(tone, make_hann(), 64, 64, 64/2);
584 DLIB_TEST(m_stft.nr() == 17 && m_stft.nc() == 64);
585 for (long i = 0 ; i < m_stft.nr() ; ++i)
586 for (long j = 0 ; j < m_stft.nc() ; ++j)
587 DLIB_TEST(std::abs(m_stft(i,j) - complex_cast<R>(STFT_FFT_64_WLEN_64_TONE_512[i][j])) < tol);
588
589 matrix<complex<R>> tone2 = istft(m_stft, make_hann(), 64, 64/2);
590 DLIB_TEST(tone.nc() == tone2.nc());
591 DLIB_TEST(tone.nr() == tone2.nr());
592 for (long i = 0 ; i < tone.nc() ; ++i)
593 DLIB_TEST(abs(tone(0,i) - tone2(0, i)) < tol);
594 }
595
596 print_spinner();
597
598 {
599 matrix<complex<R>> m_stftr = stftr(tone, make_hann(), 128, 64, 64/2);
600 DLIB_TEST(m_stftr.nr() == 17 && m_stftr.nc() == 65);
601 for (long i = 0 ; i < m_stftr.nr() ; ++i)
602 for (long j = 0 ; j < m_stftr.nc() ; ++j)
603 DLIB_TEST(std::abs(m_stftr(i,j) - complex_cast<R>(STFT_FFT_128_WLEN_64_TONE_512[i][j])) < tol);
604
605 matrix<R> tone2 = istftr(m_stftr, make_hann(), 64, 64/2);
606 DLIB_TEST(tone.nc() == tone2.nc());
607 DLIB_TEST(tone.nr() == tone2.nr());
608 for (long i = 0 ; i < tone.nc() ; ++i)
609 DLIB_TEST(abs(tone(0,i) - tone2(0, i)) < tol);
610 }
611
612 print_spinner();
613
614 {
615 matrix<complex<R>> m_stftr = stftr(tone, make_hann(), 64, 64, 64/2);
616 DLIB_TEST(m_stftr.nr() == 17 && m_stftr.nc() == 33);
617 for (long i = 0 ; i < m_stftr.nr() ; ++i)
618 for (long j = 0 ; j < m_stftr.nc() ; ++j)

Callers

nothing calls this directly

Calls 10

stftFunction · 0.85
make_hannFunction · 0.85
absFunction · 0.85
istftFunction · 0.85
print_spinnerFunction · 0.85
stftrFunction · 0.85
istftrFunction · 0.85
rangeFunction · 0.50
nrMethod · 0.45
ncMethod · 0.45

Tested by

no test coverage detected