plot.cpp (1741B)
1 #include <stdlib.h> 2 #include <stdio.h> 3 #include <stdint.h> 4 #include <string.h> 5 #include <math.h> 6 #include <algorithm> 7 8 #include "dsp/analyzer.hpp" 9 #include "dsp/signal.hpp" 10 11 using namespace bogaudio::dsp; 12 13 // KaiserWindow w(1024); 14 // float y(float x) { 15 // return w._window[(int)x]; 16 // } 17 18 // Chebyshev gain coefficient; x is ripple. 19 // float y(float x) { 20 // float e = x / 10.0; 21 // e = std::pow(10.0f, e); 22 // e -= 1.0f; 23 // e = std::sqrt(e); 24 // 25 // return 1.0f / (2.0f * e); 26 // } 27 28 // // Q https://en.wikipedia.org/wiki/Q_factor 29 // float y(float x) { 30 // x *= 2.0f; 31 // return std::pow(2.0f, x / 2.0f) / (std::pow(2.0f, x) - 1.0f); 32 // } 33 34 // const float m = 20000.0f; 35 // float y(float x) { 36 // x /= m; 37 // x = powf(x, 1.25f); 38 // x *= 0.5f * m; 39 // return x; 40 // } 41 // 42 // int main() { 43 // const float xMin = 0.1f; 44 // // const float xMax = 1023.0f; 45 // const float xMax = 100.0f; 46 // const float samples = 1024.0f; 47 // 48 // const float delta = (xMax - xMin) / samples; 49 // float x = xMin; 50 // while (x <= xMax) { 51 // printf("%f, %f\n", x, y(x)); 52 // x += delta; 53 // } 54 // // printf("%f\n", y(1.0f)); 55 // return 0; 56 // } 57 58 // const float sr = 10000.0f; 59 // float f1 = 100.0f; 60 // float f2 = sr / 2.0f * 0.1f; 61 // float T = 1.5f; 62 // float y(float t) { 63 // float k = powf(f2 / f1, 1.0f / T); 64 // return sinf(2.0f * M_PI * f1 * ((powf(k, t) - 1.0f) / logf(k))); 65 // } 66 67 PlanckTaperWindow w(1024, 300); 68 float y(float x) { 69 return w._window[(int)x]; 70 } 71 72 int main() { 73 const float xMin = 0.0f; 74 const float xMax = 1023.0f; 75 // const float xMax = T; 76 const float samples = 1024.0f; 77 78 const float delta = (xMax - xMin) / samples; 79 float x = xMin; 80 while (x <= xMax) { 81 printf("%f, %f\n", x, y(x)); 82 x += delta; 83 } 84 // printf("%f\n", y(1.0f)); 85 return 0; 86 }