Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////This program calculates the finite impulse response for an order number of N = 35
- ////Of 600 input values of a sine function.
- #include<iostream>
- #include<iomanip>
- #include<fstream>
- #include<string>
- using namespace std;
- const double PI = 3.14159265359;
- void popArrX(double xArr[600], int k)
- {
- for (int i = 0; i < 600; i++)
- {
- double t = 0.0001;
- xArr[i] = 100 * sin(k * 1000 * PI * t * i);
- }
- }
- void popArrY(double yArr[600], double xArr[600], double h[35])
- {
- yArr[0] = h[0];
- double sum = 0;
- for (int i = 1; i < 35; i++)
- {
- for (int j = 0; j <= i; j++)
- {
- sum += xArr[i - j] * h[j];
- }
- yArr[i] = sum;
- sum = 0;
- }
- for (int i = 35; i < 600; i++)
- {
- for (int j = 0; j < 35; j++)
- {
- sum += xArr[i - j] * h[j];
- }
- yArr[i] = sum;
- sum = 0;
- }
- }
- void main()
- {
- double xArr[600];
- double yArr[600];
- double h[35] = {
- 361.922,589.0001,52.556,-538.095,-58.657,499.472,-251.531,-785.16,381.999,812.822,-934.41,-1082.725,
- 1547.66,1083.109,-3229.92,-1275.73,10268.660,17571.90,10268.660,-1275.73,-3229.92,
- 1083.109,1547.66,-1082.725,-934.41,812.822,381.999,-785.16,
- -251.531,499.472,-58.657,-538.095,52.556,589.0001,361.922
- };
- for (int i = 0; i < 35; i++)
- {
- h[i] = h[i] / pow(2, 15);
- }
- int arrCount = 0;
- string lineRaw;
- double number = 0;
- ofstream outputIRV;
- popArrX(xArr, 4);
- popArrY(yArr, xArr, h);
- outputIRV.open("C:\\Users\\ns819331\\Documents\\Visual Studio 2017\\Projects\\secondTry\\secondTry\\Filex.txt");
- for (int i = 0; i < 600; i++)
- {
- outputIRV << xArr[i] << ",";
- }
- outputIRV.close();
- outputIRV.open("C:\\Users\\ns819331\\Documents\\Visual Studio 2017\\Projects\\secondTry\\secondTry\\Filey.txt");
- for (int i = 0; i < 600; i++)
- {
- outputIRV << yArr[i] << ",";
- }
- outputIRV.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement