#include #include #include using namespace std; using namespace std::chrono; int main() { ifstream in_file; // An input file stream variable int size = 0; // A number of elements in a signal series // Open the file stream in_file.open("signal.txt"); // Check that the file was opened if (!in_file) { cerr << "Unable to open file signal.txt"; exit(1); // call system to stop } in_file >> size; cout << "Number of elements: " << size << endl; float *A = new float[ 2 * size ]; float *Sums = new float[ 1 * size ]; cout << "Reading series..."; for (int i = 0; i < size; i++) { float value = 0.0; in_file >> value; A[i] = value; A[i + size] = value; } cout << "Done." << endl; // Serial implementation of the autocorrelation sum cout << "Calculating sums..."; high_resolution_clock::time_point t1 = high_resolution_clock::now(); for( int shift = 0; shift < size; shift++ ) { float sum = 0.0; for (int i = 0; i < size; i++) { sum += A[i] * A[i + shift]; } Sums[shift] = sum; } high_resolution_clock::time_point t2 = high_resolution_clock::now(); duration time_span = t2 - t1; cout << "Done in " << time_span.count() << " seconds." << endl; // Close the input stream in_file.close(); delete [] A; delete [] Sums; return 0; }