| 21 | #include "itest.h" |
| 22 | |
| 23 | ITEST(windowfunction) |
| 24 | { |
| 25 | const auto frameSize = 1024; |
| 26 | const auto overlapSize = frameSize / 4; |
| 27 | const auto tukeySize = frameSize + overlapSize; |
| 28 | |
| 29 | float rectangular[frameSize]; |
| 30 | float bartlett[frameSize]; |
| 31 | float hann[frameSize]; |
| 32 | float hamming[frameSize]; |
| 33 | float blackman[frameSize]; |
| 34 | float blackmanHarris[frameSize]; |
| 35 | float tukey[tukeySize]; |
| 36 | |
| 37 | WindowFunction::rectangular(frameSize, rectangular); |
| 38 | WindowFunction::bartlett(frameSize, bartlett); |
| 39 | WindowFunction::hann(frameSize, hann); |
| 40 | WindowFunction::hamming(frameSize, hamming); |
| 41 | WindowFunction::blackman(frameSize, blackman); |
| 42 | WindowFunction::blackmanHarris(frameSize, blackmanHarris); |
| 43 | WindowFunction::tukey(frameSize, overlapSize, tukey); |
| 44 | |
| 45 | auto gui = [&]() |
| 46 | { |
| 47 | if (ImGui::Begin("Window Functions")) |
| 48 | { |
| 49 | const char* types[] = { |
| 50 | "Rectangular", |
| 51 | "Bartlett", |
| 52 | "Hann", |
| 53 | "Hamming", |
| 54 | "Blackman", |
| 55 | "Blackman-Harris", |
| 56 | "Tukey" |
| 57 | }; |
| 58 | |
| 59 | const float* data[] = { |
| 60 | rectangular, |
| 61 | bartlett, |
| 62 | hann, |
| 63 | hamming, |
| 64 | blackman, |
| 65 | blackmanHarris, |
| 66 | tukey |
| 67 | }; |
| 68 | |
| 69 | static auto currentType = -1; |
| 70 | ImGui::Combo("Type", ¤tType, types, 7); |
| 71 | |
| 72 | if (0 <= currentType && currentType < 7) |
| 73 | { |
| 74 | auto size = (currentType == 6) ? tukeySize : frameSize; |
| 75 | ImGui::PlotLines(types[currentType], data[currentType], size, 0, nullptr, 0.0f, 1.0f, ImVec2(512, 512)); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | ImGui::End(); |
| 80 | }; |