Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // FileInputArray.cpp
- // Project
- //
- // Created by Pavlos Charalambides on 17/01/2017.
- // Copyright © 2017 Pavlos Charlambides. All rights reserved.
- //
- #include <iostream>
- //my added libraries
- #include <fstream> //input output class to operate on files
- #include <sstream> //stream class to operate on strings
- #include <string> //string class
- #include <vector>
- #include "InputRead.hpp"
- //for fft
- #include "preFFT.hpp"
- using namespace std;
- int main(int argc, const char * argv[]) {
- string filename = "/Users/PavlosCh/Desktop/C++/Project/Project/test.txt";
- float data [20000];
- float data2D [20][512]; // length would vary based on sampling frequency
- readInput(filename, data);
- //assume we only need 2seconds, would leave us with 10000 data points
- int dataLength = 10240;
- float dataReduced [dataLength];
- int startSignal = 7500; //Sam has to calculate this threshold
- for (int i=0; i<dataLength; i++){
- dataReduced[i] = data[startSignal+i];
- }
- //DATA ARRAY SHOULD BE DELETED at this point
- //deviding the signal into bins of 512, padding last one with zero
- preFFT(dataReduced, data2D);
- //performing FFT on every row of array above
- /*
- #include "dftComplex.hpp"
- const int N = 512;
- for (int i=0; i<20; i++) {
- Complex y1[N], y2[N/2 + 1];
- DftComplex(data2D[i], y1, N); //on receiver side have to add DftComplex(float *arr, Complex y[], int nFft)
- FFTReal fft(N);
- fft.Execute(data2D[i], y2);
- }
- */
- //Normalising
- for (int i=0; i<20; i++) {
- for (int j = 0; j<512; j++){
- float sumFFTrow = 0;
- for (int k=0; k<512; k++) {
- sumFFTrow = sumFFTrow + data2D[i][k];
- }
- data2D[i][j] = data2D[i][j]/sumFFTrow;
- }
- }
- //feature vector
- float featureVector[20];
- float avg = 0;
- for (int i=0; i<20; i++) {
- for (int j=0; j<512; j++){
- avg = avg + data2D[i][j];
- }
- featureVector[i] = avg/512;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement