fork download
  1. /******************************************************************************
  2.  
  3.   Online C++ Compiler.
  4.   Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <stdint.h>
  10. #include <stdbool.h>
  11. #include <stdio.h>
  12. #include <math.h>
  13.  
  14. using namespace std;
  15.  
  16. #define PI 3.14159265358979323846
  17.  
  18. static double Sinc(double x)
  19. {
  20. if (x == 0.0) return 1.0;
  21. return sin(PI * x) / (PI * x);
  22. }
  23.  
  24. static double SymmetricBlackmanHarris(double i, int n)
  25. {
  26. i += (double)n / 2.0;
  27. double factor = i * 2.0 * PI / (double)n;
  28. const double a0 = 0.35875;
  29. const double a1 = 0.48829;
  30. const double a2 = 0.14128;
  31. const double a3 = 0.01168;
  32. return a0 - a1 * cos(1.0 * factor) + a2 * cos(2.0 * factor) - a3 * cos(3.0 * factor);
  33. }
  34.  
  35. static double SymmetricBlackman(double i, int n)
  36. {
  37. i += (double)n / 2.0;
  38. double factor = i * 2.0 * PI / (double)n;
  39. // Constants from https://e...content-available-to-author-only...a.org/wiki/Window_function#Blackman_window
  40. const double a0 = 0.42;
  41. const double a1 = 0.5;
  42. const double a2 = 0.08;
  43. return a0 - a1 * cos(1.0 * factor) + a2 * cos(2.0 * factor);
  44. }
  45.  
  46. static double SymmetricHamming(double i, int n)
  47. {
  48. i += (double)n / 2.0;
  49. double factor = i * 2.0 * PI / (double)n;
  50. const double a0 = 25.0 / 46.0;
  51. const double a1 = 1.0 - a0;
  52. return a0 - a1 * cos(1.0 * factor);
  53. }
  54.  
  55. static double SymmetricHann(double i, int n)
  56. {
  57. i += (double)n / 2.0;
  58. double factor = i * 2.0 * PI / (double)n;
  59. const double a0 = 0.5;
  60. const double a1 = 1.0 - a0;
  61. return a0 - a1 * cos(1.0 * factor);
  62. }
  63.  
  64. int main()
  65. {
  66. static constexpr int FIRN = 52;
  67. float tblF[FIRN];
  68. const double cutoff = 1.0;
  69.  
  70. printf("Hello World\n");
  71.  
  72. double sum = 0;
  73. for (size_t i = 0; i < FIRN; i++)
  74. {
  75. double t = double(i) - double(FIRN / 2.0) + 1.0 - 0.5;
  76. sum += tblF[i] = SymmetricBlackmanHarris(t, FIRN) * cutoff * Sinc(cutoff * t);
  77. }
  78. // Normalize
  79. for (size_t i = 0; i < FIRN; i++)
  80. tblF[i] *= 1.0 / sum;
  81.  
  82. for (size_t i = 0; i < FIRN; i++)
  83. printf("%.20g\n", tblF[i]);
  84.  
  85. return 0;
  86. }
  87.  
Success #stdin #stdout 0.01s 5332KB
stdin
Standard input is empty
stdout
Hello World
-1.3991638070365297608e-06
7.2991083470697049052e-06
-2.2176480342750437558e-05
5.2196570322848856449e-05
-0.00010721675062086433172
0.00020154945377726107836
-0.00035480680526234209538
0.00059279310517013072968
-0.00094841298414394259453
0.0014625801704823970795
-0.0021851540077477693558
0.003176001599058508873
-0.004506402183324098587
0.0062612053006887435913
-0.008542473427951335907
0.011475901119410991669
-0.015222363173961639404
0.019999079406261444092
-0.026119500398635864258
0.03407209739089012146
-0.044687286019325256348
0.059528928250074386597
-0.081958651542663574219
0.12075470387935638428
-0.2082036435604095459
0.63527512550354003906
0.63527512550354003906
-0.2082036435604095459
0.12075470387935638428
-0.081958651542663574219
0.059528928250074386597
-0.044687286019325256348
0.03407209739089012146
-0.026119500398635864258
0.019999079406261444092
-0.015222363173961639404
0.011475901119410991669
-0.008542473427951335907
0.0062612053006887435913
-0.004506402183324098587
0.003176001599058508873
-0.0021851540077477693558
0.0014625801704823970795
-0.00094841298414394259453
0.00059279310517013072968
-0.00035480680526234209538
0.00020154945377726107836
-0.00010721675062086433172
5.2196570322848856449e-05
-2.2176480342750437558e-05
7.2991083470697049052e-06
-1.3991638070365297608e-06