Advertisement
Guest User

Lab10

a guest
Apr 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. ////This program calculates the finite impulse response for an order number of N = 35
  2. ////Of 600 input values of a sine function.
  3.  
  4. #include<iostream>
  5. #include<iomanip>
  6. #include<fstream>
  7. #include<string>
  8.  
  9. using namespace std;
  10.  
  11. const double PI = 3.14159265359;
  12.  
  13. void popArrX(double xArr[600], int k)
  14. {
  15.     for (int i = 0; i < 600; i++)
  16.     {
  17.         double t = 0.0001;
  18.         xArr[i] = 100 * sin(k * 1000 * PI * t * i);
  19.     }
  20. }
  21. void popArrY(double yArr[600], double xArr[600], double h[35])
  22. {
  23.     yArr[0] = h[0];
  24.     double sum = 0;
  25.     for (int i = 1; i < 35; i++)
  26.     {
  27.         for (int j = 0; j <= i; j++)
  28.         {
  29.             sum += xArr[i - j] * h[j];
  30.         }
  31.         yArr[i] = sum;
  32.         sum = 0;
  33.     }
  34.     for (int i = 35; i < 600; i++)
  35.     {
  36.         for (int j = 0; j < 35; j++)
  37.         {
  38.             sum += xArr[i - j] * h[j];
  39.         }
  40.         yArr[i] = sum;
  41.         sum = 0;
  42.     }
  43. }
  44.  
  45. void main()
  46. {
  47.     double xArr[600];
  48.     double yArr[600];
  49.     double h[35] = {
  50.         361.922,589.0001,52.556,-538.095,-58.657,499.472,-251.531,-785.16,381.999,812.822,-934.41,-1082.725,
  51.         1547.66,1083.109,-3229.92,-1275.73,10268.660,17571.90,10268.660,-1275.73,-3229.92,
  52.         1083.109,1547.66,-1082.725,-934.41,812.822,381.999,-785.16,
  53.         -251.531,499.472,-58.657,-538.095,52.556,589.0001,361.922
  54.     };
  55.     for (int i = 0; i < 35; i++)
  56.     {
  57.         h[i] = h[i] / pow(2, 15);
  58.     }
  59.     int arrCount = 0;
  60.     string lineRaw;
  61.     double number = 0;
  62.  
  63.     ofstream outputIRV;
  64.     popArrX(xArr, 4);
  65.     popArrY(yArr, xArr, h);
  66.     outputIRV.open("C:\\Users\\ns819331\\Documents\\Visual Studio 2017\\Projects\\secondTry\\secondTry\\Filex.txt");
  67.     for (int i = 0; i < 600; i++)
  68.     {
  69.         outputIRV << xArr[i] << ",";
  70.     }
  71.     outputIRV.close();
  72.     outputIRV.open("C:\\Users\\ns819331\\Documents\\Visual Studio 2017\\Projects\\secondTry\\secondTry\\Filey.txt");
  73.     for (int i = 0; i < 600; i++)
  74.     {
  75.         outputIRV << yArr[i] << ",";
  76.     }
  77.     outputIRV.close();
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement