Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. //
  2. // FileInputArray.cpp
  3. // Project
  4. //
  5. // Created by Pavlos Charalambides on 17/01/2017.
  6. // Copyright © 2017 Pavlos Charlambides. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. //my added libraries
  11. #include <fstream> //input output class to operate on files
  12. #include <sstream> //stream class to operate on strings
  13. #include <string> //string class
  14. #include <vector>
  15. #include "InputRead.hpp"
  16. //for fft
  17. #include "preFFT.hpp"
  18.  
  19. using namespace std;
  20.  
  21. int main(int argc, const char * argv[]) {
  22. string filename = "/Users/PavlosCh/Desktop/C++/Project/Project/test.txt";
  23. float data [20000];
  24. float data2D [20][512]; // length would vary based on sampling frequency
  25. readInput(filename, data);
  26.  
  27. //assume we only need 2seconds, would leave us with 10000 data points
  28. int dataLength = 10240;
  29. float dataReduced [dataLength];
  30.  
  31. int startSignal = 7500; //Sam has to calculate this threshold
  32. for (int i=0; i<dataLength; i++){
  33. dataReduced[i] = data[startSignal+i];
  34. }
  35. //DATA ARRAY SHOULD BE DELETED at this point
  36.  
  37. //deviding the signal into bins of 512, padding last one with zero
  38. preFFT(dataReduced, data2D);
  39. //performing FFT on every row of array above
  40.  
  41. /*
  42. #include "dftComplex.hpp"
  43. const int N = 512;
  44. for (int i=0; i<20; i++) {
  45. Complex y1[N], y2[N/2 + 1];
  46. DftComplex(data2D[i], y1, N); //on receiver side have to add DftComplex(float *arr, Complex y[], int nFft)
  47. FFTReal fft(N);
  48. fft.Execute(data2D[i], y2);
  49. }
  50. */
  51.  
  52. //Normalising
  53.  
  54. for (int i=0; i<20; i++) {
  55. for (int j = 0; j<512; j++){
  56. float sumFFTrow = 0;
  57. for (int k=0; k<512; k++) {
  58. sumFFTrow = sumFFTrow + data2D[i][k];
  59. }
  60. data2D[i][j] = data2D[i][j]/sumFFTrow;
  61. }
  62. }
  63. //feature vector
  64. float featureVector[20];
  65. float avg = 0;
  66. for (int i=0; i<20; i++) {
  67. for (int j=0; j<512; j++){
  68. avg = avg + data2D[i][j];
  69. }
  70. featureVector[i] = avg/512;
  71. }
  72.  
  73.  
  74.  
  75.  
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement